Latest articles
Latest articles of category

How to translate Gettext strings

Guru CMS make use of a PHP module called Gettext to provide its multilingual content.

GetText Portable Object (PO) files are the industry standard for multilingual websites in PHP.
In this tutorial we’ll talk about how to translate PO files and maintain translations up-to-date.

First, let’s explain what the files are.

    * PO – Portable Object. This is the file that you receive back from the translators. It’s a text file that includes the original texts and the translations.
    * MO – Machine Object. The MO file includes the exact same contents as PO file. The two files differ in their format. While a PO file is a text file and is easy for humans to read, MO files are compiled and are easy for computers to read. Your web server will use the MO file to display the translations. You do not need to edit the MO file.

Since PO files are so popular, there are several excellent tools for translating them.
The best known tool is a program called Poedit. Poedit is a tool for translators. It allows merging between new texts in a POT file (compared to the current translation in the PO file) and produces both PO and MO as output.

Poedit is available for all major Operating Systems; that is Linux, Windows, Mac OSx. You can however download direct the source files and compile them to your architecture.

Poedit Download Page

Additional programs to use for translation

Recommended PO file editors are (in no particular order):


  • XEmacs (with po-mode): runs on Unices with X
  • GNU Emacs (with po-mode): runs on Unices and Windows
  • KBabel: runs on KDE
  • Lokalize: the replacement of KBabel in KDE4. Formally known as KAider
  • poEdit: Linux, MacOSX, and Windows
    poEdit does support multiple plural forms since version 1.3..
  • OmegaT is another translation tool that can translate PO files. It is written in Java so it is available for multiple platforms (including GNU/Linux and Windows). It can be downloaded from SourceForge.
  • For Mac OS X there is AquaEmacs and a port of GNU Emacs available using carbon for OS X. Also see the Emacs wiki for more usage help and tips. po-mode is not included, but is easy to add. Get it from the GNU gettext distribution.
  • GNU Gettext (Linux/Unix) used for the GNU Translation Project. Gettext also provides msgmerge that makes merging translations easy.
  • Vim (Linux/Unix and Windows versions available) with PO ftplugin for easier editing of GNU gettext PO files.
  • LocFactory Editor (OS X).
  • gted is an eclipse plugin that turns eclipse into a gettext editor. Eclipse is written in Java, so this editor is platform independent.
  • gtranslator has been around and works fine under GNU/Linux:
  • Virtaal: Linux and Windows
    Native support for Gettext PO translation as well as XLIFF and other formats. Simple interface with powerful machine translation, translation memory and terminology management features.

Be sure to get a recent version for all editors, multiple plural forms are a recent addition to the gettext standard.

How to merge translations

Say you have fr.po, a translation of some module. The module gets updated and some strings change. You now have an updated module.pot which is blank. You now need to merge the changes into your translation, without loosing the strings previously translated.

First, check with your usual PO editor if it has a merge function.

Otherwise, you can try the UNIX CLI tool msgmerge, which comes together with GNU gettext.


Better yet, you can use, a bash msgmerge wrapper function by the KDE team. Download the file, and put it in your /bin folder (somewhere in your $PATH). You will need to have GNU gettext version 0.16 or newer installed on your system. Then enter the following fr.po module.pot

where fr.po is your old translation, and module.pot, the updated pot for the module. After that, open fr.po with your usual PO editor.

A few tricks for translation managers
Large .po files

To speed-up your work with a huge .po files (larger than a few MB) you always can do some optimization by clearing untranslated messages as follows:
msgattrib -s --no-location --translated huge.po > clean_file_for_import.po

Removing duplicates

You can remove duplicates as follows:msguniq -u --no-location --strict with_duplicates.po > clean_file_for_import.po

Posted on: 17/06/2016