You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
4.0 KiB
Plaintext

<!--201001,201112-->
<h1>blessfrey in japanese </h1>
october 29, 2020<br>
#internationalization #localization<br>
<br>
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. <br>
<br>
I followed along with GoTut's <a href="https://www.gotut.net/localisation-godot/">"Localisation in Godot"</a> 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. <br>
<br>
<h2>step 1 - make your spreadsheet </h2>
<br>
<center>
<a target="_blank" href="/static/img/ent/internationalization_spreadsheet.png">
<img src="/static/img/ent/internationalization_spreadsheet.png" alt="(image: spreadsheet with three columns - id, en, and ja. id has ids, en has English text, and ja has Japanese text.)" width="500" height="232.26">
</a><br>
</center>
<br>
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. <br>
<br>
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 <a href="https://docs.godotengine.org/en/latest/tutorials/i18n/locales.html#doc-locales">Godot Docs</a>. <br>
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. <br>
<br>
Save your spreadsheet as a .CSV file. <br>
<br>
<br>
<h2>step 2 - import your spreadsheet </h2>
<br>
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. <br>
<br>
<center>
<img src="/static/img/ent/internationalization_translations.png" alt="(image: Project Settings>Localization>Translations shows a TRANSLATION file for each language.)"><br>
</center>
<br>
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. <br>
<br>
<br>
<h2>step 3 - refer to your ids in your scripts </h2>
<br>
<center>
<img src="/static/img/ent/internationalization_script.png" alt="(image: example of an id used in a script)"><br>
</center>
<br>
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 <code>label.set_text("quit")</code>, you'd write <code>label.set_text(tr("quit_game"))</code>. In this example, the id is "quit_game" and its corresponding text in English is "quit."
<br>
<br>
<h2>step 4 - set the game's language </h2>
<br>
<center>
<img src="/static/img/ent/internationalization_setlocale.png" alt="(image: example of setting the locale in a script)"><br>
</center>
<br>
Set the locale in your script, somewhere like _ready() or on a 'change language' button. Here's the line for setting the locale: <code><a href="https://docs.godotengine.org/en/stable/classes/class_translationserver.html">TranslationServer</a>.<a href="https://docs.godotengine.org/en/stable/classes/class_translationserver.html#class-translationserver-method-set-locale">set_locale</a>(<a href="https://docs.godotengine.org/en/stable/tutorials/i18n/locales.html">"ja"</a>)</code>
<br>
<br>
<h2>step 5 - continue adding to your spreadsheet </h2>
<br>
Now that everything's in place, you can keep adding new ids + translations, and Godot will automatically use your changes in-game. <br>
<br>
<h2>that's the basics </h2>
<center>
<img src="/static/img/ent/internationalization_japanese.png" alt="(image: blessfrey screenshot in Japanese)" width="500" height="370.46"><br>
</center>
<br>
It all comes together for an old screenshot of blessfrey's main menu in my broken Japanese. やべーな!<br>
<br>