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_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})

View File

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

View File

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

View File

@ -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<std::pair<QString, QString>> 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<std::pair<QString, QString>> 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()

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/pl.png</file>
<file>icons/flags/pl@2x.png</file>
<file>icons/flags/pt-br.png</file>
<file>icons/flags/pt-br@2x.png</file>
<file>icons/flags/pt-pt.png</file>
<file>icons/flags/pt-pt@2x.png</file>
<file>icons/flags/pt-BR.png</file>
<file>icons/flags/pt-BR@2x.png</file>
<file>icons/flags/pt-PT.png</file>
<file>icons/flags/pt-PT@2x.png</file>
<file>icons/flags/ru.png</file>
<file>icons/flags/ru@2x.png</file>
<file>icons/flags/tr.png</file>
<file>icons/flags/tr@2x.png</file>
<file>icons/flags/zh-cn.png</file>
<file>icons/flags/zh-cn@2x.png</file>
<file>icons/flags/zh-CN.png</file>
<file>icons/flags/zh-CN@2x.png</file>
<file>icons/folder-open.png</file>
<file>icons/folder-open@2x.png</file>
<file>icons/github.png</file>