WIN32: Move Windows-specific implementation of getSystemLanguage out of OSystem_SDL

This commit is contained in:
Cameron Cawley 2018-05-27 22:14:06 +01:00 committed by Thierry Crozat
parent 6f60ef55ad
commit e1c83f8e87
3 changed files with 28 additions and 22 deletions

View File

@ -436,27 +436,7 @@ void OSystem_SDL::logMessage(LogMessageType::Type type, const char *message) {
}
Common::String OSystem_SDL::getSystemLanguage() const {
#if defined(USE_DETECTLANG) && !defined(_WIN32_WCE)
#ifdef WIN32
// We can not use "setlocale" (at least not for MSVC builds), since it
// will return locales like: "English_USA.1252", thus we need a special
// way to determine the locale string for Win32.
char langName[9];
char ctryName[9];
const LCID languageIdentifier = GetUserDefaultUILanguage();
if (GetLocaleInfo(languageIdentifier, LOCALE_SISO639LANGNAME, langName, sizeof(langName)) != 0 &&
GetLocaleInfo(languageIdentifier, LOCALE_SISO3166CTRYNAME, ctryName, sizeof(ctryName)) != 0) {
Common::String localeName = langName;
localeName += "_";
localeName += ctryName;
return localeName;
} else {
return ModularBackend::getSystemLanguage();
}
#else // WIN32
#if defined(USE_DETECTLANG) && !defined(WIN32)
// Activating current locale settings
const Common::String locale = setlocale(LC_ALL, "");
@ -484,7 +464,6 @@ Common::String OSystem_SDL::getSystemLanguage() const {
return Common::String(locale.c_str(), length);
}
#endif // WIN32
#else // USE_DETECTLANG
return ModularBackend::getSystemLanguage();
#endif // USE_DETECTLANG

View File

@ -150,6 +150,31 @@ bool OSystem_Win32::openUrl(const Common::String &url) {
return true;
}
Common::String OSystem_Win32::getSystemLanguage() const {
#if defined(USE_DETECTLANG) && defined(USE_TRANSLATION)
// We can not use "setlocale" (at least not for MSVC builds), since it
// will return locales like: "English_USA.1252", thus we need a special
// way to determine the locale string for Win32.
char langName[9];
char ctryName[9];
const LCID languageIdentifier = GetUserDefaultUILanguage();
if (GetLocaleInfo(languageIdentifier, LOCALE_SISO639LANGNAME, langName, sizeof(langName)) != 0 &&
GetLocaleInfo(languageIdentifier, LOCALE_SISO3166CTRYNAME, ctryName, sizeof(ctryName)) != 0) {
Common::String localeName = langName;
localeName += "_";
localeName += ctryName;
return localeName;
} else {
return ModularBackend::getSystemLanguage();
}
#endif // USE_DETECTLANG
// Falback to SDL implementation
return OSystem_SDL::getSystemLanguage();
}
Common::String OSystem_Win32::getScreenshotsPath() {
Common::String screenshotsPath = ConfMan.get("screenshotpath");
if (!screenshotsPath.empty()) {

View File

@ -38,6 +38,8 @@ public:
virtual bool openUrl(const Common::String &url);
virtual Common::String getSystemLanguage() const;
virtual Common::String getScreenshotsPath();
protected: