COMMON: Change OSystem::getSystemLanguage to always return a language code

This commit is contained in:
Thierry Crozat 2021-07-30 23:54:16 +01:00
parent cbb627a40b
commit 1af6ae593a
3 changed files with 20 additions and 14 deletions

View File

@ -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() {

View File

@ -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;
}

View File

@ -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".
*