Notes about WordPress Gutenberg themes development.

  • Context in translation

    Read more

    Prototype:

    _x( string $text, string $context, string $domain = 'default' ): string

    Quite a few times, there will be collisions with similar translatable text found in more than two places, but with different translated context.

    By including the context in the pot file, translators can translate the two strings differently.

    Example:

    _x( 'T', 'Tuesday', 'text-domain');
    _x( 'T', 'Thursday', 'text-domain');

    source : https://developer.wordpress.org/reference/functions/_x/

  • wp i18n

    Read more

    Used to generate translations from __('string to translate', 'text-domain') functions.

    MO files: MO, or Machine Object is a binary data file that contains object data referenced by a program. It is typically used to translate program code, and may be loaded or imported into the GNU gettext program.

    PO files: PO files are the files which contain the actual translations. Each language will have its own PO file, for example, for French there would be a fr.po file, for german there would be a de.po, for American English there might be en-US.po.

    POT file: POT files are the template files for PO files. They will have all the translation strings left empty. A POT file is essentially an empty PO file without the translations, with just the original strings.

    wp i18n make-pot . languages/<file-name>.pot --domain=<domain-name>
    
    wp i18n update-po languages/<file-name>.pot languages/fr_FR.po
    
    wp i18n make-mo languages/<file-name>.po languages/

    Sources: