This document applies to the latest version. If you haven't got the latest version, please download it now.
1) Modify your source code.
Add gnugettext.pas to your project.
Add gnugettext to the uses clause of all units that contains forms.
Add the following line to the OnFormCreate event of your forms:
Add typical ignores just before the TranslateComponent (self) you put in the main form.
2) Extract the text to be translated into .po files:
Click with the right mouse button on the file folder that contains your Delphi source code, and choose "GG Extract translations to template".
This will create a file named default.po with all the texts to be translated. Because it has no translations in it, it is named a "translation template".
3) Preparing the translation
If you haven't translated anything yet, copy your .po file to a subfolder and proceed to step 4).
If you have an old translation of your program, click with the right mouse button on that old translation, and choose to "Merge template". Here, you must specify the .po file that was generated in step 2). This will update your old .po file to contain the new texts, and it will remove unnecessary translations.
4) Translate the .po files with poedit
The easiest way to translate, is to install poedit. It is a free tool, so just get it and install it - it is available for Windows, Macintosh and Linux. It is very easy to use, and when you click the save button, it saves the .po file but also automatically writes an .mo file each time.
5) Deploy your application like this:
The .mo file is a compact, binary file that is much faster for lookups than .po files. It's the one you deploy with your application.
|appdir/locale/de_AT/LC_MESSAGES/default.mo||German translations for Austria|
The directory names for the different languages are either just the two-letter ISO 639 language code or a combination of the ISO 639 language code and the ISO 3166 country code.
In the above example, if the program was running on a German computer, it would first search for the de_DE directory, and then for the de directory because de_DE does not exist.
6) Consider to make a single-file version
You can avoid all the .mo files by including them inside your .exe file. In order to do this, you must first make sure that the above works, and then you right click the .exe file and choose "GG Embed translations":
This will append all the .mo files to the .exe file in a way that makes the .exe file self-contained.
- If you did everything above, you will have translated all strings in your user interface and all resourcestrings. Using resourcestrings works great, but it works much better if you would consider to use the _() syntax instead.
- GNU gettext is designed for translating English language programs to other languages. It is possible to translate from other languages, too, but then the program will be limited to run on computers that use the same character set in ansistrings.