summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp164
1 files changed, 27 insertions, 137 deletions
diff --git a/main.cpp b/main.cpp
index eb458021..bce897ad 100644
--- a/main.cpp
+++ b/main.cpp
@@ -10,13 +10,14 @@
#include <QTemporaryFile>
#include <QDateTime>
#include <QApplication>
+#include <QLocale>
#include <QTranslator>
#include <QRegularExpression>
#include <QObject>
#include <QSettings>
-#include <QLibraryInfo>
#include <QSysInfo>
#include <QDir>
+#include <QDirIterator>
#include <QStandardPaths>
#include <QStringList>
#include <QLockFile>
@@ -29,6 +30,7 @@
#include "revision_utils.hpp"
#include "MetaDataRegistry.hpp"
+#include "L10nLoader.hpp"
#include "SettingsGroup.hpp"
#include "TraceFile.hpp"
#include "MultiSettings.hpp"
@@ -107,9 +109,17 @@ int main(int argc, char *argv[])
ExceptionCatchingApplication a(argc, argv);
try
{
- QLocale locale; // get the current system locale
- qDebug () << "locale: language:" << locale.language () << "script:" << locale.script ()
- << "country:" << locale.country () << "ui-languages:" << locale.uiLanguages ();
+ // qDebug () << "+++++++++++++++++++++++++++ Resources ++++++++++++++++++++++++++++";
+ // {
+ // QDirIterator resources_iter {":/", QDirIterator::Subdirectories};
+ // while (resources_iter.hasNext ())
+ // {
+ // qDebug () << resources_iter.next ();
+ // }
+ // }
+ // qDebug () << "--------------------------- Resources ----------------------------";
+
+ QLocale locale; // get the current system locale
setlocale (LC_NUMERIC, "C"); // ensure number forms are in
// consistent format, do this after
// instantiating QApplication so
@@ -119,41 +129,6 @@ int main(int argc, char *argv[])
a.setApplicationName ("WSJT-X");
a.setApplicationVersion (version ());
- //
- // Enable base i18n
- //
- QTranslator translator_from_resources;
- QTranslator base_translator_from_resources;
- // Default translations for releases use translations stored in
- // the resources file system under the Translations
- // directory. These are built by the CMake build system from .ts
- // files in the translations source directory. New languages are
- // added by enabling the UPDATE_TRANSLATIONS CMake option and
- // building with the new language added to the LANGUAGES CMake
- // list variable. UPDATE_TRANSLATIONS will preserve existing
- // translations but should only be set when adding new
- // languages. The resulting .ts files should be checked info
- // source control for translators to access and update.
-
- // try and load the base translation
- for (QString locale_name : locale.uiLanguages ())
- {
- auto language = locale_name.left (2);
- if (base_translator_from_resources.load ("wsjtx_" + language, ":/Translations"))
- {
- qDebug () << QString {"Loaded base translation file from :/Translations based on language %1"}.arg (language);
- a.installTranslator (&base_translator_from_resources);
- break;
- }
- }
- // now try and load the most specific translations (may be a
- // duplicate but we shouldn't care)
- if (translator_from_resources.load (locale, "wsjtx", "_", ":/Translations"))
- {
- qDebug () << "Loaded translations for current locale from resources";
- a.installTranslator (&translator_from_resources);
- }
-
QCommandLineParser parser;
parser.setApplicationDescription ("\n" PROJECT_SUMMARY_DESCRIPTION);
auto help_option = parser.addHelpOption ();
@@ -161,132 +136,47 @@ int main(int argc, char *argv[])
// support for multiple instances running from a single installation
QCommandLineOption rig_option (QStringList {} << "r" << "rig-name"
- , a.translate ("main", "Where <rig-name> is for multi-instance support.")
- , a.translate ("main", "rig-name"));
+ , "Where <rig-name> is for multi-instance support."
+ , "rig-name");
parser.addOption (rig_option);
// support for start up configuration
QCommandLineOption cfg_option (QStringList {} << "c" << "config"
- , a.translate ("main", "Where <configuration> is an existing one.")
- , a.translate ("main", "configuration"));
+ , "Where <configuration> is an existing one."
+ , "configuration");
parser.addOption (cfg_option);
// support for UI language override (useful on Windows)
QCommandLineOption lang_option (QStringList {} << "l" << "language"
- , a.translate ("main", "Where <language> is <lang-code>[-<country-code>].")
- , a.translate ("main", "language"));
+ , "Where <language> is <lang-code>[-<country-code>]."
+ , "language");
parser.addOption (lang_option);
QCommandLineOption test_option (QStringList {} << "test-mode"
- , a.translate ("main", "Writable files in test location. Use with caution, for testing only."));
+ , "Writable files in test location. Use with caution, for testing only.");
parser.addOption (test_option);
if (!parser.parse (a.arguments ()))
{
- MessageBox::critical_message (nullptr, a.translate ("main", "Command line error"), parser.errorText ());
+ MessageBox::critical_message (nullptr, "Command line error", parser.errorText ());
return -1;
}
else
{
if (parser.isSet (help_option))
{
- MessageBox::information_message (nullptr, a.translate ("main", "Command line help"), parser.helpText ());
+ MessageBox::information_message (nullptr, "Command line help", parser.helpText ());
return 0;
}
else if (parser.isSet (version_option))
{
- MessageBox::information_message (nullptr, a.translate ("main", "Application version"), a.applicationVersion ());
+ MessageBox::information_message (nullptr, "Application version", a.applicationVersion ());
return 0;
}
}
- //
- // Complete i18n
- //
-
- QTranslator translation_override_from_resources;
- QTranslator base_translation_override_from_resources;
- // Load any matching translation from the current directory
- // using the command line option language override. This allows
- // translators to easily test their translations by releasing
- // (lrelease) a .qm file into the current directory with a
- // suitable name (e.g. wsjtx_en_GB.qm), then running wsjtx to
- // view the results.
- if (parser.isSet (lang_option))
- {
- auto language = parser.value (lang_option).replace ('-', '_');
- // try and load the base translation
- auto base_language = language.left (2);
- if (base_translation_override_from_resources.load ("wsjtx_" + base_language, ":/Translations"))
- {
- qDebug () << QString {"Loaded base translation file from :/Translations based on language %1"}.arg (base_language);
- a.installTranslator (&base_translation_override_from_resources);
- }
- // now load the requested translations (may be a duplicate
- // but we shouldn't care)
- if (translation_override_from_resources.load ("wsjtx_" + language , ":/Translations"))
- {
- qDebug () << QString {"Loaded translation file from :/Translations based on language %1"}.arg (language);
- a.installTranslator (&translation_override_from_resources);
- }
- }
-
- QTranslator translator_from_cwd;
- QTranslator base_translator_from_cwd;
- // Load any matching translation from the current directory
- // using the current locale. This allows translators to easily
- // test their translations by releasing (lrelease) a .qm file
- // into the current directory with a suitable name (e.g.
- // wsjtx_en_GB.qm), then running wsjtx to view the results. The
- // system locale setting will be used to select the translation
- // file which can be overridden by the LANG environment variable
- // on non-Windows system.
-
- // try and load the base translation
- for (QString locale_name : locale.uiLanguages ())
- {
- auto language = locale_name.left (2);
- if (base_translator_from_cwd.load ("wsjtx_" + language))
- {
- qDebug () << QString {"Loaded base translation file from $cwd based on language %1"}.arg (language);
- a.installTranslator (&base_translator_from_cwd);
- break;
- }
- }
- // now try and load the most specific translations (may be a
- // duplicate but we shouldn't care)
- if (translator_from_cwd.load (locale, "wsjtx", "_"))
- {
- qDebug () << "loaded translations for current locale from a file";
- a.installTranslator (&translator_from_cwd);
- }
-
- QTranslator translation_override_from_cwd;
- QTranslator base_translation_override_from_cwd;
- // Load any matching translation from the current directory
- // using the command line option language override. This allows
- // translators to easily test their translations on Windows by
- // releasing (lrelease) a .qm file into the current directory
- // with a suitable name (e.g. wsjtx_en_GB.qm), then running
- // wsjtx to view the results.
- if (parser.isSet (lang_option))
- {
- auto language = parser.value (lang_option).replace ('-', '_');
- // try and load the base translation
- auto base_language = language.left (2);
- if (base_translation_override_from_cwd.load ("wsjtx_" + base_language))
- {
- qDebug () << QString {"Loaded base translation file from $cwd based on language %1"}.arg (base_language);
- a.installTranslator (&base_translation_override_from_cwd);
- }
- // now load the requested translations (may be a duplicate
- // but we shouldn't care)
- if (translation_override_from_cwd.load ("wsjtx_" + language))
- {
- qDebug () << QString {"loaded translation file from $cwd based on language %1"}.arg (language);
- a.installTranslator (&translation_override_from_cwd);
- }
- }
+ // load UI translations
+ L10nLoader l10n {&a, locale, parser.value (lang_option)};
QStandardPaths::setTestModeEnabled (parser.isSet (test_option));
@@ -299,7 +189,7 @@ int main(int argc, char *argv[])
{
if (temp_name.contains (QRegularExpression {R"([\\/,])"}))
{
- std::cerr << QObject::tr ("Invalid rig name - \\ & / not allowed").toLocal8Bit ().data () << std::endl;
+ std::cerr << "Invalid rig name - \\ & / not allowed" << std::endl;
parser.showHelp (-1);
}