Godot: Internationalization eh?

By cyberpuffin, 16 August, 2023

With apologies to my family from our northern neighbor for resorting to linguistic stereotypes, but I promise there's a deeper reason beyond teasing mom.

Accessible Sudoku and Language

Language was not the first thing that I thought of when choosing to add as many accessibility features as would fit into Accessible Sudoku.  During the process of pushing v0.2.0 to the Android Play Store for the first public release, however, a choice had to be made for which region to target distribution.

Perhaps selecting all was a little ambitious, but how hard could it be to make a simple numbers game localized?

Godot's Translation Server

Godot provides a number of low-level "Servers" for common functions.  Relevant to this dev log is the Translation Server.

This server manages translations throughout the interface.

Translation table

Step one is to build a translation table.

Google sheets allows access to Google Translate via formula, not to mention the ease of collaboration, making it a good choice.

See the Importing translation tutorial for more information on structuring the table.  The tl;dr is that the first column is the key and each subsequent column is value of a specific language (as defined by the first row of the table).

From the tutorial:

keysenesja
GREETHello, friend!Hola, amigo!こんにけは
ASKHow are you?CΓ³mo estΓ‘?元気ですか
BYEGoodbyeAdiΓ³sγ•γ‚ˆγ†γͺら
QUOTE"Hello" said the man."Hola" dijo el hombre.γ€Œγ“γ‚“γ«γ‘γ―γ€η”·γ―θ¨€γ„γΎγ—γŸ

Google Translate

As mentioned above Google Sheets gives access to Google Translate  with the GOOGLETRANSLATE([source], "[source language code]", "[target language code]") function.

Example: =GOOGLETRANSLATE(B2, "en", "es") will translate the contents of cell B2 from English to Spanish.

Comma Separated Values

Download the translation table as a CSV file and move into the Godot project.

It's a good idea to put the file in a subdirectory of your project as the CSV importer will create an individual translation file for each language.

note:  Add *.translations to .gitignore as the CSV importer will recreate from the main table as needed.

Configuring the imported translation

Make sure to enable the localizations, as per the tutorial, when adding new languages.

Automatic translations

Now onto the places where automatic translations can happen.  Controls, such as Buttons and Labels, will automatically fetch a translation if their text matches a translation key.

The game preview will show the translation key, but once the game is running the translations are substituted.

Image
Auto translation in action.

eh?

It turns out that there are different dialects of various languages, like English.  Godot knows and supports using the country code to differentiate translations of the same language.

So for us American folks you might setup en_US to be separate from en_GB or en_AU.

en_CA, for example, can be setup to append " eh?" to the end of whatever is found in the en column easily enough with a formula =CONCAT(B2, " eh?").

Why eh?

It started out as a joke for my Canadian mother, but it turned out to be very useful for identifying which controls still needed to be updated.  Anything that wasn't asking me " eh?" wasn't pulling from the translation table.

80 / 20

This is easily the 80%.  The last 20% is going to take a while, hampered most by my lack of linguistic variation.

Next step involves going through the code to find any text assignments to their Translation key counterparts and using the Object class function, tr(), which allows pulling translations from the Translation server by key.

Further steps

Next steps will involve revamping the Font handling in Accessible Sudoku to allow swapping fonts based on the selected locale and seeing if there's a convenient way to switch the direction of the text (ltr -> rtl; ltr -> vertical) to gracefully switch between different languages.

Technology

Comments