Getttext PO/POT format explained¶
Gettext is internationalization (i18n) mechanism and library used not only in many software products, programming languages but also for translating Sphinx documentations. Gettext extracts strings marked “to-be-localized” from a source code (or a document) to plain text file with
.potfile extension. Let’s look at its format.
Before continuing, you might want to read Translating with gettext overview first. Except the process, the post explains the difference between PO and POT files.
See also gettext manual for exhausive PO file reference.
Basically, po/pot is a list of original string - translation couples with comments.
original string is on the line starting with
translation on the next line starting with
comments starts with
very first couple with blank
msgidis a header
# Menu translations from English to Czech msgid "" msgstr "" "Project-Id-Version: Documatt\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-10-15 15:32+0200\n" "PO-Revision-Date: 2021-04-28 14:31+0000\n" "Last-Translator: Matt <email@example.com>\n" "Language: cs\n" "Plural-Forms: nplurals=2; plural=n != 1\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" # terminated with any result, not neccessarily succeeded msgid "Mark as completed" msgstr "Vyřídit jako hotovou" #, fuzzy msgid "Mark as spam" msgstr "Označit jako spam"
msgid and msgstr¶
Unlike some i18n libraries, gettext uses as ID actual original string instead of key. For example, ID is convinient “Do you want to save the file?” instead of “SaveFileQuestionDialog”.
msgids are automatically extracted from source code or Sphinx document.
Actual translation is on the
msgstr line. In template .pot file, it is empty (blank string).
Couples of original-translation are separated with the blank line:
msgid "Mark as completed" msgstr "Vyřídit jako hotovou" msgid "Mark as spam" msgstr "Označit jako spam"
Long strings may be split on multiple lines with
msgid "You can see the URL of the page where the visitor is and the " "information about them is available, such as when the chat started, what " "project the conversation is about, etc. This corresponds to the editor " "layout structure into the following parts:" msgstr ""
However, I highly recommend you to use one long line. It means much easier Git diffs. You can easily wrap long lines in your text editor or viewer.
msgid "You can see the URL of the page where the visitor is and the information about them is available, such as when the chat started, what project the conversation is about, etc. This corresponds to the editor layout structure into the following parts:" msgstr ""
Both orinal and translation has to be in double quote strings. The escape character is
\", newline is
\ will be
msgid "Hello gettext!\n\nBe careful to escape double quotes \" in PO." msgstr ""
Commentscomments powered by Disqus