Introduction to the Basics

Introduction to poedit

poedit is a popular cross-platform translation editor for editing .po files. It provides an intuitive interface and a rich set of features that make it easy for translators to edit and manage software localized translations.

gettext Introduction

  • Gettext Toolset: Gettext provides a set of command-line tools for managing and processing translation-related tasks. This includes the following tools:
    xgettext: used to extract text strings from source code and generate .pot files (template files).
    msginit: used to create new .po files and provide a basic translation environment.
    msgmerge: used to merge updated .pot files into existing .po files, preserving existing translations.
    msgfmt: used to compile .po files into binary .mo files for programs to load at runtime.

.pot file

.pot File (Portable Object Template): A .pot file is a template file used to create a .po file. It contains text in the source language, but no translation into the target language. Developers typically use a .pot file as a base to extract all the text strings in an application and convert them into a .pot file. Translators can then use the .pot file to create the corresponding .po file and work on the translation.

po files

A .po file is a text file that contains the source language (usually English) and the corresponding target language translation. Each translation entry includes a unique identifier, source text and target text. .po files are editable and can be modified using a text editor or specialized translation tool.

.mo files

A .mo file is a binary file that is a compiled version of a .po file. It contains a binary representation of the translated entries in the .po file. Software typically uses .mo files to load the correct translated text at runtime. The .mo file is machine-readable and therefore improves the efficiency and performance of the translation at runtime.

Environment Preparation

Software Installation

sudo apt install gettext

sudo apt install poedit

sample program

compiling

gcc myapp.c -o myapp

Generate pot file

xgettext -a myapp.c -o myapp.pot

Note the deletion of redundant translation lines

Generate po file

msginit -l zh_CN -i myapp.pot -o zh_CN.po

To translate po files, use poedit.

Generate mo file

msgfmt zh_CN.po -o zh_CN.mo

mounting

mkdir -p locale/zh_CN/LC_MESSAGES

cp zh_CN.mo locale/zh_CN/LC_MESSAGES/myapp.mo

(of a computer) run

./myapp

Troubleshooting Translation Issues

  1. Check if the path of the translated file is correct
    To check if the translation content is correct, convert mo to a po file and use poedit to open the pot file.

msgunfmt example.mo -o example.po

  1. Check if the program language related environment variables are printed properly before the initialization function

Leave a Reply