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

Implement OS::get_locale_language() helper method #52740

Merged
merged 1 commit into from
Sep 16, 2021

Conversation

akien-mga
Copy link
Member

This method extracts the 2 or 3-letter language code from OS::get_locale(),
making it easier for users to identify the "main" language code for users
that might have different OS locales due to different OS or region, but
should be matched to the same translation (e.g. "generic" Spanish).

Fixes #40703.


Notes:

  • I added it to OS and not just to core_bind::OS as I figured it could be useful for engine code or GDExtensions too. But strictly speaking it could be included only in core_bind::OS for the binding if we want.
  • There's similar language code extraction logic in TranslationServer, but it's actually more complex as it has to handle user-provided locale strings, while here we know that we'll get something reliable from OS::get_locale().

This method extracts the 2 or 3-letter language code from `OS::get_locale()`,
making it easier for users to identify the "main" language code for users
that might have different OS locales due to different OS or region, but
should be matched to the same translation (e.g. "generic" Spanish).

Fixes godotengine#40703.
@akien-mga akien-mga added enhancement topic:core cherrypick:3.x Considered for cherry-picking into a future 3.x release labels Sep 16, 2021
@akien-mga akien-mga added this to the 4.0 milestone Sep 16, 2021
@akien-mga akien-mga requested review from a team as code owners September 16, 2021 07:38
@akien-mga
Copy link
Member Author

Test on my system (Linux with en_DK locale):

print(OS.get_locale())  # en_DK
print(OS.get_locale_language())  # en

@akien-mga
Copy link
Member Author

Note to self: Before cherry-picking this for 3.x, #40708 should be cherry-picked too, otherwise OS::get_locale() can't be expected to be reliable cross-platform.

@akien-mga akien-mga merged commit 46e3754 into godotengine:master Sep 16, 2021
@akien-mga akien-mga deleted the os-get_locale-language branch September 16, 2021 12:23
@akien-mga
Copy link
Member Author

Cherry-picked for 3.4.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent locale string between platforms
3 participants