A CLI command is provided to extract translations from twig files. It extends the core i18n make-pot
command to include twig files.
bin/docker/wp i18n-twig make-pot
Note: This will include PHP files and JS files, so you shouldn't need to run the core version as well. Doing so, will overwrite the translations that include the twig files.
The easiest way to set up translations is to use the following scripts:
bin/makepot.sh
- To make our project wide .pot
file.
bin/pot2po.sh
- To copy across our .pot
file to .po
files for each language. Only creates if non existing.
bin/po2mo.sh
- Compiles the .po
files into .mo
files.
We use wp-translations-downloader to manage 3rd party translations including core. To download translations for core WordPress and plugins, run:
bin/docker/composer wp-translation-downloader:download
So you've added some new text and put it through __()
. In order for it to work as a translation you will need to take the following steps:
-
Run
bin/makepot.sh
- this will generate a freshpot
file which will contain your text -
Run
git diff wp-content/languages/$PROJECT_NAME.pot
on the newpot
file -
Note what has changed
-
Open up
$PROJECT_NAME.pot
and look for the changes you spotted in the diff -
Copy across manually to
wp-content/languages/$PROJECT_NAME-en_GB.po
andwp-content/languages/$PROJECT_NAME-cy.po
Try to keep them in the same location as they are in the
pot
file
-
Update the translations spreadsheet manually with the stings you just copied across to the
po
files -
Once you have recieved the translations, update the
po
files accordingly -
Run
bin/po2mo.sh
to compile the strings and make them available to the site