Chapter 9. PO Translations

9.1. Introduction

The GNU gettext system offers translators an easy way to create and maintain translations of documents. Translatable strings are extracted from the original document into a PO (Portable Object) file. Translated versions of the strings are entered with a separate editor. The strings can be used directly or built into a complete translated version of the original document.

9.2. Quick Start

The procedure shown in Quick Start is assumed to have already been performed. The TRANSLATOR option is required and already enabled by default in the textproc/docproj port.

This example shows the creation of a Spanish translation of the short Leap Seconds article.

Procedure: Install a PO Editor
  1. A PO editor is needed to edit translation files. This example uses editors/poedit.

    # pkg install poedit
Procedure: Initial Setup

When a new translation is first created, the directory structure must be created or copied from the English original:

  1. Create a directory for the new translation. The English article source is in ~/doc/documentation/content/en/articles/leap-seconds/. The Spanish translation will go in ~/doc/documentation/content/es/articles/leap-seconds/. The path is the same except for the name of the language directory. The English article source is in ~/doc/en/articles/leap-seconds/. The Spanish translation will go in ~/doc/es/articles/leap-seconds/. The path is the same except for the name of the language directory.

    % mkdir ~/doc/documentation/content/es/articles/leap-seconds
  2. Copy the _index.adoc from the original document into the translation directory:

    % cp ~/doc/documentation/content/en/articles/leap-seconds/_index.adoc \
Procedure: Translation

Translating a document consists of two steps: extracting translatable strings from the original document, and entering translations for those strings. These steps are repeated until the translator feels that enough of the document has been translated to produce a usable translated document.

  1. Extract the translatable strings from the original English version into a PO file:

    % cd ~/doc
    % po4a-gettextize \
      --format asciidoc \
      --option compat=asciidoctor \
      --option yfm_keys=title,part,description \
      --master "documentation/content/en/articles/leap-seconds/_index.adoc" \
      --master-charset "UTF-8" \
      --copyright-holder "The FreeBSD Project" \
      --package-name "FreeBSD Documentation" \
      --po "documentation/content/es/articles/leap-seconds/_index.po"
  2. Use a PO editor to enter translations in the PO file. There are several different editors available. poedit from editors/poedit is shown here.

    % poedit documentation/content/es/articles/leap-seconds/_index.po
Procedure: Generating a Translated Document
  1. Generate the translated document:

    % cd ~/doc
    % po4a-translate \
      --format asciidoc \
      --option compat=asciidoctor \
      --option yfm_keys=title,part,description \
      --master "documentation/content/en/articles/leap-seconds/_index.adoc" \
      --master-charset "UTF-8" \
      --po "documentation/content/es/articles/leap-seconds/_index.po" \
      --localized "documentation/content/es/articles/leap-seconds/_index.adoc" \
      --localized-charset "UTF-8" \
      --keep 0

    The name of the generated document matches the name of the English original, usually _index.adoc.

  2. Check the generated file by rendering it to HTML and viewing it with a web browser:

    % cd ~/doc/documentation
    % make

9.3. Creating New Translations

The first step to creating a new translated document is locating or creating a directory to hold it. FreeBSD puts translated documents in a subdirectory named for their language and region in the format lang. lang is a two-character lowercase code.

Table 1. Language Names
LanguageRegionTranslated Directory Name


United States
























































The translations are in subdirectories of the main documentation directory, here assumed to be ~/doc/documentation/ as shown in [overview-quick-start]. For example, German translations are located in ~/doc/documentation/content/de/, and French translations are in ~/doc/documentation/content/fr/.

Each language directory contains separate subdirectories named for the type of documents, usually articles/ and books/.

Combining these directory names gives the complete path to an article or book. For example, the French translation of the NanoBSD article is in ~/doc/documentation/content/fr/articles/nanobsd/, and the Mongolian translation of the Handbook is in ~/doc/documentation/content/mn/books/handbook/.

A new language directory must be created when translating a document to a new language. If the language directory already exists, only a subdirectory in the articles/ or books/ directory is needed.

Example 1. Creating a Spanish Translation of the Porter’s Handbook

Create a new Spanish translation of the Porter’s Handbook. The original is a book in ~/doc/documentation/content/en/books/porters-handbook/.

  1. The Spanish language books directory ~/doc/documentation/content/es/books/ already exists, so only a new subdirectory for the Porter’s Handbook is needed:

    % cd ~/doc/documentation/content/es/books
    % mkdir porters-handbook
  2. Copy the content from the original book:

    % cd porters-handbook
    % cp -R ~/doc/documentation/content/en/books/porters-handbook/* .

    Now the document structure is ready for the translator to begin translating with po4a command.

9.4. Translating

The gettext system greatly reduces the number of things that must be tracked by a translator. Strings to be translated are extracted from the original document into a PO file. Then a PO editor is used to enter the translated versions of each string.

The FreeBSD PO translation system does not overwrite PO files, so the extraction step can be run at any time to update the PO file.

A PO editor is used to edit the file. editors/poedit is shown in these examples because it is simple and has minimal requirements. Other PO editors offer features to make the job of translating easier. The Ports Collection offers several of these editors, including devel/gtranslator.

It is important to preserve the PO file. It contains all of the work that translators have done.

Example 2. Translating the Porter’s Handbook to Spanish
  1. Change to the base directory and update all PO files.

    % cd ~/doc
    % po4a-gettextize \
      --format asciidoc \
      --option compat=asciidoctor \
      --option yfm_keys=title,part,description \
      --master "documentation/content/en/books/porters-handbook/_index.adoc" \
      --master-charset "UTF-8" \
      --copyright-holder "The FreeBSD Project" \
      --package-name "FreeBSD Documentation" \
      --po "documentation/content/es/books/porters-handbook/_index.po"
  2. Enter translations using a PO editor:

    % poedit documentation/content/es/books/porters-handbook/_index.po

These steps are necessary for all .adoc files, excluding chapters-order.adoc and toc-*.adoc.

9.5. Tips for Translators

9.5.1. Preserving AsciiDoc macros

Preserve AsciiDoc macros that are shown in the English original.

Example 3. Preserving AsciiDoc macros

English original:

msgid ""
"This example shows the creation of a Spanish translation of the short "
"extref:{leap-seconds}[Leap Seconds] article."

Spanish translation:

msgid ""
"Este ejemplo muestra la creación de un artículo con poco contenido como el artículo "
"extref:{leap-seconds}[Leap Seconds]."

9.5.2. Preserving Spaces

Preserve existing spaces at the beginning and end of strings to be translated. The translated version must have these spaces also.

9.5.3. Verbatim Tags

The contents of some tags should be copied verbatim, not translated:

9.6. Building a Translated Document

A translated version of the original document can be created at any time. Any untranslated portions of the original will be included in English in the resulting document. Most PO editors have an indicator that shows how much of the translation has been completed. This makes it easy for the translator to see when enough strings have been translated to make building the final document worthwhile.

9.7. Submitting the New Translation

Prepare the new translation files for submission. This includes adding the files to the version control system, setting additional properties on them, then creating a diff for submission.

The diff files created by these examples can be attached to a documentation bug report or code review.

Example 4. Spanish Translation of the NanoBSD Article
  1. Create a diff of the new files from the ~/doc/ base directory so the full path is shown with the filenames. This helps committers identify the target language directory.

    % cd ~/doc
    % git diff documentation/content/es/articles/nanobsd/ > /tmp/es_nanobsd.diff

All FreeBSD documents are available for download at

Questions that are not answered by the documentation may be sent to <>.
Send questions about this document to <>.