-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Improve locale detection. #52969
Improve locale detection. #52969
Conversation
Thanks for working on this, it's been a sore point and the hardcoded list we had was far from exhaustive. But I wonder - is there really any merit to limit what can be valid locales? In practice we mostly need locales to match translation identifiers, so if someone happens to have a locale of say So the only country-specific information we'd need to hardcode IMO is just what's the "main" country code to fall back to if there's no translation matching the exact locale:
|
6a17a75
to
e8dad0a
Compare
Now it should work with all supported locales on Linux (tested with the list in Changes in this PR:
|
e8dad0a
to
e6a9162
Compare
e6a9162
to
3579754
Compare
core/string/translation.cpp
Outdated
// Additional script information to preferred scripts. | ||
// Language code, script code, default country, supported countries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reference you used for those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same references as language lists.
core/string/translation.cpp
Outdated
{ "US", "United States of America" }, | ||
{ "UY", "Uruguay" }, | ||
{ "UZ", "Uzbekistan" }, | ||
{ "VA", "Holy See" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol, I never knew this was the official name.
core/string/translation.cpp
Outdated
// - https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes | ||
// - https://lh.2xlibre.net/locales/ | ||
// - https://iso639-3.sil.org/ | ||
// - https://www.localeplanet.com/icu/index.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all of these still used to make this list? If not, it would be good to narrow down to a single source so that we know how to sync potential changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have used multiple sources to make sure every language supported by the OS is in the list, but some links the might be excessive and have the same list, I'll re-check it.
core/string/translation.cpp
Outdated
if (split == -1) { | ||
split = p_locale.find("-"); | ||
String TranslationServer::standardize_locale(const String &p_locale) const { | ||
// Replaces '-' with '_' for macOS Sierra-style locales. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the reference to "Sierra" still valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sierra
is not relevant, it's used by all macOS versions.
Looks good to me overall, though I'm not sure if we actually get useful information from a hardcoded list of valid countries for a given language. That's obviously a decision ISO and various OSes followed so there might be a good reason, but nothing prevents me from using an OS in French while living in Denmark and thus ending up with a Do we do anything specific with the valid country codes information? |
It's used in two places:
Not sure if checking for the valid language and country code is necessary at all. Just using |
b945923
to
a9eec67
Compare
a9eec67
to
38920a3
Compare
bcd4f13
to
b4178cb
Compare
Use separate language, script and country lists. Add locale selection dialog and property hint.
b4178cb
to
40c56ed
Compare
Thanks! |
Instead of using a hard-coded supported locale list and expecting OS locale to match, the engine now attempts to decompose whatever garbage is returned by the
OS.get_locale()
, infer missing parts and select the best matching locale.Exposes
compare_locales
andstandardize_locale
methods to the scripts.So far it's tested on macOS only, all supported editor translations seem to be detected correctly.