i18n Support – WordPress Plugin Boilerplate
12 Stars
View on GitHub
The plugin is prepared to support internationalization (i18n) and translations for your WordPress plugin.
Translate your plugin
Section titled “Translate your plugin”- 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.
Using AI
Section titled “Using AI”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.
Actually translating strings
Section titled “Actually translating strings”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”.
Things to keep in mind
Section titled “Things to keep in mind”- 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.