Qt: Capitalize region names

Fixes base translation loading.
This commit is contained in:
Stenzek 2023-09-16 22:22:18 +10:00
parent 7120b19ab7
commit fffde62e3e
15 changed files with 44 additions and 28 deletions

View file

@ -146,7 +146,7 @@ set(TS_FILES
translations/duckstation-qt_de.ts translations/duckstation-qt_de.ts
translations/duckstation-qt_en.ts translations/duckstation-qt_en.ts
translations/duckstation-qt_es.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_fr.ts
translations/duckstation-qt_he.ts translations/duckstation-qt_he.ts
translations/duckstation-qt_it.ts translations/duckstation-qt_it.ts
@ -154,11 +154,11 @@ set(TS_FILES
translations/duckstation-qt_ko.ts translations/duckstation-qt_ko.ts
translations/duckstation-qt_nl.ts translations/duckstation-qt_nl.ts
translations/duckstation-qt_pl.ts translations/duckstation-qt_pl.ts
translations/duckstation-qt_pt-br.ts translations/duckstation-qt_pt-BR.ts
translations/duckstation-qt_pt-pt.ts translations/duckstation-qt_pt-PT.ts
translations/duckstation-qt_ru.ts translations/duckstation-qt_ru.ts
translations/duckstation-qt_tr.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}) add_executable(duckstation-qt ${SRCS} ${QM_FILES})

View file

@ -309,16 +309,16 @@
<QtTs Include="translations\duckstation-qt_pl.ts"> <QtTs Include="translations\duckstation-qt_pl.ts">
<FileType>Document</FileType> <FileType>Document</FileType>
</QtTs> </QtTs>
<QtTs Include="translations\duckstation-qt_pt-br.ts"> <QtTs Include="translations\duckstation-qt_pt-BR.ts">
<FileType>Document</FileType> <FileType>Document</FileType>
</QtTs> </QtTs>
<QtTs Include="translations\duckstation-qt_pt-pt.ts"> <QtTs Include="translations\duckstation-qt_pt-PT.ts">
<FileType>Document</FileType> <FileType>Document</FileType>
</QtTs> </QtTs>
<QtTs Include="translations\duckstation-qt_ru.ts"> <QtTs Include="translations\duckstation-qt_ru.ts">
<FileType>Document</FileType> <FileType>Document</FileType>
</QtTs> </QtTs>
<QtTs Include="translations\duckstation-qt_zh-cn.ts"> <QtTs Include="translations\duckstation-qt_zh-CN.ts">
<FileType>Document</FileType> <FileType>Document</FileType>
</QtTs> </QtTs>
</ItemGroup> </ItemGroup>

View file

@ -243,16 +243,16 @@
<QtTs Include="translations\duckstation-qt_nl.ts"> <QtTs Include="translations\duckstation-qt_nl.ts">
<Filter>translations</Filter> <Filter>translations</Filter>
</QtTs> </QtTs>
<QtTs Include="translations\duckstation-qt_pt-br.ts"> <QtTs Include="translations\duckstation-qt_pt-BR.ts">
<Filter>translations</Filter> <Filter>translations</Filter>
</QtTs> </QtTs>
<QtTs Include="translations\duckstation-qt_pt-pt.ts"> <QtTs Include="translations\duckstation-qt_pt-PT.ts">
<Filter>translations</Filter> <Filter>translations</Filter>
</QtTs> </QtTs>
<QtTs Include="translations\duckstation-qt_ru.ts"> <QtTs Include="translations\duckstation-qt_ru.ts">
<Filter>translations</Filter> <Filter>translations</Filter>
</QtTs> </QtTs>
<QtTs Include="translations\duckstation-qt_zh-cn.ts"> <QtTs Include="translations\duckstation-qt_zh-CN.ts">
<Filter>translations</Filter> <Filter>translations</Filter>
</QtTs> </QtTs>
<QtTs Include="translations\duckstation-qt_pl.ts"> <QtTs Include="translations\duckstation-qt_pl.ts">

View file

@ -49,6 +49,7 @@ struct GlyphInfo
const char16_t* used_glyphs; const char16_t* used_glyphs;
}; };
static QString FixLanguageName(const QString& language);
static std::string GetFontPath(const GlyphInfo* gi); static std::string GetFontPath(const GlyphInfo* gi);
static void UpdateGlyphRanges(const std::string_view& language); static void UpdateGlyphRanges(const std::string_view& language);
static const GlyphInfo* GetGlyphInfo(const std::string_view& language); static const GlyphInfo* GetGlyphInfo(const std::string_view& language);
@ -67,8 +68,9 @@ void QtHost::InstallTranslator()
} }
s_translators.clear(); s_translators.clear();
const QString language( // Fix old language names.
QString::fromStdString(Host::GetBaseStringSettingValue("Main", "Language", GetDefaultLanguage()))); const QString language =
FixLanguageName(QString::fromStdString(Host::GetBaseStringSettingValue("Main", "Language", GetDefaultLanguage())));
// install the base qt translation first // install the base qt translation first
#ifndef __APPLE__ #ifndef __APPLE__
@ -77,15 +79,17 @@ void QtHost::InstallTranslator()
const QString base_dir = QStringLiteral("%1/../Resources/translations").arg(qApp->applicationDirPath()); const QString base_dir = QStringLiteral("%1/../Resources/translations").arg(qApp->applicationDirPath());
#endif #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); bool has_base_ts = QFile::exists(base_path);
if (!has_base_ts) if (!has_base_ts)
{ {
// Try without the country suffix. // Try without the country suffix.
const int index = language.indexOf('-'); const int index = language.lastIndexOf('_');
if (index > 0) 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); has_base_ts = QFile::exists(base_path);
} }
} }
@ -134,6 +138,18 @@ void QtHost::InstallTranslator()
Host::ClearTranslationCache(); 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, s32 Host::Internal::GetTranslatedStringImpl(const std::string_view& context, const std::string_view& msg, char* tbuf,
size_t tbuf_space) size_t tbuf_space)
{ {
@ -184,7 +200,7 @@ std::vector<std::pair<QString, QString>> QtHost::GetAvailableLanguageList()
return {{QStringLiteral("English"), QStringLiteral("en")}, return {{QStringLiteral("English"), QStringLiteral("en")},
{QStringLiteral("Deutsch"), QStringLiteral("de")}, {QStringLiteral("Deutsch"), QStringLiteral("de")},
{QStringLiteral("Español de Hispanoamérica"), QStringLiteral("es")}, {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("Français"), QStringLiteral("fr")},
{QStringLiteral("עברית"), QStringLiteral("he")}, {QStringLiteral("עברית"), QStringLiteral("he")},
{QStringLiteral("日本語"), QStringLiteral("ja")}, {QStringLiteral("日本語"), QStringLiteral("ja")},
@ -192,11 +208,11 @@ std::vector<std::pair<QString, QString>> QtHost::GetAvailableLanguageList()
{QStringLiteral("Italiano"), QStringLiteral("it")}, {QStringLiteral("Italiano"), QStringLiteral("it")},
{QStringLiteral("Nederlands"), QStringLiteral("nl")}, {QStringLiteral("Nederlands"), QStringLiteral("nl")},
{QStringLiteral("Polski"), QStringLiteral("pl")}, {QStringLiteral("Polski"), QStringLiteral("pl")},
{QStringLiteral("Português (Pt)"), QStringLiteral("pt-pt")}, {QStringLiteral("Português (Pt)"), QStringLiteral("pt-PT")},
{QStringLiteral("Português (Br)"), QStringLiteral("pt-br")}, {QStringLiteral("Português (Br)"), QStringLiteral("pt-BR")},
{QStringLiteral("Русский"), QStringLiteral("ru")}, {QStringLiteral("Русский"), QStringLiteral("ru")},
{QStringLiteral("Türkçe"), QStringLiteral("tr")}, {QStringLiteral("Türkçe"), QStringLiteral("tr")},
{QStringLiteral("简体中文"), QStringLiteral("zh-cn")}}; {QStringLiteral("简体中文"), QStringLiteral("zh-CN")}};
} }
const char* QtHost::GetDefaultLanguage() const char* QtHost::GetDefaultLanguage()

View file

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View file

@ -278,16 +278,16 @@
<file>icons/flags/nl@2x.png</file> <file>icons/flags/nl@2x.png</file>
<file>icons/flags/pl.png</file> <file>icons/flags/pl.png</file>
<file>icons/flags/pl@2x.png</file> <file>icons/flags/pl@2x.png</file>
<file>icons/flags/pt-br.png</file> <file>icons/flags/pt-BR.png</file>
<file>icons/flags/pt-br@2x.png</file> <file>icons/flags/pt-BR@2x.png</file>
<file>icons/flags/pt-pt.png</file> <file>icons/flags/pt-PT.png</file>
<file>icons/flags/pt-pt@2x.png</file> <file>icons/flags/pt-PT@2x.png</file>
<file>icons/flags/ru.png</file> <file>icons/flags/ru.png</file>
<file>icons/flags/ru@2x.png</file> <file>icons/flags/ru@2x.png</file>
<file>icons/flags/tr.png</file> <file>icons/flags/tr.png</file>
<file>icons/flags/tr@2x.png</file> <file>icons/flags/tr@2x.png</file>
<file>icons/flags/zh-cn.png</file> <file>icons/flags/zh-CN.png</file>
<file>icons/flags/zh-cn@2x.png</file> <file>icons/flags/zh-CN@2x.png</file>
<file>icons/folder-open.png</file> <file>icons/folder-open.png</file>
<file>icons/folder-open@2x.png</file> <file>icons/folder-open@2x.png</file>
<file>icons/github.png</file> <file>icons/github.png</file>