argentum / translation-bundle
提供翻译的数据库存储和编辑GUI
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-09-19 19:37:58 UTC
README
ArgentumTranslationBundle提供了翻译的数据库存储和编辑GUI。
此bundle支持PHP 5.4+和Symfony 2.3+。
该bundle结合了以下bundle的功能
安装
使用composer安装bundle
composer require argentum/translation-bundle:dev-master
在app/AppKernel::registerBundles()
中注册bundle
$bundles = array( // ... new Argentum\TranslationBundle\ArgentumTranslationBundle(), // ... );
配置
在parameters.yml
中配置地区列表
parameters: locales: - ru - uk - en
然后在config.yml
中添加以下选项
a2lix_translation_form: locales: %locales% argentum_translation: locales: %locales%
确保您已在config.yml
中注册了KnpLabs DoctrineBehaviors监听器
imports: - { resource: ../../vendor/knplabs/doctrine-behaviors/config/orm-services.yml }
并且在app/AppKernel::registerBundles()
中注册了A2lixTranslationFormBundle
$bundles = array( // ... new A2lix\TranslationFormBundle\A2lixTranslationFormBundle(), // ... );
最后,在您的数据库中创建翻译表
app/console doctrine:schema:update --force
或创建迁移并执行它
app/console doctrine:migrations:diff app/console doctrine:migrations:migrate
翻译编辑器
现在您可以使用GUI编辑翻译。
该bundle会自动在Sonata Admin的菜单中添加额外的项目。如果您已自定义菜单,应在config.yml
中添加Translation组
sonata_admin: dashboard: groups: // ... Translation: ~
所有域的列表位于以下URL(取决于项目中的Sonata Admin基本位置):/admin/argentum/translation/translationdomain/list
。
加载顺序
合并所有翻译时,将先加载所有bundle中的文件翻译,然后加载数据库中的所有翻译。因此,数据库中的翻译可以覆盖项目中的任何翻译文件。
建议的工作流程
首先,在开发项目时,您应使用管理面板创建所有必要的域并将所有必要的翻译添加到其中。
其次,当您的bundle准备就绪时,您应将bundle域的所有翻译导出到bundle翻译文件并提交到版本控制系统。
最后,当项目启动时,您或您的客户可以编辑任何翻译,而无需编辑项目文件。
缓存
所有翻译都缓存在缓存文件中,并且仅在清除缓存后从数据库加载一次。
导出
此bundle允许您将数据库中的翻译导出到指定目录的指定地区和格式。
将所有翻译导出到目录
app/console translation:export --dir=/path/to/translations
导出"messages"域的翻译
app/console translation:export --dir=/path/to/translations messages
以xliff格式导出"messages"域和地区"ru"和"uk"的翻译
app/console translation:export --dir=/path/to/translations --locales="ru,uk" --format=xlf messages
导入
此bundle允许您将文件中的翻译导入到数据库。
从指定目录导入所有翻译
app/console translation:import --dir=/path/to/translations
仅从目录导入"messages"域的翻译
app/console translation:import --dir=/path/to/translations messages
仅从目录导入"messages"域和地区"ru"和"uk"的翻译
app/console translation:import --dir=/path/to/translations --locales="ru,uk" messages
从指定bundle导入翻译
app/console translation:import --bundles="SonataAdminBundle, SonataUserBundle"
从整个项目导入翻译,包括所有bundle、表单和验证组件以及本地应用翻译
app/console translation:import