From fffde62e3e0a5cc9653b24ed979087e0cf27c7ba Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 16 Sep 2023 22:22:18 +1000 Subject: [PATCH] Qt: Capitalize region names Fixes base translation loading. --- src/duckstation-qt/CMakeLists.txt | 8 ++-- src/duckstation-qt/duckstation-qt.vcxproj | 6 +-- .../duckstation-qt.vcxproj.filters | 8 ++-- src/duckstation-qt/qttranslations.cpp | 38 +++++++++++++----- .../icons/flags/{pt-br.png => pt-BR.png} | Bin .../flags/{pt-br@2x.png => pt-BR@2x.png} | Bin .../icons/flags/{pt-pt.png => pt-PT.png} | Bin .../flags/{pt-pt@2x.png => pt-PT@2x.png} | Bin .../icons/flags/{zh-cn.png => zh-CN.png} | Bin .../flags/{zh-cn@2x.png => zh-CN@2x.png} | Bin src/duckstation-qt/resources/resources.qrc | 12 +++--- ...on-qt_es-es.ts => duckstation-qt_es-ES.ts} | 0 ...on-qt_pt-br.ts => duckstation-qt_pt-BR.ts} | 0 ...on-qt_pt-pt.ts => duckstation-qt_pt-PT.ts} | 0 ...on-qt_zh-cn.ts => duckstation-qt_zh-CN.ts} | 0 15 files changed, 44 insertions(+), 28 deletions(-) rename src/duckstation-qt/resources/icons/flags/{pt-br.png => pt-BR.png} (100%) rename src/duckstation-qt/resources/icons/flags/{pt-br@2x.png => pt-BR@2x.png} (100%) rename src/duckstation-qt/resources/icons/flags/{pt-pt.png => pt-PT.png} (100%) rename src/duckstation-qt/resources/icons/flags/{pt-pt@2x.png => pt-PT@2x.png} (100%) rename src/duckstation-qt/resources/icons/flags/{zh-cn.png => zh-CN.png} (100%) rename src/duckstation-qt/resources/icons/flags/{zh-cn@2x.png => zh-CN@2x.png} (100%) rename src/duckstation-qt/translations/{duckstation-qt_es-es.ts => duckstation-qt_es-ES.ts} (100%) rename src/duckstation-qt/translations/{duckstation-qt_pt-br.ts => duckstation-qt_pt-BR.ts} (100%) rename src/duckstation-qt/translations/{duckstation-qt_pt-pt.ts => duckstation-qt_pt-PT.ts} (100%) rename src/duckstation-qt/translations/{duckstation-qt_zh-cn.ts => duckstation-qt_zh-CN.ts} (100%) diff --git a/src/duckstation-qt/CMakeLists.txt b/src/duckstation-qt/CMakeLists.txt index fcb6331cb..25654dc07 100644 --- a/src/duckstation-qt/CMakeLists.txt +++ b/src/duckstation-qt/CMakeLists.txt @@ -146,7 +146,7 @@ set(TS_FILES translations/duckstation-qt_de.ts translations/duckstation-qt_en.ts translations/duckstation-qt_es.ts - translations/duckstation-qt_es-es.ts + translations/duckstation-qt_es-ES.ts translations/duckstation-qt_fr.ts translations/duckstation-qt_he.ts translations/duckstation-qt_it.ts @@ -154,11 +154,11 @@ set(TS_FILES translations/duckstation-qt_ko.ts translations/duckstation-qt_nl.ts translations/duckstation-qt_pl.ts - translations/duckstation-qt_pt-br.ts - translations/duckstation-qt_pt-pt.ts + translations/duckstation-qt_pt-BR.ts + translations/duckstation-qt_pt-PT.ts translations/duckstation-qt_ru.ts translations/duckstation-qt_tr.ts - translations/duckstation-qt_zh-cn.ts + translations/duckstation-qt_zh-CN.ts ) add_executable(duckstation-qt ${SRCS} ${QM_FILES}) diff --git a/src/duckstation-qt/duckstation-qt.vcxproj b/src/duckstation-qt/duckstation-qt.vcxproj index 952e86c3f..b860d8d24 100644 --- a/src/duckstation-qt/duckstation-qt.vcxproj +++ b/src/duckstation-qt/duckstation-qt.vcxproj @@ -309,16 +309,16 @@ Document - + Document - + Document Document - + Document diff --git a/src/duckstation-qt/duckstation-qt.vcxproj.filters b/src/duckstation-qt/duckstation-qt.vcxproj.filters index 60840d61b..c11d09ab6 100644 --- a/src/duckstation-qt/duckstation-qt.vcxproj.filters +++ b/src/duckstation-qt/duckstation-qt.vcxproj.filters @@ -243,16 +243,16 @@ translations - + translations - + translations translations - + translations @@ -262,4 +262,4 @@ translations - \ No newline at end of file + diff --git a/src/duckstation-qt/qttranslations.cpp b/src/duckstation-qt/qttranslations.cpp index 350cb2c8f..2426ef876 100644 --- a/src/duckstation-qt/qttranslations.cpp +++ b/src/duckstation-qt/qttranslations.cpp @@ -49,6 +49,7 @@ struct GlyphInfo const char16_t* used_glyphs; }; +static QString FixLanguageName(const QString& language); static std::string GetFontPath(const GlyphInfo* gi); static void UpdateGlyphRanges(const std::string_view& language); static const GlyphInfo* GetGlyphInfo(const std::string_view& language); @@ -67,25 +68,28 @@ void QtHost::InstallTranslator() } s_translators.clear(); - const QString language( - QString::fromStdString(Host::GetBaseStringSettingValue("Main", "Language", GetDefaultLanguage()))); + // Fix old language names. + const QString language = + FixLanguageName(QString::fromStdString(Host::GetBaseStringSettingValue("Main", "Language", GetDefaultLanguage()))); // install the base qt translation first #ifndef __APPLE__ const QString base_dir = QStringLiteral("%1/translations").arg(qApp->applicationDirPath()); #else - const QString base_dir = QStringLiteral("%1/../Resources/translations").arg(qApp->applicationDirPath()); + const QString base_dir = QStringLiteral("%1/../Resources/translations").arg(qApp->applicationDirPath()); #endif - - QString base_path(QStringLiteral("%1/qtbase_%2.qm").arg(base_dir).arg(language)); + + // Qt base uses underscores instead of hyphens. + const QString qt_language = QString(language).replace(QChar('-'), QChar('_')); + QString base_path(QStringLiteral("%1/qt_%2.qm").arg(base_dir).arg(qt_language)); bool has_base_ts = QFile::exists(base_path); if (!has_base_ts) { // Try without the country suffix. - const int index = language.indexOf('-'); + const int index = language.lastIndexOf('_'); if (index > 0) { - base_path = QStringLiteral("%1/qtbase_%2.qm").arg(base_dir).arg(language.left(index)); + base_path = QStringLiteral("%1/qt_%2.qm").arg(base_dir).arg(language.left(index)); has_base_ts = QFile::exists(base_path); } } @@ -134,6 +138,18 @@ void QtHost::InstallTranslator() Host::ClearTranslationCache(); } +QString QtHost::FixLanguageName(const QString& language) +{ + if (language == QStringLiteral("pt-br")) + return QStringLiteral("pt-BR"); + else if (language == QStringLiteral("pt-pt")) + return QStringLiteral("pt-PT"); + else if (language == QStringLiteral("zh-cn")) + return QStringLiteral("zh-CN"); + else + return language; +} + s32 Host::Internal::GetTranslatedStringImpl(const std::string_view& context, const std::string_view& msg, char* tbuf, size_t tbuf_space) { @@ -184,7 +200,7 @@ std::vector> QtHost::GetAvailableLanguageList() return {{QStringLiteral("English"), QStringLiteral("en")}, {QStringLiteral("Deutsch"), QStringLiteral("de")}, {QStringLiteral("Español de Hispanoamérica"), QStringLiteral("es")}, - {QStringLiteral("Español de España"), QStringLiteral("es-es")}, + {QStringLiteral("Español de España"), QStringLiteral("es-ES")}, {QStringLiteral("Français"), QStringLiteral("fr")}, {QStringLiteral("עברית"), QStringLiteral("he")}, {QStringLiteral("日本語"), QStringLiteral("ja")}, @@ -192,11 +208,11 @@ std::vector> QtHost::GetAvailableLanguageList() {QStringLiteral("Italiano"), QStringLiteral("it")}, {QStringLiteral("Nederlands"), QStringLiteral("nl")}, {QStringLiteral("Polski"), QStringLiteral("pl")}, - {QStringLiteral("Português (Pt)"), QStringLiteral("pt-pt")}, - {QStringLiteral("Português (Br)"), QStringLiteral("pt-br")}, + {QStringLiteral("Português (Pt)"), QStringLiteral("pt-PT")}, + {QStringLiteral("Português (Br)"), QStringLiteral("pt-BR")}, {QStringLiteral("Русский"), QStringLiteral("ru")}, {QStringLiteral("Türkçe"), QStringLiteral("tr")}, - {QStringLiteral("简体中文"), QStringLiteral("zh-cn")}}; + {QStringLiteral("简体中文"), QStringLiteral("zh-CN")}}; } const char* QtHost::GetDefaultLanguage() diff --git a/src/duckstation-qt/resources/icons/flags/pt-br.png b/src/duckstation-qt/resources/icons/flags/pt-BR.png similarity index 100% rename from src/duckstation-qt/resources/icons/flags/pt-br.png rename to src/duckstation-qt/resources/icons/flags/pt-BR.png diff --git a/src/duckstation-qt/resources/icons/flags/pt-br@2x.png b/src/duckstation-qt/resources/icons/flags/pt-BR@2x.png similarity index 100% rename from src/duckstation-qt/resources/icons/flags/pt-br@2x.png rename to src/duckstation-qt/resources/icons/flags/pt-BR@2x.png diff --git a/src/duckstation-qt/resources/icons/flags/pt-pt.png b/src/duckstation-qt/resources/icons/flags/pt-PT.png similarity index 100% rename from src/duckstation-qt/resources/icons/flags/pt-pt.png rename to src/duckstation-qt/resources/icons/flags/pt-PT.png diff --git a/src/duckstation-qt/resources/icons/flags/pt-pt@2x.png b/src/duckstation-qt/resources/icons/flags/pt-PT@2x.png similarity index 100% rename from src/duckstation-qt/resources/icons/flags/pt-pt@2x.png rename to src/duckstation-qt/resources/icons/flags/pt-PT@2x.png diff --git a/src/duckstation-qt/resources/icons/flags/zh-cn.png b/src/duckstation-qt/resources/icons/flags/zh-CN.png similarity index 100% rename from src/duckstation-qt/resources/icons/flags/zh-cn.png rename to src/duckstation-qt/resources/icons/flags/zh-CN.png diff --git a/src/duckstation-qt/resources/icons/flags/zh-cn@2x.png b/src/duckstation-qt/resources/icons/flags/zh-CN@2x.png similarity index 100% rename from src/duckstation-qt/resources/icons/flags/zh-cn@2x.png rename to src/duckstation-qt/resources/icons/flags/zh-CN@2x.png diff --git a/src/duckstation-qt/resources/resources.qrc b/src/duckstation-qt/resources/resources.qrc index 7725df902..47f77738e 100644 --- a/src/duckstation-qt/resources/resources.qrc +++ b/src/duckstation-qt/resources/resources.qrc @@ -278,16 +278,16 @@ icons/flags/nl@2x.png icons/flags/pl.png icons/flags/pl@2x.png - icons/flags/pt-br.png - icons/flags/pt-br@2x.png - icons/flags/pt-pt.png - icons/flags/pt-pt@2x.png + icons/flags/pt-BR.png + icons/flags/pt-BR@2x.png + icons/flags/pt-PT.png + icons/flags/pt-PT@2x.png icons/flags/ru.png icons/flags/ru@2x.png icons/flags/tr.png icons/flags/tr@2x.png - icons/flags/zh-cn.png - icons/flags/zh-cn@2x.png + icons/flags/zh-CN.png + icons/flags/zh-CN@2x.png icons/folder-open.png icons/folder-open@2x.png icons/github.png diff --git a/src/duckstation-qt/translations/duckstation-qt_es-es.ts b/src/duckstation-qt/translations/duckstation-qt_es-ES.ts similarity index 100% rename from src/duckstation-qt/translations/duckstation-qt_es-es.ts rename to src/duckstation-qt/translations/duckstation-qt_es-ES.ts diff --git a/src/duckstation-qt/translations/duckstation-qt_pt-br.ts b/src/duckstation-qt/translations/duckstation-qt_pt-BR.ts similarity index 100% rename from src/duckstation-qt/translations/duckstation-qt_pt-br.ts rename to src/duckstation-qt/translations/duckstation-qt_pt-BR.ts diff --git a/src/duckstation-qt/translations/duckstation-qt_pt-pt.ts b/src/duckstation-qt/translations/duckstation-qt_pt-PT.ts similarity index 100% rename from src/duckstation-qt/translations/duckstation-qt_pt-pt.ts rename to src/duckstation-qt/translations/duckstation-qt_pt-PT.ts diff --git a/src/duckstation-qt/translations/duckstation-qt_zh-cn.ts b/src/duckstation-qt/translations/duckstation-qt_zh-CN.ts similarity index 100% rename from src/duckstation-qt/translations/duckstation-qt_zh-cn.ts rename to src/duckstation-qt/translations/duckstation-qt_zh-CN.ts