SDB:Localization work with po files
What is po file
Dialogs and menus of an application, which should be translated, are stored in the po file. The po file is a file with special structure and suffix .po. It contains information about the language, translators, original dialogs and translated dialogs. Original dialogs starts with msgid and they are followed by their translation started with msgstr. Information about language and translator are at the beginning of the po file. If no translated dialog or menus is available, the msgstr part is empty. The sign # means, that the line is a comment.
The example of the empty translation:
#: src/PackageCommands.cs:57 src/PackageCommands.cs:3181 msgid "Search for a match to any of the search strings" msgstr ""
The example of the Czech translation:
#: src/PackageCommands.cs:57 src/PackageCommands.cs:3181 msgid "Search for a match to any of the search strings" msgstr "Vyhledat výsledek odpovídající alespoň některému z řetězců"
What is pot File
The pot file is a template for the translation. The format of the pot file is similar to po file but it includes only original English text and no information about language or translators. From the pot file are created po files. If your created po file manually in a text editor, you need add information about your language and save the file with suffix .po. If you create the beginning of the po file incorrectly, the po file will not pass the syntax check and in the statistics will have violet color and zero translated and fuzzy strings.
The beginning of the rug.pot:
# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2006-05-02 20:04-0400\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" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n"
The beginning of the rug.hu.po:
# translation of hu.po to # Peter Breuer <email@example.com>, 2003. # Marcel Hilzinger <firstname.lastname@example.org>, 2003. # Marcel Hilzinger <email@example.com>, 2004. # Szabolcs Varga <firstname.lastname@example.org>, 2004, 2005. # Kalman Kemenczy <email@example.com>, 2006. msgid "" msgstr "" "Project-Id-Version: hu\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2006-06-08 12:58+0200\n" "PO-Revision-Date: 2006-06-08 17:26+0200\n" "Last-Translator: \n" "Language-Team: <firstname.lastname@example.org>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: KBabel 1.11.2\n" "Plural-Forms: nplurals=1; plural=0;\n"
How to Translate po Files
All you need to start localization is a text editor and fill all empty msgstr with your translations. But maybe you find a special translation tool more convenient to do it.
Original English text in the po file started with msgid is not possible to change. You can change only translation. If you find an error in the original English text, please use Bugzilla to report it. All wrong texts must be fixed in the source code of the application first and then will be generated a new pot file.
There are two different ways how-to define shortcuts:
msgid "&Add..." msgstr "&Hozzáadás"
msgid "_Add" msgstr "_Hozzáadás"
You can select any letter of your translated string and also place the shortcut symbol to different position, but the shortcut symbol must be same as in the original strings. If it used & in the original string, you must also use the symbol & in your translation. If it is not possible to add shortcut directly to the string, use this syntax:
msgid "&Add..." msgstr "新增(&A)"
msgid "_Add" msgstr "新增(_A)"
All variables consist of % and one number or letter. Example of string with variable:
msgid "Automatic configuration via %s?" msgstr ""
Variables are obligatory in your translation. If a string contains a variable, you have to use it in your translation too.
In every po file you can find various formating strings. Most of them are same as HTML tags. It can also happens, you find XML tags or formating strings from other languages. All these strings are obligatory in your translation. If you omit a string, the translation will not pass the syntax check.
if all lines except the last in the original string end with \n you can have in your translation only the last line without \n even if you have in your translation more or less lines than in the original string. All other lines must end with \n.
String with a plural in a pot file:
msgid "%1 second" msgid_plural "%1 seconds" msgstr "" msgstr ""
Translation of the string with one plural form (zh_CN):
msgid "%1 second" msgid_plural "%1 seconds" msgstr "%1 秒"
Translation of the string with two plural forms (Greek):
msgid "%1 second" msgid_plural "%1 seconds" msgstr "%1 δευτερόλεπτο" msgstr "%1 δευτερόλεπτα"
Translation of the string with three plural forms (Czech):
msgid "%1 second" msgid_plural "%1 seconds" msgstr "%1 sekunda" msgstr "%1 sekundy" msgstr "%1 sekund"
In the KBabel you should first setup the plural forms definition in the project settings. If is your setting correct, KBabel will provide for each plural form separate tab.
Before committing the po file to the SVN, check the syntax of the po file. To do it, use msgfmt with parameter -c or check functionality in your translation application.
- POEditor - web-based translation tool for gettext po files and other popular localization formats
- KBabel Manual (outdated)
- Lokalize - Lokalize is a KDE4 for translations
Main Page: openSUSE:Localization_guide