5959#include < QtCore/QDateTime>
6060#include < QtCore/QDebug>
6161#include < QtCore/QEventLoop>
62- #include < QtCore/QTranslator>
6362#include < QtCore/QFile>
6463#include < QtCore/QTimer>
64+ #include < QtCore/QTranslator>
6565#include < QtCore/QtLogging>
6666#include < QtGui/QClipboard>
6767#include < QtGui/QKeyEvent>
@@ -123,6 +123,7 @@ static void MigrateSettings();
123123static void SaveSettings ();
124124static bool RunSetupWizard ();
125125static void UpdateFontOrder (std::string_view language);
126+ static void UpdateApplicationLocale (std::string_view language);
126127static std::optional<bool > DownloadFile (QWidget* parent, const QString& title, std::string url, std::vector<u8 >* data);
127128static void InitializeEarlyConsole ();
128129static void HookSignals ();
@@ -135,6 +136,7 @@ static bool ParseCommandLineParametersAndInitializeConfig(QApplication& app,
135136static INISettingsInterface s_base_settings_interface;
136137static std::unique_ptr<QTimer> s_settings_save_timer;
137138static std::vector<QTranslator*> s_translators;
139+ static QLocale s_app_locale;
138140static bool s_batch_mode = false ;
139141static bool s_nogui_mode = false ;
140142static bool s_start_fullscreen_ui = false ;
@@ -2180,7 +2182,6 @@ bool Host::CopyTextToClipboard(std::string_view text)
21802182
21812183std::string Host::FormatNumber (NumberFormatType type, s64 value)
21822184{
2183- const QLocale loc = QLocale::system ();
21842185 std::string ret;
21852186
21862187 if (type >= NumberFormatType::ShortDate && type <= NumberFormatType::LongDateTime)
@@ -2190,18 +2191,20 @@ std::string Host::FormatNumber(NumberFormatType type, s64 value)
21902191 {
21912192 case NumberFormatType::ShortDate:
21922193 case NumberFormatType::LongDate:
2193- format = loc.dateFormat ((type == NumberFormatType::LongDate) ? QLocale::LongFormat : QLocale::ShortFormat);
2194+ format =
2195+ s_app_locale.dateFormat ((type == NumberFormatType::LongDate) ? QLocale::LongFormat : QLocale::ShortFormat);
21942196 break ;
21952197
21962198 case NumberFormatType::ShortTime:
21972199 case NumberFormatType::LongTime:
2198- format = loc.timeFormat ((type == NumberFormatType::LongTime) ? QLocale::LongFormat : QLocale::ShortFormat);
2200+ format =
2201+ s_app_locale.timeFormat ((type == NumberFormatType::LongTime) ? QLocale::LongFormat : QLocale::ShortFormat);
21992202 break ;
22002203
22012204 case NumberFormatType::ShortDateTime:
22022205 case NumberFormatType::LongDateTime:
2203- format =
2204- loc. dateTimeFormat ((type == NumberFormatType::LongDateTime) ? QLocale::LongFormat : QLocale::ShortFormat);
2206+ format = s_app_locale. dateTimeFormat ((type == NumberFormatType::LongDateTime) ? QLocale::LongFormat :
2207+ QLocale::ShortFormat);
22052208 break ;
22062209
22072210 DefaultCaseIsUnreachable ();
@@ -2211,22 +2214,21 @@ std::string Host::FormatNumber(NumberFormatType type, s64 value)
22112214 }
22122215 else
22132216 {
2214- ret = loc .toString (value).toStdString ();
2217+ ret = s_app_locale .toString (value).toStdString ();
22152218 }
22162219
22172220 return ret;
22182221}
22192222
22202223std::string Host::FormatNumber (NumberFormatType type, double value)
22212224{
2222- const QLocale loc = QLocale::system ();
22232225 std::string ret;
22242226
22252227 switch (type)
22262228 {
22272229 case NumberFormatType::Number:
22282230 default :
2229- ret = loc .toString (value).toStdString ();
2231+ ret = s_app_locale .toString (value).toStdString ();
22302232 break ;
22312233 }
22322234
@@ -2309,6 +2311,7 @@ void QtHost::UpdateApplicationLanguage(QWidget* dialog_parent)
23092311
23102312 // We end up here both on language change, and on startup.
23112313 UpdateFontOrder (language);
2314+ UpdateApplicationLocale (language);
23122315}
23132316
23142317s32 Host::Internal::GetTranslatedStringImpl (std::string_view context, std::string_view msg,
@@ -2423,6 +2426,28 @@ void QtHost::UpdateFontOrder(std::string_view language)
24232426 }
24242427}
24252428
2429+ const QLocale& QtHost::GetApplicationLocale ()
2430+ {
2431+ return s_app_locale;
2432+ }
2433+
2434+ void QtHost::UpdateApplicationLocale (std::string_view language)
2435+ {
2436+ #if 0
2437+ // Only for testing purposes. Keep the system locale for users.
2438+ if (language == "ja")
2439+ s_app_locale = QLocale(QLocale::Japanese, QLocale::Japan);
2440+ else if (language == "ko")
2441+ s_app_locale = QLocale(QLocale::Korean, QLocale::SouthKorea);
2442+ else if (language == "zh-CN")
2443+ s_app_locale = QLocale(QLocale::Chinese, QLocale::China);
2444+ else
2445+ s_app_locale = QLocale::system();
2446+ #else
2447+ s_app_locale = QLocale::system ();
2448+ #endif
2449+ }
2450+
24262451void Host::ReportDebuggerMessage (std::string_view message)
24272452{
24282453 INFO_LOG (" Debugger message: {}" , message);
0 commit comments