eugene-erg / wordpress-icu-i18n-translator
WordPress plugin for eugene-erg/icu-i18n-translator: wp icu-i18n sync translates a plugin's or theme's .pot into .po, .mo and .l10n.php, keeping what people wrote in the site's database
Package info
github.com/EugeneErg/wordpress-icu-i18n-translator
Type:wordpress-plugin
pkg:composer/eugene-erg/wordpress-icu-i18n-translator
Requires
- php: ^8.2
- ext-intl: *
- ext-mysqli: *
- composer/installers: ^2.3
- doctrine/dbal: ^4.5
- eugene-erg/dbal-icu-i18n-translator: ^1.1
- eugene-erg/http-provider-icu-i18n-translator: ^1.0
- eugene-erg/icu-i18n-translator: ^4.4
- eugene-erg/l10n-php-formatter-icu-i18n-translator: ^1.0
- eugene-erg/mo-formatter-icu-i18n-translator: ^1.0
- eugene-erg/po-formatter-icu-i18n-translator: ^1.3
- eugene-erg/sync-icu-i18n-translator: ^1.3
- nyholm/psr7: ^1.8
- psr/http-client: ^1.0
- psr/http-factory: ^1.1
- psr/http-message: ^2.0
- psr/simple-cache: ^3.0
Requires (Dev)
- eugene-erg/amazon-icu-i18n-translator: ^2.0
- eugene-erg/azure-icu-i18n-translator: ^2.0
- eugene-erg/claude-icu-i18n-translator: ^1.0
- eugene-erg/deepl-icu-i18n-translator: ^2.0
- eugene-erg/google-cloud-icu-i18n-translator: ^2.0
- eugene-erg/libretranslate-icu-i18n-translator: ^2.0
- eugene-erg/llm-icu-i18n-translator: ^1.2
- laravel/pint: ^1.32
- php-stubs/wp-cli-stubs: ^2.11
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.2
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.1
- phpstan/phpstan-strict-rules: ^2.1
- phpunit/phpunit: ^12.5
- roots/wordpress-no-content: ^7.0
- szepeviktor/phpstan-wordpress: ^2.0
- wp-cli/wp-cli: ^2.12
- wp-phpunit/wp-phpunit: ^7.0
- yoast/phpunit-polyfills: ^4.0
Suggests
- eugene-erg/amazon-icu-i18n-translator: machine translation by Amazon Translate, set up in the settings or wp-config.php
- eugene-erg/azure-icu-i18n-translator: machine translation by Azure Translator, set up in the settings or wp-config.php
- eugene-erg/claude-icu-i18n-translator: machine translation by Claude, set up in the settings or wp-config.php
- eugene-erg/deepl-icu-i18n-translator: machine translation by DeepL, set up in the settings or wp-config.php
- eugene-erg/google-cloud-icu-i18n-translator: machine translation by Google Cloud Translation, set up in the settings or wp-config.php
- eugene-erg/libretranslate-icu-i18n-translator: machine translation by LibreTranslate, set up in the settings or wp-config.php
- eugene-erg/llm-icu-i18n-translator: machine translation by an OpenAI-compatible model, set up in the settings or wp-config.php
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-03 16:17:31 UTC
README
A WordPress plugin for eugene-erg/icu-i18n-translator: wp icu-i18n sync translates the .pot of a plugin or theme into .po, .mo and .l10n.php files with machine translation,
and keeps what people wrote. The translations it has seen live in the site's database, so a text translated once is
not sent to a provider again.
wp i18n make-pot wp-content/plugins/shop wp-content/plugins/shop/languages/shop.pot wp icu-i18n sync wp-content/plugins/shop --locale=de_DE,fr_FR
created languages/shop-de_DE.po (12 machine)
created languages/shop-de_DE.mo
created languages/shop-de_DE.l10n.php
…
Success: 6 file(s) written; 24 text(s) translated by a provider: review them (--show-machine).
Installing
Without Composer: download wordpress-icu-i18n-translator.zip from the
latest release and upload it in
Plugins → Add New → Upload Plugin, or wp plugin install wordpress-icu-i18n-translator.zip --activate. It carries
its libraries and the seven providers below. The libraries of others (Doctrine, PSR, Nyholm) are renamed inside it, so
another plugin's copies, of another version, never meet these; the translator's own classes keep their names.
The zip updates itself as WordPress.org plugins do: a new release appears under Dashboard → Updates, and automatic updates work. It comes from the releases of this repository, and is installed only when its SHA-256 is the digest GitHub published for it.
With Composer — composer/installers puts it into wp-content/plugins:
composer require eugene-erg/wordpress-icu-i18n-translator wp plugin activate wordpress-icu-i18n-translator
Activation makes the plugin's tables. Loaded without activation (as a must-use plugin), or after an update, make or
update them with wp icu-i18n install.
Needs PHP 8.2+ with intl and mysqli, WordPress 6.5+ and its usual database, MySQL or MariaDB: the plugin connects
to it as WordPress does, from DB_HOST, DB_USER, DB_PASSWORD, DB_NAME and MYSQL_CLIENT_FLAGS of
wp-config.php. A database drop-in for another database (SQLite) is not supported.
On a page load the plugin does nothing: WordPress loads the .mo and .l10n.php files the command writes.
wp icu-i18n sync <path>
| Option | |
|---|---|
--locale=de_DE,fr_FR |
the languages to write; by default the languages installed on the site |
--source=en_US |
the language of the .pot (default en_US) |
--dry-run |
list the files that would be written; translate nothing |
--show-machine |
list the texts a provider translated |
By default <path>/languages/{domain}.pot gives languages/{domain}-{locale}.po, and from each .po its .mo and
.l10n.php are written anew.
- A text a person translated in a
.pofile stays as it is. - A new text is translated by the providers and marked
fuzzy: open the.poin Poedit or Loco, check it, and remove the mark. Until then the.moand.l10n.phpcarry the machine translation, so the site shows it at once. - Run the command again after
make-pot: new texts are translated, the rest is kept.
Providers
Settings → ICU i18n Translator (Network Admin → Settings when the plugin is active for a network: one set for
every site). For each provider: its keys, whether it is used and in what order, and Save and try — it translates
"Hello" into German with what was saved and says what came back. Keys are kept encrypted with the salts of
wp-config.php, so a dump of the database does not give them away, and are never shown again; new salts make them
unreadable, and the page asks for them again.
| Provider | Settings |
|---|---|
| Claude | ICU_I18N_CLAUDE_KEY, ICU_I18N_CLAUDE_MODEL (claude-sonnet-5-5 by default) |
| An OpenAI-compatible model — OpenAI, OpenRouter, Mistral, Ollama, LM Studio… | ICU_I18N_LLM_URL, ICU_I18N_LLM_MODEL, ICU_I18N_LLM_KEY (not for a local server) |
| DeepL | ICU_I18N_DEEPL_KEY (a key ending in :fx goes to the free API) |
| Google Cloud Translation | ICU_I18N_GOOGLE_KEY |
| Azure Translator | ICU_I18N_AZURE_KEY, ICU_I18N_AZURE_REGION |
| Amazon Translate | ICU_I18N_AMAZON_ACCESS_KEY, ICU_I18N_AMAZON_SECRET_KEY, ICU_I18N_AMAZON_REGION |
| LibreTranslate | ICU_I18N_LIBRETRANSLATE_URL, ICU_I18N_LIBRETRANSLATE_KEY |
The same names are constants of wp-config.php, which win over the page and lock its fields — keys out of the
database, different per environment:
define('ICU_I18N_DEEPL_KEY', '…'); define('ICU_I18N_PROVIDERS', 'llm,deepl'); // which ones, in this order
Chosen neither way, every provider set up is used: the language models first — they translate whole messages —
then the services, in the order of the table. Requests go through the HTTP API of WordPress (the site's proxy and
certificates); the providers' language lists are kept a day in transients. Installed with Composer, a provider also
needs its package (eugene-erg/deepl-icu-i18n-translator…); the page and the command say which is missing.
Without a provider, sync works only while every text has a translation already (in the .po files or the
database), and stops at the first new one.
In code
The icu_i18n_translator_providers filter gets the providers of the settings and can reorder them or add any other
— a model through a command-line tool, Google's Advanced edition with a service account, a provider of yours. Its second argument gives a PSR-18 client over the HTTP API of WordPress, the
PSR-17 factories and a PSR-16 cache in transients:
use EugeneErg\DeepLIcuI18nTranslator\Client\DeepLClient; use EugeneErg\DeepLIcuI18nTranslator\DeepLTranslator; use EugeneErg\DeepLIcuI18nTranslator\Formality; use EugeneErg\HttpProviderIcuI18nTranslator\Http\HttpJsonClient; use EugeneErg\WordPressIcuI18nTranslator\Services; // DeepL with options the constants do not have add_filter('icu_i18n_translator_providers', static function (array $providers, Services $services): array { $http = new HttpJsonClient($services->http(), $services->factory(), $services->factory()); return [new DeepLTranslator(new DeepLClient($http, DEEPL_KEY), Formality::PreferLess, cache: $services->cache())]; }, 10, 2);
In the zip the PSR interfaces are renamed with the rest, so a provider that is not in it comes with Composer.
Other files
| Filter | Default | |
|---|---|---|
icu_i18n_translator_formatters |
po, mo, l10n.php |
the formats by name, FormatterInterface |
icu_i18n_translator_patterns |
languages/{domain}-{locale}.po from languages/{domain}.pot, with its .mo and .l10n.php |
FilePatterns of sync-icu-i18n-translator; gets the path of the plugin or theme |
use EugeneErg\SyncIcuI18nTranslator\DerivedFile; use EugeneErg\SyncIcuI18nTranslator\FilePattern; // a theme that keeps its translations in lang/, without .l10n.php files add_filter('icu_i18n_translator_patterns', static fn (): array => [ new FilePattern('lang/{locale}.po', 'po', 'theme', 'lang/theme.pot', [new DerivedFile('lang/{locale}.mo', 'mo')]), ]);
A filter that gives something else stops the command with what is wrong.
The database
Four tables next to the site's, under its prefix: wp_icu_i18n_groups, _translates, _group_translates, _paths
(wp_2_icu_i18n_… on the second site of a network), in the charset and collation of WordPress. Activated for a
network, the plugin makes them on every site, and on each site made later. Deleting the plugin drops them, and its
settings, on every site; the .po files keep their translations.
Testing
The tests run in WordPress itself, with its test suite, on a real MySQL or MariaDB — the suite empties that database, so give it one of its own:
composer install mysql -e "CREATE DATABASE wordpress_tests; CREATE USER wp@localhost IDENTIFIED BY 'wp'; GRANT ALL ON wordpress_tests.* TO wp@localhost" composer check # pint --test, phpstan (level max), phpunit on a single site WP_MULTISITE=1 vendor/bin/phpunit # on a network
The zip — built for PHP 8.2, and tried on a WordPress of its own beside a plugin that brings its own Doctrine and Nyholm, installed, activated, used and deleted:
composer install --working-dir=tools/scoper bin/build-zip.sh 1.1.0 # dist/wordpress-icu-i18n-translator.zip bin/smoke-zip.sh 1.1.0 # on the database of the tests, under the prefix zip_
WP_TESTS_DB_HOST, WP_TESTS_DB_NAME, WP_TESTS_DB_USER, WP_TESTS_DB_PASSWORD and WP_CORE_DIR change the
defaults (127.0.0.1, wordpress_tests, wp, wp, vendor/roots/wordpress-no-content). php bin/coverage.php joins the
coverage of both runs (--coverage-php).
License
MIT