Gettext PO Import / Export
Using the gettext PO file format to import/export content in your apps
Within the Localize dashboard we provide you with an ability to import and export phrases and translations in various file formats.
You can also import/export Glossary terms.
To see a general explanation of how importing and exporting works in Localize, click here.
The gettext PO file format is used in Django apps, among others.
UTF-8 File Format
Be sure that you are using the UTF-8 file format when working with the external files you are creating for importing purposes.
Importing Phrases or Glossary Terms
Before importing, make sure your file adheres to the file requirements below.
Navigate to the File Import / Export: Import tab in your dashboard.
- Drag-and-drop a file to import into the box, or select a file to import.
- Select GETTEXT PO under File Format.
- Select the language you are importing.
- Specify the import type: Phrases or Glossary terms
- Click the Submit button.
- Wait for the file to be uploaded.
- Success! View the file details to see how many phrases were created, updated, etc.
After importing a source language file, Localize will show the phraseKey along with the phrase in the Localize dashboard.
Exporting Phrases or Glossary Terms
Import First!
gettext PO files for the source language must first be imported into the Localize dashboard so that the
msgid
is established for each phrase. Then upon subsequent exports, themsgid
will be maintained.Exporting phrases for which there is no
msgid
will result in an unusable gettext PO file!!!
Navigate to the File Import / Export: Export tab in your dashboard.
- Select GETTEXT PO under File Format.
- Select a filter which will determine which phrases get exported:
a. Published translations
b. Machine translations
c. Human translations
d. No translations
e. Needs human translations - Select the language you are exporting.
- Specify the export type: Phrases or Glossary terms
- Click the Export button.
- Wait for your download to complete, then close the popup dialog.
Exporting Selected Phrases
Alternatively, you can filter exactly which phrases that you want to export on the Phrases page. Find out how...
File Requirements
The following are the requirements for the gettext PO file format.
You can have as many comment lines and info lines as you want at the start of the file. Data will only start to be processed once the msgid
and msgstr
pairs start.
The following header data is optional:
Project-Id-Version
: 1\nMIME-Version
: 1.0\nContent-Type
: text/plain; charset=UTF-8\nContent-Transfer-Encoding
: 8bit\n
The following data is required for each phrase:
msgid
"PhraseKey": this is the key of the phrase as defined in your appmsgstr
"source phrase | target language translation": this is the source phrase in an imported file, or a target language translation in an exported file- Optionally you could have multiple
msgstr
lines for onemsgid
.
- Optionally you could have multiple
The following data is optional for each phrase:
# A comment
: a comment string
Django PO Files
Typically in a gettext PO file that is used in a Django application, there will be an empty
msgid
and amsgstr
at the start of the file.
Example of an imported file for the source language.
# SOME DESCRIPTIVE TITLE.
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-09-04 20:27+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \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"
#: templates/localize.html:1
msgid "welcomeHeading"
msgstr "Welcome to a sample "
msgstr "Django application!"
#: templates/localize.html:2
msgid "subHeading"
msgstr "This is some generic copy to be translated"
#: templates/localize.html:3
msgid "mainText"
msgstr "We hope it helps with your localization process."
Example of an exported file for the target language of Spanish.
#
msgid ""
msgstr ""
"Project-Id-Version: 1\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "mainText"
msgstr "Esperamos que le ayude con su proceso de localización."
msgid "subHeading"
msgstr "Esta es una copia genérica para traducir"
msgid "welcomeHeading"
msgstr "¡Bienvenido a una aplicación de muestra de Django!"
Not available in Web projects
The Gettext PO file format is not available in Web-based projects, because it is a format traditionally used in mobile app development.
Troubleshooting
If your import fails you can view the error here under Import History.
Updated about 3 years ago