Use gettext
The GNU gettext library is the standard for translating applications to other languages. There are many tools like poedit that assist a translator.
Some links:
- http://www.gnu.org/software/gettext/ (gettext homepage)
- http://www.gnu.org/software/gettext/manual/gettext.html#Pascal (gettext manual, Pascal section)
- http://wiki.freepascal.org/Translations_/_i18n_/_localizations_for_programs/de (FPC + gettext)
- http://dxgettext.po.dk/ (Delphi + gettext)
These are the steps for getting gettext to work:
1. mark strings as localized, either by
1.1. defining them as a resourcestring
1.2. marking them by a _() function
2. extract the marked strings to a .po file (
3. copy the .po to a localized file, e.g. ultrastardx.po -> ultrastardx.de.po and translate the strings
4. compile the .po files into .mo files
5. load the .mo file of the user specified language from the application (the language selection is not fixed during runtime)
Remarks to 1)
- The gettext manual proposes the "resourcestring" approach for pascal
- The xgettext tool is not able to parse pascal code for _() functions. This is only possible for C/C++/C#/PHP/Java/Perl and almost all other languages except Pascal.
- The Lazarus IDE has integrated support for the creation of .po-files from resourcestrings. If Lazarus is not available we can still use "rstconv -i *.rst -o *.po" (rstconv is part of FPC) for this task from a Makefile.
- dxgettext is a command-line tool that is able to parse pascal code with either resourcestrings, _() "markers" or both. In addition it has great Delphi support. There are linux + mac versions too but they are not included in any linux repository (Ubuntu etc.) so we have to compile them ourselves (using the pre-compiled linux binaries is not a good idea).
Remarks to 4)
- compilation of .po to .mo files can be done with msgfmt, either by a Makefile or by adding it into the post-compile action of the lazarus compilation options of the USDX project file
- poedit is able to compile .po files to .mo too and could be used for delphi, dxedit will probably work too
- the .mo files seem to be machine (win, linux, mac, x86, x86_64) dependent so compiling them once and checking them into svn will probably not work
- Maybe it is possible to use the .po files directly, that would make things easier especially on windows. They are not as fast as the .mo files but probably still faster than the current .ini approach of USDX
Questions:
- Should we use "resourcestring" or a _() function? Although the latter one seems to be the better approach it does not work without dxgettext and might be a struggle to get it to work on non-windows systems.
- How do we create those .mo files with least effort on windows? (This is not a problem for systems with "native" Makefile support)
- which pascal headers should we use? The FPC or the dxgettext ones?
Proposal 1:
- Use "resourcestring" to mark strings
- Windows users should use either Lazarus or Delphi + dxgettext
- Add rstconv and msgfmt calls to the Makefile so Linux + Mac users can go on as usual
Proposal 2:
- Use _() to mark strings
- Windows users HAVE to install dxgettext (and have to integrate it into the windows file-explorer by this)
- Linux + Mac:
- copy the dxgettext code into the USDX tools dir
- add a rule to build dxgettext to the Makefile
- start dxgettext on the USDX sourcecode from the Makefile
Somebody should open an SVN branch an experiment a little bit with gettext.
Some links:
- http://www.gnu.org/software/gettext/ (gettext homepage)
- http://www.gnu.org/software/gettext/manual/gettext.html#Pascal (gettext manual, Pascal section)
- http://wiki.freepascal.org/Translations_/_i18n_/_localizations_for_programs/de (FPC + gettext)
- http://dxgettext.po.dk/ (Delphi + gettext)
These are the steps for getting gettext to work:
1. mark strings as localized, either by
1.1. defining them as a resourcestring
1.2. marking them by a _() function
2. extract the marked strings to a .po file (
3. copy the .po to a localized file, e.g. ultrastardx.po -> ultrastardx.de.po and translate the strings
4. compile the .po files into .mo files
5. load the .mo file of the user specified language from the application (the language selection is not fixed during runtime)
Remarks to 1)
- The gettext manual proposes the "resourcestring" approach for pascal
- The xgettext tool is not able to parse pascal code for _() functions. This is only possible for C/C++/C#/PHP/Java/Perl and almost all other languages except Pascal.
- The Lazarus IDE has integrated support for the creation of .po-files from resourcestrings. If Lazarus is not available we can still use "rstconv -i *.rst -o *.po" (rstconv is part of FPC) for this task from a Makefile.
- dxgettext is a command-line tool that is able to parse pascal code with either resourcestrings, _() "markers" or both. In addition it has great Delphi support. There are linux + mac versions too but they are not included in any linux repository (Ubuntu etc.) so we have to compile them ourselves (using the pre-compiled linux binaries is not a good idea).
Remarks to 4)
- compilation of .po to .mo files can be done with msgfmt, either by a Makefile or by adding it into the post-compile action of the lazarus compilation options of the USDX project file
- poedit is able to compile .po files to .mo too and could be used for delphi, dxedit will probably work too
- the .mo files seem to be machine (win, linux, mac, x86, x86_64) dependent so compiling them once and checking them into svn will probably not work
- Maybe it is possible to use the .po files directly, that would make things easier especially on windows. They are not as fast as the .mo files but probably still faster than the current .ini approach of USDX
Questions:
- Should we use "resourcestring" or a _() function? Although the latter one seems to be the better approach it does not work without dxgettext and might be a struggle to get it to work on non-windows systems.
- How do we create those .mo files with least effort on windows? (This is not a problem for systems with "native" Makefile support)
- which pascal headers should we use? The FPC or the dxgettext ones?
Proposal 1:
- Use "resourcestring" to mark strings
- Windows users should use either Lazarus or Delphi + dxgettext
- Add rstconv and msgfmt calls to the Makefile so Linux + Mac users can go on as usual
Proposal 2:
- Use _() to mark strings
- Windows users HAVE to install dxgettext (and have to integrate it into the windows file-explorer by this)
- Linux + Mac:
- copy the dxgettext code into the USDX tools dir
- add a rule to build dxgettext to the Makefile
- start dxgettext on the USDX sourcecode from the Makefile
Somebody should open an SVN branch an experiment a little bit with gettext.
Leave a comment