godot-docs
godot-docs copied to clipboard
Add simple example for working with locales / languages
Your Godot version:
Not relevant
Issue description:
The docs for "Internationalizing games" are great, but I couldn't find a simple example of how TranslationServer should be used to switch between languages:
Mainly whether TranslationServer.set_locale("en")
is valid and should be used as such.
Context:
- If I understand correctly locale commonly refers to language + region (e.g.
en_US
English in USA oren_DE
for English in Germany) - But the locale in
Project Settings > Internationalization > Locale > Fallback
is set by default toen
andTranslationServer.set_locale("en")
does work as well (so without a region) - It seems to me Godot is not too strict about locale vs. language
Enhancement
I'd propose to add an example that follows the following principles (which should be good enough for most games):
- Use the user's preferred language (obtained from the OS) -> Godot doesn't seem to do this automatically if I didn't miss anything
- Allow to override manually
- Important in bi- or multilingual countries
- Important for user preference (e.g. when a translation is low quality)
- Ignore region as for smaller games it's often not relevant
Default to user's preferred language
If this is not available it will fall back to Project Settings > Internationalization > Locale > Fallback
(which in most cases should be en
for English)
var user_language = OS.get_locale_language()
TranslationServer.set_locale(user_language)
Settings
It's recommended in your game's settings that you have one option "auto" which uses the computer's default language but allow the players to change languages and store this preference in a file.
How to switch to languages from GD-script
TranslationServer.set_locale("en") # Switch to English
TranslationServer.set_locale("en_GB") # Switch to British English
TranslationServer.set_locale("de") # Switch to German
💡 If something like the above would be desirable I am happy to write a docs entry.
URL to the documentation page (if already existing):
- https://docs.godotengine.org/en/stable/tutorials/i18n/internationalizing_games.html
- https://docs.godotengine.org/en/stable/classes/class_translationserver.html