eugene-erg / symfony-icu-i18n-translator
Symfony bundle for eugene-erg/icu-i18n-translator: the translator as a service, storage on Doctrine DBAL, providers and formats by tags, bin/console icu-i18n:sync for translations/
Package info
github.com/EugeneErg/symfony-icu-i18n-translator
Type:symfony-bundle
pkg:composer/eugene-erg/symfony-icu-i18n-translator
Requires
- php: ^8.2
- doctrine/doctrine-bundle: ^2.13 || ^3.0
- eugene-erg/dbal-icu-i18n-translator: ^1.0
- eugene-erg/icu-i18n-translator: ^4.4
- eugene-erg/sync-icu-i18n-translator: ^1.0
- eugene-erg/xliff-formatter-icu-i18n-translator: ^2.0
- eugene-erg/yaml-formatter-icu-i18n-translator: ^1.1
- symfony/config: ^6.4 || ^7.0 || ^8.0
- symfony/console: ^6.4 || ^7.0 || ^8.0
- symfony/dependency-injection: ^6.4 || ^7.0 || ^8.0
- symfony/http-kernel: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
- laravel/pint: ^1.32
- 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
- symfony/framework-bundle: ^6.4 || ^7.0 || ^8.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-03 06:20:45 UTC
README
A Symfony bundle for eugene-erg/icu-i18n-translator: the
translator as a service, its memory in your database through Doctrine DBAL, providers and formats by tags, and
bin/console icu-i18n:sync, which translates translations/ into every language you configure.
composer require eugene-erg/symfony-icu-i18n-translator
bin/console icu-i18n:install # the tables, on the Doctrine connection
Requires PHP 8.2+, Symfony 6.4, 7 or 8 and DoctrineBundle. Register the bundle in config/bundles.php if Flex
does not:
EugeneErg\SymfonyIcuI18nTranslator\IcuI18nTranslatorBundle::class => ['all' => true],
Providers
Every service that implements TranslatorInterface (texts) or MessageTranslatorInterface (whole messages:
language models) is a provider; they are tried by tag priority. For example, Claude and the free Google endpoint:
# config/services.yaml services: EugeneErg\LlmIcuI18nTranslator\LlmTranslator: arguments: ['@EugeneErg\ClaudeIcuI18nTranslator\AnthropicApi'] # defined as you need it tags: [{ name: icu_i18n.provider, priority: 10 }] # first
Formats
yaml and xlf are registered, for Symfony's ICU files (messages+intl-icu.en.yaml, ….xlf). Add others with
the icu_i18n.formatter tag and a format name:
services: EugeneErg\PoFormatterIcuI18nTranslator\PoFormatter: tags: [{ name: icu_i18n.formatter, format: po }]
or, for a formatter of your own, with the #[AsIcuFormatter('name')] attribute on its class.
Configuration
# config/packages/icu_i18n.yaml icu_i18n: connection: ~ # a Doctrine DBAL connection name; the default one when empty table_prefix: icu_i18n_ source: '%kernel.default_locale%' locales: [en, de, fr, ru] # the languages icu-i18n:sync writes sync: root: '%kernel.project_dir%' patterns: # where the files are; these two are the default - { template: 'translations/{domain}+intl-icu.{locale}.yaml', format: yaml } - { template: 'translations/{domain}+intl-icu.{locale}.xlf', format: xlf }
A pattern is a path with {locale}, {path} (folders included) and other placeholders such as {domain}; see
sync-icu-i18n-translator.
Translating translations/
bin/console icu-i18n:sync # every language of icu_i18n.locales bin/console icu-i18n:sync --locale=de --dry-run # which files would be written bin/console icu-i18n:sync --show-machine # which keys a provider translated
A missing file is created. An existing one is read first: what a person changed there becomes theirs and is
never sent to a provider again, and only missing texts are translated. XLIFF files are written over themselves
(notes, states and layout stay) and mark machine translations needs-review-translation; clear the mark in your
XLIFF editor to approve a text. YAML has no such mark: review its machine translations before you commit.
In code
use EugeneErg\IcuI18nTranslator\Translator; public function __construct(private Translator $translator) {} $this->translator->translateMessage('{count, plural, one {# file} other {# files}}', ['count' => 3], 'ru', 'en');
CatalogSync (the work behind icu-i18n:sync) and DbalStorage are services too.
Tables
bin/console icu-i18n:install creates the tables or brings them up to date, touching no other table;
--dump-sql prints the statements instead, for a Doctrine migration of yours.
Development
composer check # pint --test, phpstan (level max, strict rules) and phpunit
composer coverage
License
MIT