argentum/translation-bundle

提供翻译的数据库存储和编辑GUI

v1.0.3 2017-11-23 23:03 UTC

This package is auto-updated.

Last update: 2024-09-19 19:37:58 UTC


README

SensioLabsInsight Build Status Coverage Status Latest Stable Version License

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