Soluling home   Document home


gettext and PO Localization and Internationalization

gettext (Wikipedia) is a popular resource file format used, especially in Lazarus, PHP, Python,and Linux applications. PO is another name for gettext. Soluling localization tool and service support gettext and PO files.

The end of the document contains links to get the full source code of the samples. After reading this document, we recommend reading a tutorial about how to use Soluling.

Localization Process

A .po/.pot file contain one or more strings. Let's look at a sample file. You can find it from <data-dir>\Samples\PO\Simple\Simple.pot.

#: Simple.cpp:3
#, c-format
msgid "Hello World"
msgstr ""

The sample contains one string. The id is "Hello World," and the value is an empty string. The first line contains a comment (# is a comment marker) that contains the location where the string was extracted from. The second line contains flags. In this case, it tells the format of the source text (C/C++). The third line contains the string id and the fourth line the string value (most ofter empty in .pot files). This is what you get when you run xgettext tool to extract strings from your source code into a .pot file.

The Finnish file is identical to the original except the name of the file name is Simple_fi.po, and the msgstr lines contain Finnish values.

#: Simple.cpp:3
#, c-format
msgid "Moi maailma"
msgstr ""

Either of the values in the string item can have multiple lines. In the case of a multi-line string, the value starts with an empty string "" following by any number of strings.

#: Features.cpp:3
#, c-format
msgid ""
msgstr ""

The id of the above item is


PO supports pluralized strings.

#: Plural.cpp:3
#, c-format
msgid "%d file"
msgid_plural "%d files"
msgstr[0] ""
msgstr[1] ""

A pluralized string contains a variable amount of msgstr values starting with index 0 and containing all different pluralized forms that the language uses. English, like most other Western languages, use two forms: singular and plural. msgstr[0] contains singular form and msgstr[1] contains plural form. Soluling correctly scans a pluralized message and lets you enter translations with the correct amount of forms.

Most .pot files contain a header item as the first item. The header item has an empty message-id.

msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-07-11 14:18+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <>\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

The header can contain various information such as the character set used in the file, creating date, translator's name, etc. When Soluling scans the .po/.pot file, it extracts the items and some fields from the header (if any). The header field is stored into a Translator sub-node in the project tree. Use the Options sheet to configure what items to extract and what value to use as a context value of extracted items.

When Soluling creates a localized .po file, it, by default, also compiles them into binary .mo file that you can deploy with your application. Use the Write options sheet to configure how to create the localized .po files and select if to compile the .mo files.


gettext has a plural enabled format function: ngettext. Soluling fully supports gettext's plural forms. When Soluling creates localized .po files, it fills, the right amount of grammatical gender patterns and writes the right value into the .po header's Plural-Forms field.

See <data-dir>\Samples\PO\Plural sample.


GitHub and <data-dir>\Samples\PO contains following samples:

Directory Description Notes
Simple A simple C++ source code that contains few strings. Try this first!
Plural A sample that shows how to use plural messages.  

In addition Lazarus, PHP and Python samples show how to localize PO files.

Configuring gettext/PO Localization

You can configure how to localize your PO file by selecting the item in the project tree, right-clicking, and choosing the Options menu. A source dialog appears that lets you edit the options. This source uses the following option sheets.