ao/translation-bundle

Doctrine 作为 symfony 翻译提供者 + 一个用于编辑翻译的优雅 GUI。

1.0.4 2015-05-12 06:47 UTC

This package is not auto-updated.

Last update: 2024-09-28 14:48:02 UTC


README

此扩展提供 doctrine 作为翻译存储和可从分析器访问的优雅 Web GUI,方便进行翻译。

Build Status

功能

  • 所有翻译消息都会自动保存到数据库中(无需提取)
  • 翻译面板可在 Symfony Web 调试工具栏中使用
  • 只有当前动作中使用的消息才会从数据库中加载
  • 通过 SonataAdminBundle 提供的翻译管理后端

安装

需要供应商库

composer.json 中需要 ao/translation-bundle & stof/doctrine-extensions-bundle

"require": {
  "symfony/symfony": "2.1.*",
  "_comment": "other packages",
  "stof/doctrine-extensions-bundle": "1.1.*@dev",
  "ao/translation-bundle": "1.0.*@dev"
}

然后使用以下命令安装或更新 composer 扩展

php composer.phar install

php composer.phar update

将扩展添加到您的应用程序内核

app/AppKernel.php 中添加

// app/AppKernel.php
public function registerBundles()
{
    return array(
        //...
        new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
        new AO\TranslationBundle\AOTranslationBundle()
        //...
    );
}

配置翻译器

# app/config/config.yml
# enable translation component
framework:
    translator: ~

# use AOTranslationBundle as translator
parameters:
    translator.class: AO\TranslationBundle\Translation\Translator

# configure locales avaliable for translation 
ao_translation:
    locales:
        en: ~
        de:
          label: German
        fr: ~

配置 doctrine 扩展扩展

必须启用可变时间戳行为。

# app/config/config.yml
stof_doctrine_extensions:
    orm:
        default:
            timestampable: true

更新您的数据库模式

如果您使用迁移

app/console doctrine:migrations:diff
app/console doctrine:migrations:migrate

否则

app/console doctrine:schema:update

添加路由信息

# app/config/routing.yml
ao_translation:
    resource: "@AOTranslationBundle/Controller/"
    type:     annotation
    prefix:   / 

使用方法

使用与 Symfony 翻译 文档中描述的翻译方法。

翻译面板

您可以通过点击 Web 调试工具栏中的“翻译”来访问翻译面板。

Translations web debug toolbar

现在您可以编辑所有的翻译消息。可以在 参数 (2)列中直接通过点击链接将消息参数插入到翻译中。完成后,请点击 保存翻译 按钮(1)。

由于翻译器需要知道每个动作中使用的哪些消息,因此它会将这种关系存储在缓存表中。因此,当某个消息不再使用时,它仍然会在翻译面板中可见。要清除缓存的消息,请使用 重置动作缓存 (3)按钮,这将清除当前动作的缓存。或者,使用 重置缓存 (4)按钮,这将清除所有动作的缓存。缓存将在下一次执行动作时重建。

Translations panel

翻译后端

要使用翻译后端,您需要安装 SonataAdminBundleSonataDoctrineORMAdminBundle。请参阅它们的安装指南。安装和配置后,后端将在 /admin/ao/translation/message/list 下可用。

其他功能

使用单独的数据库连接来存储翻译

如果您需要共享翻译数据库(例如,当多个开发者协作时),可以为该扩展配置 单独的实体管理器

# app/config/config.yml
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                ...
            # configure translations database connection
            translations:
                ...
                
orm:
    ...
    default_entity_manager: default
    entity_managers:
        default:
            connection: default
            mappings:
                ...
        translations:
            connection: translations
            mappings:
                AOTranslationBundle: ~

ao_translation:
    entity_manager: translations

stof_doctrine_extensions:
    orm:
        ...
        # enable timestampable behavior for translations entity manager
        translations:
            timestampable: true

要创建翻译模式,请使用 --em 参数,如下所示

app/console doctrine:schema:create --em=translations