diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/ECMCreateQmFromPoFiles.cmake | 2 | ||||
| -rw-r--r-- | modules/ECMQmLoader.cpp.in | 24 | 
2 files changed, 15 insertions, 11 deletions
| diff --git a/modules/ECMCreateQmFromPoFiles.cmake b/modules/ECMCreateQmFromPoFiles.cmake index 3da31940..f331460d 100644 --- a/modules/ECMCreateQmFromPoFiles.cmake +++ b/modules/ECMCreateQmFromPoFiles.cmake @@ -134,7 +134,7 @@ function(_ECM_QM_CREATE_TARGET install_destination catalog_name)          # strings. Finally run lrelease to create the .qm files.          add_custom_command(OUTPUT ${qmfile}              COMMAND ${lconvert_executable} -                ARGS -i ${it} -o ${tsfile} +                ARGS -i ${it} -o ${tsfile} -target-language ${language}              COMMAND Qt5::lrelease                  ARGS -compress -removeidentical -silent ${tsfile} -qm ${qmfile}              DEPENDS ${it} diff --git a/modules/ECMQmLoader.cpp.in b/modules/ECMQmLoader.cpp.in index fd530602..2d8531f3 100644 --- a/modules/ECMQmLoader.cpp.in +++ b/modules/ECMQmLoader.cpp.in @@ -10,32 +10,36 @@  #include <QDebug> -static QTranslator *createTranslator(const QString &localeDirName) +static bool loadTranslation(const QString &localeDirName)  {      QString subPath = QStringLiteral("locale/") + localeDirName + QStringLiteral("/LC_MESSAGES/@catalog_name@.qm");      QString fullPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, subPath);      if (fullPath.isEmpty()) { -        return 0; +        return false;      }      QTranslator *translator = new QTranslator(QCoreApplication::instance());      if (!translator->load(fullPath)) {          delete translator; -        return 0; +        return false;      } -    return translator; +    QCoreApplication::instance()->installTranslator(translator); +    return true;  }  static void load()  { +    // The way Qt translation system handles plural forms makes it necessary to +    // have a translation file which contains only plural forms for `en`. That's +    // why we load the `en` translation unconditionally, then load the +    // translation for the current locale to overload it. +    loadTranslation(QStringLiteral("en")); +      QLocale locale = QLocale::system(); -    QTranslator *translator = createTranslator(locale.name()); -    if (!translator) { -        translator = createTranslator(locale.bcp47Name()); -        if (!translator) { -            return; +    if (locale.name() != QStringLiteral("en")) { +        if (!loadTranslation(locale.name())) { +            loadTranslation(locale.bcp47Name());          }      } -    QCoreApplication::instance()->installTranslator(translator);  }  Q_COREAPP_STARTUP_FUNCTION(load) | 
