Translation

Text domain, translation files and the pitfall that makes an edited translation not show up.

Table of Contents

Text domain and files

The text domain is kb. Both themes keep their translation files in languages/:

FilePurpose
kb.potTemplate with every translatable string of the theme
de_DE.poGerman translation, the editable source
de_DE.moGerman translation, compiled
de_DE.l10n.phpGerman translation in the PHP format WordPress loads first

Both themes carry the same four filenames. The Custom files contain every Core string plus the Custom ones, so in the Custom theme they replace Core’s.

Background on preparing themes for several languages: WordPress-Themes mehrsprachig vorbereiten (German).


Editing a translation

The translation files are maintained by hand. There is no build task that extracts strings, so new strings mean manual work in Poedit.

Editing de_DE.po alone changes nothing. WordPress 6.5 and later loads de_DE.l10n.php in preference to de_DE.mo, so both compiled files have to be regenerated, or the old translation stays live. Poedit writes all three files on save.

On the command line it is msgfmt for the .mo and WP_Translation_File::transform( $mo, 'php' ) for the .l10n.php, because WP-CLI has no i18n make-php in every version. That writer does not add a Plural-Forms header the way Poedit does, so it has to be present in the .po header.

Run msgfmt --check first. Three mistakes fail silently, and the string simply never reaches the site:

  • A typographic quotation mark used as a string delimiter invalidates the whole file.
  • Entries marked #, fuzzy are dropped from the catalog.
  • Entries marked #~ are obsolete and dropped too.