It all boils down to the .POT, .PO and .MO translation files
Here’s a tutorial on how to use Loco Translate plugin for WordPress website translations. It gives an overview about the three required files (PO, POT, and MO) and takes you to the steps how to set them up.
Please note: Some of the links below may be affiliate links, meaning, at no additional cost to you, I will earn a commission if you click through and make a purchase.
- GNU Gettext
- Portable Object (PO) File
- Portable Object Template
- Loco Translate
- FTP / cPanel
- File Manager
Down with the Details
The Portable Object format is a translation coding standard of the GNU operating system (free softwares). It made use of the GNU gettext toolset that helped make it easy to understand.
A PO file’s schematic is usually comprised of a repetition or recombination of seven (7) standard lines or code snippets (excluding white-space) as shown below, and in most cases it tends to use at least three of those lines – these are the reference, msgid, and msgstr code snippets.
white-space # translator-comments #. extracted-comments #: reference… #, flag… #| msgid previous-untranslated-string msgid untranslated-string msgstr translated-string
Here’s how the codes are shown on the PO file. As could be seen, the reference line (lines that start with the #: symbols) code snippet informs the translation program to inspect the files (i.e. content-grid.php) and check the word/string entry on line number 29. Same goes to the entry on content.php line 25, and content-single at line 26 – all found on the first two lines of codes at the screenshot below.
These references are then checked and compared to the contents of the msgid line (i.e. “% Comments” on the example screenshot above). The msgstr line marks where the translation program (i.e. POEDIT or Loco Translate) should place the form field where the translation could be typed into.
The flag line (line that started with the #, symbols and followed by the “php-format” string) informs that the contents of next msgid will contain PHP (programming language) formatted string.
What are PO, MO and POT Files?
The .po file is the one that gets modified to create translations on a per language basis. Meaning, if I were to create a French (fr) translation and a German (de) translation of English words, then I need to create two different .po files > fr_FR.po and de_DE.po files.
The POT or Portable Object Template file, on the other hand, contains the base list of strings or words used as basis for when a translation needs to be created. It is based on word instances on the website that needs to be translated (i.e. Overview, About, Continue Reading, Written by, Learn More).
So basically, the only difference between the PO and the POT file is that .po contains translations inside the msgstr line or code snippet.
The .mo file is auto-generated by the translation program so convert the texts into machine-readable codes. So everytime a translation is saved into the .po file, the .mo file automatically gets updated soon after.
The photo above shows the files I used when I added new strings for translations (i.e. the “Written by” string into “Von”) into the existing portable object template of the Jobify Theme (jobify.pot).
NEXT: How to get a theme’s or plugin’s PO Template (.pot) file?
Please check back next week for the next guide on how to get a copy of the portable object template.
About this Post
The topic posted above is the result of some work done in the past related to creating translations for a website project using Loco Translate, and a File Manager system.