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

Add simple example for working with locales / languages #9684

Open
stephanbogner opened this issue Jul 31, 2024 · 2 comments
Open

Add simple example for working with locales / languages #9684

stephanbogner opened this issue Jul 31, 2024 · 2 comments

Comments

@stephanbogner
Copy link

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 or en_DE for English in Germany)
  • But the locale in Project Settings > Internationalization > Locale > Fallback is set by default to en and TranslationServer.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):

@skyace65
Copy link
Contributor

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

@stephanbogner
Copy link
Author

@skyace65 I added a pull request :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants