summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-12-10 11:49:00 +0100
committerGitHub <noreply@github.com>2020-12-10 11:49:00 +0100
commit37d0d757d653e7d831f991f0c7f31d7166845357 (patch)
tree3a5d0afc974782ae2c6d3efe87786c5af8c569be
parent2a325f388825a20b8e87280d967de80411b2e927 (diff)
parentf797e1c0782a477cc8c0e9997aa5add6172ea9a0 (diff)
Merge pull request #40708 from bruvzg/improve_os_locale
Improve `OS::get_locale()` and documentation.
-rw-r--r--doc/classes/OS.xml7
-rw-r--r--platform/osx/os_osx.mm2
-rw-r--r--platform/windows/os_windows.cpp8
3 files changed, 11 insertions, 6 deletions
diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml
index 1d80695798..ec47d455a9 100644
--- a/doc/classes/OS.xml
+++ b/doc/classes/OS.xml
@@ -233,7 +233,12 @@
<return type="String">
</return>
<description>
- Returns the host OS locale.
+ Returns the host OS locale as a string of the form [code]language_Script_COUNTRY_VARIANT@extra[/code].
+ [code]language[/code] - 2 or 3 letter [url=https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes]language code[/url], in lower case.
+ [code]Script[/code] - optional, 4 letter [url=https://en.wikipedia.org/wiki/ISO_15924]script code[/url], in title case.
+ [code]COUNTRY[/code] - optional, 2 or 3 letter [url=https://en.wikipedia.org/wiki/ISO_3166-1]country code[/url], in upper case.
+ [code]VARIANT[/code] - optional, language variant, region and sort order. Variant can have any number of underscored key words.
+ [code]extra[/code] - optional, semicolon separated list of additional key words. Currency, calendar, sort order and numbering system information.
</description>
</method>
<method name="get_model_name" qualifiers="const">
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 399a29cbe0..ed03e953a5 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -286,7 +286,7 @@ Error OS_OSX::shell_open(String p_uri) {
String OS_OSX::get_locale() const {
NSString *locale_code = [[NSLocale preferredLanguages] objectAtIndex:0];
- return [locale_code UTF8String];
+ return String([locale_code UTF8String]).replace("-", "_");
}
String OS_OSX::get_executable_path() const {
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 633a5091de..451f3bf18c 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -561,21 +561,21 @@ String OS_Windows::get_locale() const {
LANGID langid = GetUserDefaultUILanguage();
String neutral;
- int lang = langid & ((1 << 9) - 1);
- int sublang = langid & ~((1 << 9) - 1);
+ int lang = PRIMARYLANGID(langid);
+ int sublang = SUBLANGID(langid);
while (wl->locale) {
if (wl->main_lang == lang && wl->sublang == SUBLANG_NEUTRAL)
neutral = wl->locale;
if (lang == wl->main_lang && sublang == wl->sublang)
- return wl->locale;
+ return String(wl->locale).replace("-", "_");
wl++;
}
if (neutral != "")
- return neutral;
+ return String(neutral).replace("-", "_");
return "en";
}