59
59
#include < QtCore/QDateTime>
60
60
#include < QtCore/QDebug>
61
61
#include < QtCore/QEventLoop>
62
- #include < QtCore/QTranslator>
63
62
#include < QtCore/QFile>
64
63
#include < QtCore/QTimer>
64
+ #include < QtCore/QTranslator>
65
65
#include < QtCore/QtLogging>
66
66
#include < QtGui/QClipboard>
67
67
#include < QtGui/QKeyEvent>
@@ -123,6 +123,7 @@ static void MigrateSettings();
123
123
static void SaveSettings ();
124
124
static bool RunSetupWizard ();
125
125
static void UpdateFontOrder (std::string_view language);
126
+ static void UpdateApplicationLocale (std::string_view language);
126
127
static std::optional<bool > DownloadFile (QWidget* parent, const QString& title, std::string url, std::vector<u8 >* data);
127
128
static void InitializeEarlyConsole ();
128
129
static void HookSignals ();
@@ -135,6 +136,7 @@ static bool ParseCommandLineParametersAndInitializeConfig(QApplication& app,
135
136
static INISettingsInterface s_base_settings_interface;
136
137
static std::unique_ptr<QTimer> s_settings_save_timer;
137
138
static std::vector<QTranslator*> s_translators;
139
+ static QLocale s_app_locale;
138
140
static bool s_batch_mode = false ;
139
141
static bool s_nogui_mode = false ;
140
142
static bool s_start_fullscreen_ui = false ;
@@ -2180,7 +2182,6 @@ bool Host::CopyTextToClipboard(std::string_view text)
2180
2182
2181
2183
std::string Host::FormatNumber (NumberFormatType type, s64 value)
2182
2184
{
2183
- const QLocale loc = QLocale::system ();
2184
2185
std::string ret;
2185
2186
2186
2187
if (type >= NumberFormatType::ShortDate && type <= NumberFormatType::LongDateTime)
@@ -2190,18 +2191,20 @@ std::string Host::FormatNumber(NumberFormatType type, s64 value)
2190
2191
{
2191
2192
case NumberFormatType::ShortDate:
2192
2193
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);
2194
2196
break ;
2195
2197
2196
2198
case NumberFormatType::ShortTime:
2197
2199
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);
2199
2202
break ;
2200
2203
2201
2204
case NumberFormatType::ShortDateTime:
2202
2205
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);
2205
2208
break ;
2206
2209
2207
2210
DefaultCaseIsUnreachable ();
@@ -2211,22 +2214,21 @@ std::string Host::FormatNumber(NumberFormatType type, s64 value)
2211
2214
}
2212
2215
else
2213
2216
{
2214
- ret = loc .toString (value).toStdString ();
2217
+ ret = s_app_locale .toString (value).toStdString ();
2215
2218
}
2216
2219
2217
2220
return ret;
2218
2221
}
2219
2222
2220
2223
std::string Host::FormatNumber (NumberFormatType type, double value)
2221
2224
{
2222
- const QLocale loc = QLocale::system ();
2223
2225
std::string ret;
2224
2226
2225
2227
switch (type)
2226
2228
{
2227
2229
case NumberFormatType::Number:
2228
2230
default :
2229
- ret = loc .toString (value).toStdString ();
2231
+ ret = s_app_locale .toString (value).toStdString ();
2230
2232
break ;
2231
2233
}
2232
2234
@@ -2309,6 +2311,7 @@ void QtHost::UpdateApplicationLanguage(QWidget* dialog_parent)
2309
2311
2310
2312
// We end up here both on language change, and on startup.
2311
2313
UpdateFontOrder (language);
2314
+ UpdateApplicationLocale (language);
2312
2315
}
2313
2316
2314
2317
s32 Host::Internal::GetTranslatedStringImpl (std::string_view context, std::string_view msg,
@@ -2423,6 +2426,28 @@ void QtHost::UpdateFontOrder(std::string_view language)
2423
2426
}
2424
2427
}
2425
2428
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
+
2426
2451
void Host::ReportDebuggerMessage (std::string_view message)
2427
2452
{
2428
2453
INFO_LOG (" Debugger message: {}" , message);
0 commit comments