diff --git a/backends/platform/ios7/ios7_osys_misc.mm b/backends/platform/ios7/ios7_osys_misc.mm index f0e6067ec24..b4780577c10 100644 --- a/backends/platform/ios7/ios7_osys_misc.mm +++ b/backends/platform/ios7/ios7_osys_misc.mm @@ -39,10 +39,14 @@ static inline void execute_on_main_thread_async(void (^block)(void)) { } Common::String OSystem_iOS7::getSystemLanguage() const { - NSString *locale = [[NSLocale currentLocale] localeIdentifier]; - if (locale == nil) + NSString *language = [[NSLocale preferredLanguages] firstObject]; + if (language == nil) return Common::String(); - return Common::String([locale cStringUsingEncoding:NSISOLatin1StringEncoding]); + Common::String lang([language cStringUsingEncoding:NSISOLatin1StringEncoding]); + // Depending on the iOS version this may use an underscore (e.g. en_US) or a + // dash (en-US). Make sure we always return one with an underscore. + Common::replace(lang, "-", "_"); + return lang; } bool OSystem_iOS7::hasTextInClipboard() { diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 386c8a867f6..c9349dfca46 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -565,16 +565,17 @@ Common::String OSystem_SDL::getSystemLanguage() const { // Detect the language from the locale if (locale.empty()) { return BaseBackend::getSystemLanguage(); + } else if (locale == "C" || locale == "POSIX") { + return "en_US"; } else { int length = 0; - // Strip out additional information, like - // ".UTF-8" or the like. We do this, since - // our translation languages are usually - // specified without any charset information. + // Assume the locale is in the form language[_territory[.codeset]][@modifier]. + // On macOS the format is different (it looks like C/UTF-8/C/C/C/C), but we + // have a different implementation of getSystemLanguage for macOS anyway, so + // we don't have to handle it here. + // Strip out additional information, like ".UTF-8" or the like. for (int size = locale.size(); length < size; ++length) { - // TODO: Check whether "@" should really be checked - // here. if (locale[length] == '.' || locale[length] == ' ' || locale[length] == '@') break; } diff --git a/common/system.h b/common/system.h index 26c6963a443..4ef6825d097 100644 --- a/common/system.h +++ b/common/system.h @@ -1807,16 +1807,17 @@ public: virtual bool openUrl(const Common::String &url) {return false; } /** - * Return the locale of the system. + * Return the language of the system. * - * This returns the currently set locale of the system on which + * This returns the currently set language of the system on which * ScummVM is run. * - * The format of the locale is language_country. These should match - * the POSIX locale values. + * The format is an ISO 639 language code, optionally followed by an ISO 3166-1 country code + * in the form language_country. * * For information about POSIX locales, see the following link: - * https://en.wikipedia.org/wiki/Locale_(computer_software)#POSIX_platforms + * https://en.wikipedia.org/wiki/ISO_639 + * https://en.wikipedia.org/wiki/ISO_3166-1 * * The default implementation returns "en_US". *