eugene-erg / dbal-icu-i18n-translator
Doctrine DBAL storage for eugene-erg/icu-i18n-translator: the translation memory in MySQL, MariaDB, PostgreSQL or SQLite, with or without a framework
Package info
github.com/EugeneErg/dbal-icu-i18n-translator
pkg:composer/eugene-erg/dbal-icu-i18n-translator
Requires
- php: ^8.2
- doctrine/dbal: ^4.5
- eugene-erg/icu-i18n-translator: ^4.4
- eugene-erg/icu-message-format-parser: ^3.0
Requires (Dev)
- eugene-erg/json-formatter-icu-i18n-translator: ^1.2
- 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
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-03 16:41:33 UTC
README
Storage for eugene-erg/icu-i18n-translator on Doctrine DBAL: the translation memory in MySQL, MariaDB, PostgreSQL or SQLite, in any PHP project. The Symfony bundle uses it; Laravel has its own Eloquent storage.
composer require eugene-erg/dbal-icu-i18n-translator
use Doctrine\DBAL\DriverManager; use EugeneErg\DbalIcuI18nTranslator\DbalStorage; use EugeneErg\JsonFormatterIcuI18nTranslator\JsonFormatter; $connection = DriverManager::getConnection(['driver' => 'pdo_pgsql', 'host' => 'localhost', 'dbname' => 'app', /* … */]); $storage = new DbalStorage($connection); $storage->schema()->install($connection); // creates the tables, once $translator = $storage->translator( providers: [$claude, $google], // tried in order formatters: ['json' => new JsonFormatter()], ); $translator->translateMessage('{count, plural, one {# file} other {# files}}', ['count' => 5], 'ru', 'en'); // "5 файлов": translated once, then read from the database
Requires PHP 8.2+, doctrine/dbal 4.5+.
Tables
| Table | Holds |
|---|---|
icu_i18n_groups |
messages: one row per text, context and language |
icu_i18n_translates |
translations: one row per text and language, shared by every message that has it |
icu_i18n_group_translates |
which translation a message has for each variant and plural form, and whether a provider made it (source_id) |
icu_i18n_paths |
the key trees of files: a root per file, keys under it, messages at the leaves |
Long texts — messages, translations and keys of files, which can be whole sentences — are found by their md5
hashes, so no index limit is hit. new Tables('app_i18n_') puts the tables under another prefix; pass it to
DbalStorage.
Creating the tables
- By itself:
$storage->schema()->install($connection)creates the missing tables and brings existing ones up to date; other tables are not looked at.sql($connection)returns the statements without running them. - With your migrations:
$storage->schema()->tables()are DBALTableobjects andaddTo($schema)returns your schema with them, for Doctrine Migrations ordoctrine:schema:update.
On MySQL and MariaDB the tables are utf8mb4 whatever the database's default: a latin1 database would refuse or
mangle every text outside it. $storage->schema(['charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci'])
gives other DBAL table options; other platforms ignore them.
Deleting
Deletes clean up after themselves in code, not only through foreign keys (which SQLite enforces only when told to): a deleted translation leaves no links, and messages translated from it keep no source; a deleted message leaves its file keys without a message; a deleted file key takes its subtree. The translator itself never deletes messages: they are memory shared by every file.
Development
composer check # pint, phpstan, phpunit on SQLite DBAL_TEST_URL=pdo-pgsql://user:password@localhost/db vendor/bin/phpunit # the same tests on a server
CI runs them on SQLite, PostgreSQL 16, MySQL 8.4 and MariaDB 11.
License
MIT