mirror of
https://github.com/stenzek/duckstation.git
synced 2025-07-29 06:11:47 +00:00
Qt: Use selected language locale for formatting
But check the prefix against the system locale, so that e.g. en can use the system country.
This commit is contained in:
parent
c82351a14a
commit
96c224497b
@ -2383,8 +2383,7 @@ std::span<const std::pair<const char*, const char*>> Host::GetAvailableLanguageL
|
||||
static constexpr const std::pair<const char*, const char*> languages[] = {
|
||||
{QT_TRANSLATE_NOOP("QtHost", "System Language"), ""},
|
||||
|
||||
#define TRANSLATION_LIST_ENTRY(name, our_translation_code, locale_code) \
|
||||
{name " [" our_translation_code "]", our_translation_code},
|
||||
#define TRANSLATION_LIST_ENTRY(name, code, locale_code, qlanguage, qcountry) {name " [" code "]", code},
|
||||
#include "qttranslations.inl"
|
||||
#undef TRANSLATION_LIST_ENTRY
|
||||
};
|
||||
@ -2488,19 +2487,30 @@ const QLocale& QtHost::GetApplicationLocale()
|
||||
|
||||
void QtHost::UpdateApplicationLocale(std::string_view language)
|
||||
{
|
||||
#if 0
|
||||
// Only for testing purposes. Keep the system locale for users.
|
||||
if (language == "ja")
|
||||
s_app_locale = QLocale(QLocale::Japanese, QLocale::Japan);
|
||||
else if (language == "ko")
|
||||
s_app_locale = QLocale(QLocale::Korean, QLocale::SouthKorea);
|
||||
else if (language == "zh-CN")
|
||||
s_app_locale = QLocale(QLocale::Chinese, QLocale::China);
|
||||
else
|
||||
static constexpr const std::tuple<const char*, QLocale::Language, QLocale::Country> lookup[] = {
|
||||
#define TRANSLATION_LIST_ENTRY(name, code, locale_code, qlanguage, qcountry) {code, qlanguage, qcountry},
|
||||
#include "qttranslations.inl"
|
||||
#undef TRANSLATION_LIST_ENTRY
|
||||
};
|
||||
|
||||
// If the system locale is using the same language, then use the system locale.
|
||||
// Otherwise we'll be using that ugly US date format in Straya mate.
|
||||
s_app_locale = QLocale::system();
|
||||
#else
|
||||
s_app_locale = QLocale::system();
|
||||
#endif
|
||||
const std::string system_locale_name = s_app_locale.name().toStdString();
|
||||
if (s_app_locale.name().startsWith(QLatin1StringView(language), Qt::CaseInsensitive))
|
||||
{
|
||||
INFO_LOG("Using system locale for {}.", language);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& [code, qlanguage, qcountry] : lookup)
|
||||
{
|
||||
if (language == code)
|
||||
{
|
||||
s_app_locale = QLocale(qlanguage, qcountry);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Host::ReportDebuggerMessage(std::string_view message)
|
||||
|
@ -1,20 +1,20 @@
|
||||
// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
||||
|
||||
// TRANSLATION_LIST_ENTRY(name, our_translation_code, locale_code)
|
||||
// TRANSLATION_LIST_ENTRY(name, code, locale_code, qlanguage, qcountry)
|
||||
|
||||
TRANSLATION_LIST_ENTRY("English", "en", "en-US")
|
||||
TRANSLATION_LIST_ENTRY("Español de Latinoamérica", "es", "es-ES")
|
||||
TRANSLATION_LIST_ENTRY("Español de España", "es-ES", "es-ES")
|
||||
TRANSLATION_LIST_ENTRY("Français", "fr", "fr-FR")
|
||||
TRANSLATION_LIST_ENTRY("Bahasa Indonesia", "id", "id-ID")
|
||||
TRANSLATION_LIST_ENTRY("日本語", "ja", "ja-JA")
|
||||
TRANSLATION_LIST_ENTRY("한국어", "ko", "ko-KO")
|
||||
TRANSLATION_LIST_ENTRY("Italiano", "it", "it-IT")
|
||||
TRANSLATION_LIST_ENTRY("Polski", "pl", "pl-PL")
|
||||
TRANSLATION_LIST_ENTRY("Português (Pt)", "pt-PT", "pt-PT")
|
||||
TRANSLATION_LIST_ENTRY("Português (Br)", "pt-BR", "pt-BR")
|
||||
TRANSLATION_LIST_ENTRY("Русский", "ru", "ru-RU")
|
||||
TRANSLATION_LIST_ENTRY("Svenska", "sv", "sv-SV")
|
||||
TRANSLATION_LIST_ENTRY("Türkçe", "tr", "tr-TR")
|
||||
TRANSLATION_LIST_ENTRY("简体中文", "zh-CN", "zh-CN")
|
||||
TRANSLATION_LIST_ENTRY("English", "en", "en-US", QLocale::English, QLocale::UnitedStates)
|
||||
TRANSLATION_LIST_ENTRY("Español de Latinoamérica", "es", "es-ES", QLocale::Spanish, QLocale::LatinAmerica)
|
||||
TRANSLATION_LIST_ENTRY("Español de España", "es-ES", "es-ES", QLocale::Spanish, QLocale::Spain)
|
||||
TRANSLATION_LIST_ENTRY("Français", "fr", "fr-FR", QLocale::French, QLocale::France)
|
||||
TRANSLATION_LIST_ENTRY("Bahasa Indonesia", "id", "id-ID", QLocale::Indonesian, QLocale::Indonesia)
|
||||
TRANSLATION_LIST_ENTRY("日本語", "ja", "ja-JA", QLocale::Japanese, QLocale::Japan)
|
||||
TRANSLATION_LIST_ENTRY("한국어", "ko", "ko-KO", QLocale::Korean, QLocale::SouthKorea)
|
||||
TRANSLATION_LIST_ENTRY("Italiano", "it", "it-IT", QLocale::Italian, QLocale::Italy)
|
||||
TRANSLATION_LIST_ENTRY("Polski", "pl", "pl-PL", QLocale::Polish, QLocale::Poland)
|
||||
TRANSLATION_LIST_ENTRY("Português (Pt)", "pt-PT", "pt-PT", QLocale::Portuguese, QLocale::Portugal)
|
||||
TRANSLATION_LIST_ENTRY("Português (Br)", "pt-BR", "pt-BR", QLocale::Portuguese, QLocale::Brazil)
|
||||
TRANSLATION_LIST_ENTRY("Русский", "ru", "ru-RU", QLocale::Russian, QLocale::Russia)
|
||||
TRANSLATION_LIST_ENTRY("Svenska", "sv", "sv-SV", QLocale::Swedish, QLocale::Sweden)
|
||||
TRANSLATION_LIST_ENTRY("Türkçe", "tr", "tr-TR", QLocale::Turkish, QLocale::Turkey)
|
||||
TRANSLATION_LIST_ENTRY("简体中文", "zh-CN", "zh-CN", QLocale::Chinese, QLocale::China)
|
||||
|
Loading…
x
Reference in New Issue
Block a user