Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS.get_locale() fixed in windows && _OS::get_standardized_locale() implemented #37246

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/bind/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,11 @@ String _OS::get_locale() const {
return OS::get_singleton()->get_locale();
}

String _OS::get_standardized_locale() const {

return get_locale().replace("-", "_");
}

String _OS::get_latin_keyboard_variant() const {
switch (OS::get_singleton()->get_latin_keyboard_variant()) {
case OS::LATIN_KEYBOARD_QWERTY: return "QWERTY";
Expand Down Expand Up @@ -1295,6 +1300,7 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_ticks_usec"), &_OS::get_ticks_usec);
ClassDB::bind_method(D_METHOD("get_splash_tick_msec"), &_OS::get_splash_tick_msec);
ClassDB::bind_method(D_METHOD("get_locale"), &_OS::get_locale);
ClassDB::bind_method(D_METHOD("get_standardized_locale"), &_OS::get_standardized_locale);
ClassDB::bind_method(D_METHOD("get_latin_keyboard_variant"), &_OS::get_latin_keyboard_variant);
ClassDB::bind_method(D_METHOD("get_model_name"), &_OS::get_model_name);

Expand Down
1 change: 1 addition & 0 deletions core/bind/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class _OS : public Object {
Vector<String> get_cmdline_args();

String get_locale() const;
String get_standardized_locale() const;
String get_latin_keyboard_variant() const;

String get_model_name() const;
Expand Down
8 changes: 8 additions & 0 deletions doc/classes/OS.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@
Returns the host OS locale.
</description>
</method>
<method name="get_standardized_locale" qualifiers="const">
<return type="String">
</return>
<description>
Returns the host OS locale as a string of the form [code]locale[_VARIANT][/code] (e.g. [code]en_US[/code] for American English). The returned String will not depend on the OS or user configuration. See [url=https://docs.godotengine.org/en/latest/tutorials/i18n/locales.html]this page[/url] for examples of locale codes that can be returned.
[b]Note:[/b] This method returns [code]en[/code] if the host OS locale can't be detected for any reason.
</description>
</method>
<method name="get_model_name" qualifiers="const">
<return type="String">
</return>
Expand Down
2 changes: 1 addition & 1 deletion platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3019,7 +3019,7 @@ String OS_Windows::get_locale() const {
LANGID langid = GetUserDefaultUILanguage();
String neutral;
int lang = langid & ((1 << 9) - 1);
int sublang = langid & ~((1 << 9) - 1);
int sublang = langid >> 10;

while (wl->locale) {

Expand Down