blessfrey in japanese

october 29, 2020
#internationalization #localization

Instead of hard-coding text, keep it in a spreadsheet instead. It's easier to organize, edit, and it also makes possible future translations a much smoother process.

I followed along with GoTut's "Localisation in Godot" guide, but the process is pretty simple. It's a great guide, so honestly just follow theirs instead. I'll echo the process here in case it's taken down, though.

step 1 - make your spreadsheet


(image: spreadsheet with three columns - id, en, and ja. id has ids, en has English text, and ja has Japanese text.)

Instead of writing your text directly into Godot, refer to the text by ids instead. These ids will be kept in the first column of your spreadsheet. Don't use spaces.

The rest of the columns will hold the corresponding text in different languages. Name these columns after the language's locale code. English's is en, and Japanese's is ja. You can find the more codes in the Godot Docs.
It works just fine if you're only using one language. If you have multiple languages but don't provide a translation for a specific id, whenever your game is set to that language, references to that script will show blank text.

Save your spreadsheet as a .CSV file.


step 2 - import your spreadsheet


Make sure your .CSV spreadsheet is in your game folder, so Godot can automatically import files. Wherever you import your text, make sure you check 'Comma' for the delimiter or separator options. You'll get a few .TRANSLATION files.

(image: Project Settings>Localization>Translations shows a TRANSLATION file for each language.)

From Godot's top menu, go to Project>Project Settings...>Localization>Translations and add all your .TRANSLATION files. They'll be right next to wherever you saved your .CSV.


step 3 - refer to your ids in your scripts


(image: example of an id used in a script)

It's really simple stuff. Anywhere you would have written a string, like "quit", you instead use its id wrapped in tr(). So instead of label.set_text("quit"), you'd write label.set_text(tr("quit_game")). In this example, the id is "quit_game" and its corresponding text in English is "quit."

step 4 - set the game's language


(image: example of setting the locale in a script)

Set the locale in your script, somewhere like _ready() or on a 'change language' button. Here's the line for setting the locale: TranslationServer.set_locale("ja")

step 5 - continue adding to your spreadsheet


Now that everything's in place, you can keep adding new ids + translations, and Godot will automatically use your changes in-game.


step 6 - insert values into text


Languages differ in syntax, so use format strings.

In your spreadsheet, write %s where your inserted text will go.
(image: in the .CSV, id= character_level, en= Level %s, ja= レバル %s)

Then in your script, write tr("key") % inserted_val in place of the formatted string.

(image: in the script, set_text(tr("character_level") % String(level))

Now the formatted string will appear in-game.

(image: screenshot: Level 1)(image: screenshot: レベル 1)

that's the basics

(image: blessfrey screenshot in Japanese)

It all comes together for an old screenshot of blessfrey's main menu in my broken Japanese. やべーな!