Skip to main content
Gettext (.po, .pot)
Nick Ustinov avatar
Written by Nick Ustinov
Updated this week

Gettext files (.po, .pot) are widely used for managing translations in software projects. A PO (portable object) file is made up of many entries, each holding the relation between an original untranslated string and its corresponding translation.

POT (portable object template) files are similar but serve as templates for creating new PO files. All entries in a PO file usually pertain to a single project, and all translations are expressed in a single target language. This format is commonly used in projects that require localization, providing a structured way to handle translations.

Technical information

Overview

Format name:
Gettext

File extensions:
.po, .pot

Common use cases:
Managing translations in software projects, particularly those requiring localization into multiple languages.

Technical details:

  • Structure: Gettext files consist of multiple entries, each containing an original string and its corresponding translation. The structure includes:

    • Header: Metadata about the file.

    • Entries: Each entry contains the original string (msgid) and the translated string (msgstr).

    • Comments: Provide context or instructions for translators.

  • Encoding: UTF-8

Example:
Here's an example of a typical PO file:

msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2021-10-10 12:00+0000\n"
"PO-Revision-Date: 2021-10-10 12:00+0000\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"

#: src/main.c:55
msgid "Hello, world!"
msgstr "Bonjour, le monde!"

#: src/main.c:76
msgid "File not found"
msgstr "Fichier non trouvé"

In this example, each entry starts with a comment (optional), followed by the msgid (original string) and msgstr (translated string). The header provides metadata about the file.

Using with Lokalise

Lokalise supports Gettext files, making it easy to manage your translations within the platform. When working with PO or POT files in Lokalise, you can import, edit, and export translations seamlessly. Lokalise provides tools to handle the metadata and context comments efficiently, ensuring accurate translations.

Supported project types

Please note that Gettext files can be uploaded only to Web and mobile projects.

Headers

As you upload the source .po files, Lokalise extracts the header and adds an archived key lokalise.po.header with the header content. To edit the contents, in the project editor, click Filter > QA > Archived. Copy/paste the contents of the header to all languages if required. You can also manually create this key if necessary.

Descriptions and comments

Please note that if you are uploading a translation file with multiple descriptions, all additional descriptions will be stored under the comments for the key. Upon downloading such keys, you'll need to include both comments and descriptions in the export bundle.

Known limitations and special notes

  • Complex entries: PO files can become complex with multiple context-specific entries, which may require careful management.

  • Manual editing: While PO files are human-readable, manual editing can be error-prone and time-consuming for large projects.

  • Key support one Lokalise: Lokalise parses the following keys:

#: (reference)
# or #@ or #. (comment)
#, fuzzy (fuzzy flag)
msgctxt
msgid
msgid_plural
msgstr
  • Obsolete terms marked with (#~) are not imported from .po and .pot files.

  • Plural forms are accepted. However Lokalise does not add/update language-specific plural form headers to Gettext files, so you'll have to add those manually, for example (note the last Plural-Forms header):

"Project-Id-Version: Sample 1.0.1\n"
"Report-Msgid-Bugs-To: support@example.com \n"
"Last-Translator: Username <user@example.com>\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

You can find the table with all the plural headers in the following document.

Additional reading

Did this answer your question?