Soluling home Document home
gettext Localization and Internationalization
gettext (Wikipedia) is a popular resource file format used, especially in PHP, Python, and Linux applications. Soluling localization tool and service support gettext and PO files.
.pot file contain one or more strings. Let's look at a sample file. You can find it from
#: 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 "" "One\n" "Two" 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 "" msgstr ""
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 contains singular form and msgstr contains plural form. Soluling correctly scans a pluralized message and lets you enter translations with the correct amount of forms.
.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 <LL@li.org>\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
.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
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:
|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 PHP and Python samples show how to localize PO files.
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.