You use standard GetText formats for translating (PO, MO) and utilizing GetText tools like PoEdit. You can automatically translate strings in Pascal code, declared as resourcestring
(use CastleTranslateResourceStrings
). You can automatically translate user interface (use TranslateAllDesigns
). You can generate starting file to translate user interface (use GenerateGetTextPo
).
A workflow for translating an application goes like this:
-
Generate POT (PO Template) files containing everything to translate:
-
Generate POT file to translate the user interface by calling GenerateGetTextPo('castle-data:/gui/*.castle-user-interface');
. Place the resulting contents in user_interface.pot
.
-
Generate POT file to translate all resourcestrings using the rstconv
tool from FPC. Place the resulting contents in game.pot
.
-
Create and translate the PO files for each language you support.
For each xxx.pot
, create a file xxx.<language-code>.po
. For example:
Each game.xx.po
should contain a map from English text → localized (Polish, Japanese etc.) text. In contrast, each user_interface.xx.po
should contain a map from internal identifier (qualified component names) → localized (Polish, Japanese etc.) text. Both approaches are possible with GetText.
You can create and edit PO files using any GetText PO editor, like PoEdit. The PO is a text file format, so you can use any regular text editor (like Atom or Emacs) as well.
-
Generate MO files from PO using the GetText msgfmt
tool. Some editors like PoEdit may also do this automatically.
In effect you will get
game.pl.mo
,
user_interface.pl.mo
(Polish translation) and
game.ja.mo
,
user_interface.ja.mo
(Japanese translation).
-
In game, determine user preferred language, e.g. using CastleSystemLanguage
.
Then translate things by loading appropriate MO file.
-
To translate all user interface that will be loaded, call TranslateAllDesigns('castle-data:/translations/user_interface.ja.mo');
(where "ja" stands for Japanese localization, just an example).
-
To translate resourcestrings, call CastleTranslateResourceStrings('castle-data:/translations/game.ja.mo');
.