Skip to content

Commit 61c9660

Browse files
committed
frontend: Use system locale on Windows instead of 'C'
Sets runtime locale to system locale with UTF-8 codepage. This is already default behavior on unix, but Windows defaults to minimal 'C' locale. OBS Studio language settings no longer change QLocale default locale, instead system locale is used for conformity. It is likely this is what user wants as well. Ie. sorting and formatting functions should follow OS locale instead of OBS Studio language (which also lacks country information).
1 parent 35c02e7 commit 61c9660

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

frontend/OBSApp.cpp

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,6 @@ bool OBSApp::InitLocale()
693693

694694
locale = lang;
695695

696-
// set basic default application locale
697-
if (!locale.empty())
698-
QLocale::setDefault(QLocale(QString::fromStdString(locale).replace('-', '_')));
699-
700696
string englishPath;
701697
if (!GetDataFilePath("locale/" DEFAULT_LANG ".ini", englishPath)) {
702698
OBSErrorBox(NULL, "Failed to find locale/" DEFAULT_LANG ".ini");
@@ -732,10 +728,6 @@ bool OBSApp::InitLocale()
732728
blog(LOG_INFO, "Using preferred locale '%s'", locale_.c_str());
733729
locale = locale_;
734730

735-
// set application default locale to the new choosen one
736-
if (!locale.empty())
737-
QLocale::setDefault(QLocale(QString::fromStdString(locale).replace('-', '_')));
738-
739731
return true;
740732
}
741733

@@ -868,11 +860,49 @@ OBSApp::OBSApp(int &argc, char **argv, profiler_name_store_t *store)
868860
profilerNameStore(store),
869861
appLaunchUUID_(QUuid::createUuid())
870862
{
863+
864+
bool usingUTF8 = true;
865+
#ifdef _WIN32
866+
/*
867+
Appropriate setlocale() calls are already performed for unix platforms in QCoreApplicationPrivate::initLocale()
868+
We are just following suit for win32
869+
*/
870+
871+
// Use system locale with UTF-8 codepage (available from Windows 10 version 1803)
872+
// Qt calls setlocale(LC_ALL, "") for unix system defaults, but it is likely unix defaults to UTF-8 ccodepage
873+
if (!setlocale(LC_ALL, ".UTF-8")) {
874+
875+
// Fallback to minimal C locale
876+
// Could use "" for system defaults, but the Windows default ANSI codepages (.125x or .9xx)
877+
// mismatch with UTF-8 that is assumed by many parts of the codebase
878+
setlocale(LC_ALL, "C");
879+
usingUTF8 = false;
880+
}
881+
#else
882+
// Extend Qt default locale calls for unix by enforcing UTF-8 LC_COLLATE (string comparisons, sorting, regex)
883+
{
884+
QByteArray collationLocale = setlocale(LC_COLLATE, nullptr);
885+
if (qsizetype dot = collationLocale.indexOf('.'); dot != -1)
886+
collationLocale.truncate(dot); // remove encoding, if any
887+
888+
if (qsizetype at = collationLocale.indexOf('@'); at != -1)
889+
collationLocale.truncate(at); // remove variant, as the old de_DE@euro
890+
891+
collationLocale += ".UTF-8";
892+
if (!setlocale(LC_COLLATE, collationLocale))
893+
usingUTF8 = false;
894+
}
895+
#endif
896+
871897
/* fix float handling */
872-
#if defined(Q_OS_UNIX)
873898
if (!setlocale(LC_NUMERIC, "C"))
874899
blog(LOG_WARNING, "Failed to set LC_NUMERIC to C locale");
875-
#endif
900+
901+
if (!usingUTF8)
902+
blog(LOG_WARNING, "Failed to set UTF-8 codepage for locales");
903+
904+
const char *localeStr = setlocale(LC_ALL, nullptr);
905+
blog(LOG_INFO, "Set locale to: %s", localeStr);
876906

877907
#ifndef _WIN32
878908
/* Handle SIGINT properly */

0 commit comments

Comments
 (0)