godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.78k stars 3.07k forks source link

Add simple example for working with locales / languages #9684

Open stephanbogner opened 1 month ago

stephanbogner commented 1 month ago

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:

Enhancement

I'd propose to add an example that follows the following principles (which should be good enough for most games):

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):

skyace65 commented 1 month ago

If you'd like to do this change then you can make a PR, help with the docs is always appreciated.