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 translation #9

Open
SammygoodTunes opened this issue Oct 12, 2024 · 4 comments
Open

Add translation #9

SammygoodTunes opened this issue Oct 12, 2024 · 4 comments

Comments

@SammygoodTunes
Copy link
Owner

Implement text translation and a language menu.

@onihilist
Copy link
Contributor

I can do that i guess if you want bro 🤠

@SammygoodTunes
Copy link
Owner Author

SammygoodTunes commented Nov 1, 2024

Sure.

Here's some info to get you started:

  • en.yml and fr.yml are both files containing translations to various texts in the game
  • They must be exactly the same (except for the translated texts obviously and the locale namespace "en", "fr", etc)

If you want to create a new language:

  • Create a .yml file (not .yaml because otherwise the i18n module won't detect it) with the abbreviated version of the language (for example: "en" for English so -> en.yml)
  • Copy over the contents of another .yml file and make sure to change the locale namespace (first line) so that it matches the name of your .yml file (so if your file is called en.yml, then the locale namespace must be en:
  • Once you've done all that, you must add it to the locale dict in the game/utils/translator.py module - this is how the language appears in the language SelectBox (in the options menu)

If you're adding a new translated text to one of the language files:

  • Choose a good and appropriate namespace(s) for the text that you're translating - e.g.: if the text is about world themes, then the namespaces should be something like:
# en.yml
en:
  world:
    themes:
      default: Default
  • Call the setter functions for setting the text of the UI components within the translate() method of the UI that you want to translate (all UIs are found in the game/gui/screens package) - this is where you'll update all the UI components' text:
from game.utils.translator import translator as t  # Importing the translator module

t.t('path.to.translated.text')  # Getting the translated text using the translator

# The setter functions for changing the text varies from widget to widget: 
label.set_text(TEXT_HERE)  # For labels
button.label.set_text(TEXT_HERE)  # For buttons 
checkbox.title_label.set_text(TEXT_HERE)  # For checkboxes
selectbox.set_tooltip_text(TEXT_HERE)  # For selectboxes
# etc.
  • Once you're done implementing the translation for a specific screen, call the translate() method in the game/gui/screen_manager.py:perform_translate() method, and it should be good.

Feel free to look at the game/gui/screens/options_screen module if you need an example, the translation for that screen is done.

Si jamais tu vois des corrections à faire au niveau de ce qu'il y a déjà dans les fichiers yml (ou à l'avenir), n'hésites pas bien sûr.

@onihilist
Copy link
Contributor

Hey,

Few PR are already done for mainmenu_screen & gameover_screen.
I also add Polski & Russian to the traduction.
I'm omw for the others screens

@SammygoodTunes
Copy link
Owner Author

Don't forget to call the translate() methods inside the perform_translate() method of the screen_manager module.

See here.

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

No branches or pull requests

2 participants