| title | i18n Support |
|---|---|
| short_title | i18n |
| description | Translation workflow and extraction/compilation scripts. |
The plugin is prepared to support internationalization (i18n) and translations for your WordPress plugin.
:::note
The i18n Composer scripts assume that WP-CLI is available in the current environment. You can either use wp-env or install WP-CLI separately. See the official WP-CLI installation guide.
:::
- Run bundling using
npm run buildfor js script extraction. - Run
composer run i18n:extractto generate the.potfile in thelanguages/directory and update existing.pofiles. - Translate the strings in the
.pofiles existing or create a new file for each language you want to support. - (Optional) Run
composer run i18n:compileto compile the.pofiles into.mo,.jsonand.phpfiles. This step makes translations available to WordPress. Thedeployaction does this automatically using wp-env.
This process allows you translating blocks and generate the fast php format for maximum performance.
The plugin does provide a command to instruct your coding agent to do the work for you.
/upsert-translations [lang1 lang2 ...]
Use the wp-plugin-bp skill for translation work, or run the commands manually when working without an agent.
The .po files have to be created and the strings have to actually be translated. You can use tools like Poedit or Loco Translate to manage translations.
Another thing that works well is using is to ask your coding agent to "upsert the translations".
- The textdomain has to be exactly the one defined in
demo-plugin.php. Otherwise, extraction will not find the strings. - The provided scripts only work if
wp-cliis available and a fully working WordPress installation is present. - i18n Strings in Enums are not supported due to upstream library limitation in
gettext - To extract twig strings you need to install https://github.com/timber/wp-i18n-twig
- The
make-potcommand requires to read bundled js files. Thats why we exclude theresources/folder incomposer i18n:extract. Processing the source folder would result a in json translation file per js source file and therefore be incompatible with thewp_set_script_translationsduring enqueueing of bundles.