argentum / translation-bundle
Provides a database storage for translations and GUI for editing them
Installs: 1 081
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.4.0
- a2lix/translation-form-bundle: >=2.0
- doctrine/common: >=2.2
- doctrine/orm: >=2.2
- knplabs/doctrine-behaviors: >=1.0
- sonata-project/admin-bundle: >=2.0
- sonata-project/doctrine-orm-admin-bundle: >=2.2
- symfony/monolog-bundle: >=2.3
- symfony/symfony: >=2.3
- twig/twig: >=1.10
Requires (Dev)
- doctrine/doctrine-fixtures-bundle: >=2.2
- liip/functional-test-bundle: >=1.1.0
- phpunit/phpunit: ^4.8.35|^5.4.3
- satooshi/php-coveralls: 1.0.*
This package is auto-updated.
Last update: 2024-11-19 20:03:36 UTC
README
ArgentumTranslationBundle provides a database storage for translations and GUI for editing them.
This bundle supports PHP 5.4+ and Symfony 2.3+.
The bundle combines the power of the following bundles:
Installation
Install the bundle with composer:
composer require argentum/translation-bundle:dev-master
Register the bundle in app/AppKernel::registerBundles()
:
$bundles = array( // ... new Argentum\TranslationBundle\ArgentumTranslationBundle(), // ... );
Configuration
In the parameters.yml
you should configure a list of locales:
parameters: locales: - ru - uk - en
Then in the config.yml
you should add the following options:
a2lix_translation_form: locales: %locales% argentum_translation: locales: %locales%
Make sure you have registered KnpLabs DoctrineBehaviors Listeners in your config.yml
:
imports: - { resource: ../../vendor/knplabs/doctrine-behaviors/config/orm-services.yml }
and have registered A2lixTranslationFormBundle in app/AppKernel::registerBundles()
:
$bundles = array( // ... new A2lix\TranslationFormBundle\A2lixTranslationFormBundle(), // ... );
And finally, create translation tables in your database:
app/console doctrine:schema:update --force
or create a migration and execute it:
app/console doctrine:migrations:diff app/console doctrine:migrations:migrate
Translation editor
Now you can use GUI for editing the translations.
The bundle will automatically add additional items in the menu of your Sonata Admin. If you have customized the menu, you should add Translation group in config.yml
:
sonata_admin: dashboard: groups: // ... Translation: ~
The list of all domains is located at URL something like (depends on the base location of Sonata Admin in your project): /admin/argentum/translation/translationdomain/list
.
Loading order
When merging all translations together translations from files in all bundles will be loaded, and then all translations from the database will be loaded. Thus, translations from the database can override any translation from the translation files in your project.
Proposed workflow
Firstly, when developing your project you should use admin panel to create all necessary domains and add all necessary translations to them.
Secondly, when your bundle is ready, you should export all translations for the bundle domain into the bundle translation files and commit them to VCS.
And finally, when your project is started, you or your client can edit any translation without need to edit project files.
Cache
All translations are cached in the cache files and will be loaded from the database only once after clearing the cache.
Export
This bundle allows you to export translations from the database for single domain or all domains in the specified directory for the specified locales using the specified format.
Export all translations to the directory:
app/console translation:export --dir=/path/to/translations
Export translations for domain "messages":
app/console translation:export --dir=/path/to/translations messages
Export translations for domain "messages" and locales "ru" and "uk" in xliff format:
app/console translation:export --dir=/path/to/translations --locales="ru,uk" --format=xlf messages
Import
This bundle allows you to import translations from files into the database.
Import all translations from the specified directory:
app/console translation:import --dir=/path/to/translations
Import translations from the directory only for the domain "messages":
app/console translation:import --dir=/path/to/translations messages
Import translations from the directory only for the domain "messages" and locales "ru" and "uk":
app/console translation:import --dir=/path/to/translations --locales="ru,uk" messages
Import translations from the specified bundles:
app/console translation:import --bundles="SonataAdminBundle, SonataUserBundle"
Import translations from the entire project including all bundles, Form and Validation components, and local application translations:
app/console translation:import