Preparation for UI i18n

Re-enabling the WSJT-X i18n  facilities. This allows translation files
to  be created  for languages  that are  automatically used  to lookup
translatable strings. To enable a  new language the language name must
be added to the CMakeLists.txt LANGUAGES list variable in BCP47 format
(i.e. en_US,  en_GB, pt_PT, ...). Do  one build with the  CMake option
UPDATE_TRANSLATIONS enabled  (do not  leave it enabled  as there  is a
danger of loosing existing translated texts), that will create a fresh
translations/wsjtx_<lang>.ts file which  should be immediately checked
in with the  CMakeLists.txt change. The .ts should then  be updated by
the translator using  the Qt Linguist tool to  add translations. Check
in the  updated .ts file  to complete the initial  translation process
for that language.

To  aid translators  their WIP  .ts file  may be  tested by  releasing
(using the  lrelease tool or  from the Linguist  menu) a .qm  file and
placing  that  .qm  file  in the  current  directory  before  starting
WSJT-X. The translations will be used if the system locale matches the
file name.   If the system  locale does not  match the file  name; the
language may be  overridden by setting the  LANG environment variable.
For  example if  a wsjtx_pt_PT.qm  file  is in  the current  directory
WSJT-X will use it for  translation lookups, regardless of the current
system locale setting, if the LANG variable is set to pt_PT or pt-PT.

On MS Windows from a command prompt:

 set LANG=pt_PT
 C:\WSJT\wsjtx\bin\wsjtx

elsewhere:

 LANG=pt_PT wsjtx
This commit is contained in:
Bill Somerville
2019-06-06 12:56:25 +01:00
parent b985d41591
commit 45b12e6028
30 changed files with 12142 additions and 14 deletions
+29
View File
@@ -10,6 +10,7 @@
#include <QTemporaryFile>
#include <QDateTime>
#include <QApplication>
#include <QTranslator>
#include <QRegularExpression>
#include <QObject>
#include <QSettings>
@@ -106,6 +107,34 @@ int main(int argc, char *argv[])
ExceptionCatchingApplication a(argc, argv);
try
{
//
// Enable i18n
//
QTranslator 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.
translator_from_resources.load (QLocale::system (), "wsjtx", "_", ":/Translations");
a.installTranslator (&translator_from_resources);
QTranslator translator_from_files;
// Load any matching translation from the current directory
// using the locale name. 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. Either the system locale setting or the environment
// variable LANG can be used to select the target language.
translator_from_files.load (QString {"wsjtx_"} + QLocale::system ().name ());
a.installTranslator (&translator_from_files);
setlocale (LC_NUMERIC, "C"); // ensure number forms are in
// consistent format, do this after
// instantiating QApplication so