Modern Translation File Generator for WordPress
Previously WordPress developers needed to use makepot.php
to generate the .po files
necessary for translation., (*1)
This WP CLI command allows you to generate different types of translation file from WP
code and also convert between types easily., (*2)
Supported translation file types are:, (*3)
- CSV
- CSV Dictionary (no plural support)
- JSON
- JSON Dictionary (no plural support)
- mo
- PHP Array
- po
- jed
- xliff
- YAML
- YAML Dictionary (no plural support)
Installation
You can install the command as WP CLI package (Recommended):, (*4)
wp package install roborourke/wp-l10n-gen
Using composer:, (*5)
composer require roborourke/wp-l10n-gen
As a plugin:, (*6)
git clone git@github.com:roborourke/wp-l10n-gen.git
cd wp-l10-gen
composer install
wp plugin activate wp-l10n-gen # (or activate via wp-admin)
Usage
More docs to come soon, to see options for now run:, (*7)
wp l10n generate --help
wp l10n convert --help
wp l10n po2mo --help
Roadmap
- Improve generated headers
- Documentation for use with JS based projects?
About
Being frustrated with the existing tools for generating translation files I wondered if
there was a better way that more closely tied in with the modern ways we interact with
WP via the command line now., (*8)
Looking to other PHP Projects and how they manage translations was a useful exercise although
WP's translation function don't follow the usual standards. A bit of hacking later and I was
able to get Oscar Otero's excellent Gettext library
working with WordPress code., (*9)
Contributing
It's very early days yet but if anyone finds this useful and wants to contribute please go
ahead. You'll find my outline for a roadmap above and plenty of TODO
comments in the code., (*10)
License
GPLv3+, (*11)