Language (WordPress)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen

This article is the starting point concerning language, translations and multilingualism for WordPress. See WordPress & Taal for the Dutch predecessor to this article.

Introduction

WordPress Core does not natively support multilingual functionality. It operates as a single-language platform out of the box, but you can make it multilingual through plugins and a multisite setups. The latter is not further discussed here.

While WordPress doesn't natively support multilingualism, the WordPress ecosystem has developed strong conventions and best practices for implementing multilingual sites. These conventions are followed by plugin developers, theme creators, and site administrators to ensure that multilingualism integrates smoothly with WordPress. E.g.:

  • i18n standard for internationalisation (the number 18 refers to the numbers of letters between the first i and last n in internationalisation)
  • l10n standard for localisation
  • GNU gettext standard for translations, maybe related or part of i18n or l10n or whatever. This system is not limited to WordPress only
  • Standardized content translation
  • URL structures
  • Language metadata
  • Language switches
  • Translations of themes and plugins
  • Database conventions.

Translations of themes and plugins

  • Within themes and plugin files, gettext functions like __(), _e() and _n() are used to handle translatable strings

.pot files

.pot or Portable Object Template' files' are templates for translations:

  • They contain source text strings
  • in English by convention
  • Extracted from the code
  • Without translations
  • With line references.

To create a .pot file from a project (plugin, theme, maybe some other things?):

  • Tools like Poedit: A standalone app that handles generic PO and PHP translation files
  • Command-line utilities like xgettext
  • WP-CLI command wp i18n make-pot

.po files

.po or Portable Object files are human-readible text files that contain translations for a specific language and is derived form a .pot file:

  • Contain the original strings (msgid) and their translations (msgstr)
  • Only onle language per .po file?
  • Comments or metadata can be included.

To work with .po files:

  • Standalone editors like Poedit
  • Plugins like Loco Translate
  • Just a text editor.

.mo files

.mo or Machine Object files are compiled .po files that WordPress uses during runtime:

  • GNU gettext
  • This is not a programming language format, but a data file format
  • Defined by the GNU gettext .mo file format. Maybe GNU MO file format is the right name [1].

To create .mo files:

  • Stand-alone tools like Poedit
  • command-line tools like msgfmt.

See also