albertofem/translatableroutepath-bundle

JpnForPhp Symfony2 扩展包集成

dev-master 2014-11-30 15:14 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:52:02 UTC


README

build status Scrutinizer Code Quality

允许在路由路径中使用翻译

/**
 * @Route("/[my.translatable.key]/route/{param}", options={"translatable"=true})
 */
public function myAction()
{
}

如果 my.transatable.key 在英语中定义为: my_translatable_route,这将生成一个路由

/my_translatable_route/route/whatever_param

安装

在 composer 中要求它

composer require albertofem/translatableroutepath-bundle dev-master

安装它

composer update albertofem/translatableroutepath-bundle

将其添加到您的扩展包中

$bundles = array(
    ...,
    new \AFM\Bundle\TranslatableRoutePathBundle\AFMTranslatableRoutePathBundle()
);

此外,您可以使用此扩展包与 JMSI18nRoutingBundle 一起使用,在这种情况下,您需要在此扩展包之前注册它

$bundles = array(
    ...
    new \JMS\I18nRoutingBundle\JMSI18nRoutingBundle(),
    new \AFM\Bundle\TranslatableRoutePathBundle\AFMTranslatableRoutePathBundle()
);

如果您需要运行测试

./vendor/bin/phpunit

使用方法

您需要将可翻译选项添加到您的路由中

/**
 * @Route("/[my.translatable.key]/route/{param}", options={"translatable"=true})
 */
public function myAction()
{
}

使用 YAML

my_translatable_route:
    path: /[my.translatable.key]/route/{param}
    options: { translatable: true }

使用 [...] 语法来引用路由路径中的翻译。您可以在注释/yaml/PHP 中无区别地使用此语法。

JMSI18nRoutingBundle 集成

如果您使用此优秀的扩展包,路由将自动翻译为配置中设置的所有区域设置。

与 Symfony 核心路由器集成

当使用 Symfony 核心路由器时,所有路由都翻译为默认区域设置。如果需要将路由翻译为其他语言,您必须指定 _locale 默认参数

my_translatable_route:
    path: /[my.translatable.key]/route/{param}
    options: { translatable: true }
    defaults: { _locale: en } # this route will translated in English

待办事项

  • 支持翻译参数(域等)
  • 支持 transChoice