Gettext - PO/POT

Last updated: September 09, 2024Author: Jakub Pomykała
po-pot
File format value
po-pot

Gettext is a commonly used system for software localization and internationalization. It was released initially in 1990, and it's still widely used in many Unix-like systems. Thanks to gettext, you can easily separate source code logic from texts in your application.

We can distinguish 2 different file formats:

  • POT file format, acronym stands for Portable Object Template which is used as a template for translating text, it does not contain translated messages, only message ids, comments, and contexts. You can treat it as a template.
  • PO file format, acronym stands for Portable Object which is a translation record which contains same values like POT file, but it also contains translated strings for single language.

File format example

# Single line
msgctxt "Translation context"
msgid "Translation key"
msgstr "Translation message"

# Multiple lines
msgid ""
"The input text "
"split to several "
"lines"
msgstr ""
"Translation "
"can also be splitted."

Example gettext usage

printf(gettext("Hello world! I'm %s.\n"), application_title);
printf(_("Hello world! I'm %s.\n"), application_title); // shorter version

Upload with CLI

simplelocalize upload --apiKey <PROJECT_KEY> \
  --uploadFormat po-pot \
  --uploadPath ./messages_{lang}.po

Learn more about SimpleLocalize CLI and translations upload feature.

Download with CLI

simplelocalize download --apiKey <PROJECT_KEY> \
  --downloadFormat po-pot \
  --downloadPath ./messages_{lang}.po

Learn more about SimpleLocalize CLI and translations download feature.

Import with API

curl
    --request POST \
    --url 'https://api.simplelocalize.io/api/v2/import?uploadFormat=po-pot&languageKey=en' \
    --header 'x-simplelocalize-token: <API_KEY>' \
    --form file=@/path/to/your/messages.po

Learn more about importing translations with API

Export with API

curl
    --request GET \
    --url https://api.simplelocalize.io/api/v3/export?downloadFormat=po-pot \
    --header 'x-simplelocalize-token: <API_KEY>'

Learn more about exporting translations with API

Was this helpful?