astina/translation-bundle

使用DoctrineLoader将翻译存储在数据库中,并提供简单的管理界面来编辑翻译消息。

安装: 465

依赖者: 0

建议者: 0

安全: 0

星级: 0

关注者: 20

分支: 0

类型:symfony-bundle

1.0.0 2016-07-01 08:15 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:18:44 UTC


README

使用DoctrineLoader将翻译存储在数据库中,并提供简单的管理界面来编辑翻译消息。

安装

步骤 1: 添加到composer.json

"require":  {
    "astina/translation-bundle":"dev-master",
}

步骤 2: 启用组件

在内核中启用组件

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Astina\Bundle\TranslationBundle\AstinaTranslationBundle(),
    );
}

步骤 3: 配置组件

组件配置

# app/config/config.yml
astina_translation:
    domains: [ messages ]
    locales: [ de, fr, it, en ]
    admin:
        layout_template: ::translation_layout.html.twig
    filters:
        - { name: filter_common, domain: messages, filter: '!weather% AND !wispo% AND !booking%' }
        - { name: filter_weather, domain: messages, filter: 'weather% OR wispo%' }
        - { name: filter_booking, domain: messages, filter: 'booking%' }

路由配置(如果需要管理界面)

# app/config/routing.yml
astina_translation:
    resource: "@AstinaTranslationBundle/Resources/config/routing.yml"
    prefix:   /admin/translations

用法

您可以使用翻译存储库服务添加/更新消息。

$repo = $container->get('astina_translation.repository.translation');
$repo->set('messages', 'foo', 'fr', 'foux');

注意:添加/更改翻译后,需要清除缓存。

如果您已添加路由配置,您可以通过访问 /admin/translations 来编辑存储在数据库中的消息。保存后缓存会自动清除。

导出翻译

您可以使用导出命令将所有存储的翻译导出到PHP数组或JSON字符串。

php app/console astina:translation:dump