GnuGetText tools for Delphi |
|
GnuGetText
GnuGetText is a system for developing multilingual applications. Various programming
languages are supported, including C, C++, Python and Java.
Support for Delphi (Pascal) is missing, however.
In 2003 an extension of this system for Delphi was provided for the first time
by Lars B. Dybdahl:
GNU Gettext for Delphi.
Unfortunately there is no further
development worth mentioning since 2008. Also the handling of applications with
support for multiple languages is a bit cumbersome. The present program package
offers, in addition to the revised versions of the original programs, a new user
interface (GgtTranslate), which combines all
the necessary steps for creating and editing translations under one roof, and
several other tools for editing and integrating translations into your own programs.
Basis for all translations is a Delphi application, where all texts (strings), which are displayed to the user, are specified in a source language, preferably English. First a po template (text file) with the strings in the source language (e.g. English) is created from the program source texts as a template for the translations. From this template the language specific po file can be created with a suitable editor, e.g. PoEdit, by translating string by string. If later in the program changes are made to the strings or new strings are added, the language-specific po file only needs to be updated. All strings that have already been translated will be preserved:
msgid "" msgstr "" "Project-Id-Version: Delphi-Units - Deutsche Übersetzung\n" "POT-Creation-Date: 2023-08-31 17:05+0200\n" "PO-Revision-Date: 2023-08-31 17:06+0200\n" "Last-Translator: J. Rathlev <name@mail.de>\n" "Language-Team: J. Rathlev <name@mail.de>\n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" #. Programmer's name for it: rsExecuteError #: UnitConsts.pas:47 msgid "Error executing process" msgstr "Fehler beim Ausführen eines Prozesses" #. Programmer's name for it: rsAnyKey #: UnitConsts.pas:125 msgid "Strike any key to continue ..." msgstr "Drücken Sie eine beliebige Taste, um fortzufahren ..."
The first section (header) contains general information about the translation, especially the abbreviation for the language used (here de_DE) and the character encoding used (UTF-8). This is followed by the sections containing the individual strings in the original wording (msgid) and the corresponding translation (msgstr). Lines starting with # contain comments, e.g. the name of the source code file (UnitConsts.pas with the line number and further notes.
Download the comprehensive manual.
When creating the po template (see above) the following strings are recognized:
In addition, the GnuGetText.pas unit must be included in the Delphi program.
The po file (text) created in this way is then converted into a mo file (binary).
In order for this to be found when the application is started, it must be located at
a very specific subdirectory of the exe file:
locale\<Lang-Id>\LC_MESSAGES\
(<Lang-Id> = de, fr, es, etc.)
Example: c:\Program Files (x86)\Delphi GetText\locale\de\LC_MESSAGES\default.mo
For the function of the provided Delphi tools some programs from the original GnuGettext package are needed:
These files are included in the installation package, but can also be downloaded from GitHub The source codes can be found on the Gnu portal.
The described programs are provided as Windows setup. After downloading, the setup is started by double-clicking. The permissions of an administrator are required for installation. During the installation it can be selected whether the programs of the package can be started directly via the Windows context menus.