Localization (l10n) and PO files
Once you have internationalized your code by marking translatable strings (see Internationalization (i18n) API), you are ready to start creating translations: this is localization (l10n) of your program, which is achieved by authoring a .po
file with a list of translated strings.
In fact, the .po
files need not be created by the programmer — they can instead be contributed by users, which allows native speakers of other languages to help you out. There are numerous software tools to help people create and edit .po
files, some of which we mention below.
Localization involves three components: setting up the po
directory to hold translations, extracting the strings to be translated, and creating/editing .po
files for various locales. We summarize each of these components below.
The po
directory
Every Julia package or program should set up a po
directory to contain its translation files. (For Julia packages, this is typically located in the top level of the package directory, as described in Gettext for modules and packages.) The po
directory's location is configured by a call to bindtextdomain
in the code (see Domains).
The po
directory will initially be empty, but each new localization should add two files:
po/<locale>/LC_MESSAGES/<domain>.po
po/<locale>/LC_MESSAGES/<domain>.mo
Here,
<locale>
is the name of the locale (language and culture) of the localization, typically of the formll
orll_CC
, wherell
is the two-letter language code (e.g.en
for English orfr
for French), andCC
is the two-letter code of a country or territory (e.g.en_GB
would indicate localization for British English). See also Locale Names in the GNU gettext manual.<domain>
is the name of the Gettext domain used by the program or package (see Domains), typically the name of the program or package followed by a unique identifier like a UUID; for a package/module, this is the value of__GETTEXT_DOMAIN__
.The
<domain>.po
file is a human-readable/editable text file containing the translated messages. The<domain>.mo
file is a condensed binary representation of the<domain>.po
data, which can be generated from<domain>.po
by the GNUmsgfmt
program.
Extracting the strings to be translated
The strings to be translated consist of every call to the localization macros _"..."
, @ngettext
, and so on in the program or package (see Internationalization (i18n) API).
Currently, this list of strings must be extracted manually, but in the near future we hope to automate this process. See: Gettext.jl#22.
Creating/editing .po
files
Once a list of strings has been extracted, typically in the form of a "template" .pot
file that contains the empty translations (""
), there are various ways that you can edit/create .po
files:
- Hand editing: the format is human-readable; see also this tutorial and this
sample.po
file included with Gettext.jl. - Various software packages provide
.po
editor tools, including: Virtaal, Poedit, Gtranslator, Lokalize - Zanata and Weblate are web-based platforms for collaborating with translators, both of which support
.po
files. - Various packages to auto-generate translations: e.g. using Google translate, using LLMs
- Translation Toolkit provides a number of other automation utilities for
.po
files.
(We hope that this is a useful list of resources, but currently make no specific recommendations.)