4

我的语言环境声明parameters.yml

parameters:
    locale:            en
    locales:           [ en, de, fr, it, es, pt, ru, ja, zh ]

并想重用locales参数routing.yml

homepage_locale:
    pattern: /{_locale}
    defaults: { _controller: SiteBundle:World:index }
    requirements: { _locale: %locales% }

但这显然会导致

The container parameter "locales", used in the route configuration value 
"%locales%", must be a string or numeric, but it is of type array.

有没有办法重用这个参数,或者我真的必须把语言环境写成一个字符串来满足这个 yaml/regex 格式,像这样:

en|de|fr|it|es|pt|ru|ja|zh
4

3 回答 3

4

在 src/AppBundle/DependencyInjection/AppExtension.php

您可以在加载功能中添加此代码

    $languages = $container->getParameter('languages');
    $container->setParameter('languages_string', implode('|', $languages));

然后你可以在你的注释中使用

     *     requirements={"_locale": "%languages_string%"},

它可以防止配置文件中出现重复的参数。

于 2016-11-22T14:32:12.300 回答
1

怎么样:

parameters:
    locale:            en
    locales:           en|de|fr|it|es|pt|ru|ja|zh
于 2014-01-30T17:16:27.767 回答
-1

也许你必须尝试

_locale: en|de|fr|it|es|pt|ru|ja|zh

好看

于 2014-01-30T18:07:48.077 回答