davidhirtz / yii2-translation
Exports message translations to an Excel file and imports them back
Package info
github.com/davidhirtz/yii2-translation
Type:yii2-extension
pkg:composer/davidhirtz/yii2-translation
Requires
- php: ^8.3
- davidhirtz/yii2-skeleton: ^3.8
- phpoffice/phpspreadsheet: ^5.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Exports a project's message files to an Excel workbook for translators and imports the workbook back into the
message files. Only the php message format is supported. Depends on davidhirtz/yii2-skeleton and
phpoffice/phpspreadsheet.
Installation
composer require davidhirtz/yii2-translation --dev
The bundle bootstraps itself through extra.bootstrap (Hirtz\Translation\Bootstrap) and registers the
translation console command; the web application is left alone.
Export
./yii translation/export [outputDir]
Writes translations.xlsx to outputDir (default @runtime), one worksheet per category and one column per
language. The sheet is protected so that only the translations can be edited; the key column and the header are
locked.
How the columns are laid out depends on the category's message source:
- Without
forceTranslationthe messages are keyed by their source text, so the first column is the source language (en-US), holding the text itself, followed by every other language. - With
forceTranslation(every bundle category in v3) the keys are identifiers: the first column iskey, followed by every language, the source language included.
Every cell is written as text, so a translation that looks like a number or a formula survives the trip.
Import
./yii translation/import <file>
Reads a workbook in the export's layout and merges each worksheet into <messagePath>/<language>/<category>.php.
A translation present in the workbook replaces the one in the file, an empty cell included; a key the workbook
lacks is kept. An existing file keeps its docblock, and the files are sorted by key as yii message sorts them,
so a round trip without edits leaves the files unchanged.
Options
| Option | Default | Meaning |
|---|---|---|
--messagePath |
@messages |
The directory holding one subdirectory per language |
--phpDocBlock |
null |
The docblock of a message file the import creates |
--sort |
true |
Whether the import sorts the messages by key |
--width |
100 |
The width of the exported columns |
A bundle's own messages are exported with its path, for example
./yii translation/export --messagePath=@skeleton/../messages.