段落1 / i18n-routing-service-provider
Silex i18n 路由服务提供程序。从 ehibes/I18nRoutingServiceProvider 分支而来
v1.0
2015-09-14 13:25 UTC
Requires
- silex/silex: ~1.1
- symfony/translation: ~2.4
Requires (Dev)
- phpunit/phpunit: 4.8
This package is not auto-updated.
Last update: 2024-09-14 19:25:43 UTC
README
I18n 路由服务提供程序

由 JMSI18nRoutingBundle 启发,为 Silex 提供国际化路由服务
安装
推荐安装方式是通过 Composer。只需将以下内容添加到您的 composer.json
文件中
Silex 2
{
"require": {
"paragraph1/i18n-routing-service-provider": "dev-master"
}
}
注册
$app->register(new Jenyak\I18nRouting\Provider\I18nRoutingServiceProvider());
参数
- i18n_routing.translation_domain: 路由的翻译域。默认值是
routes
。 - i18n_routing.locales: 路由的区域设置。默认值是
array(en)
。 - locale: 默认路由区域设置。默认值是
en
。
示例
$app = new Application(); //... $app->register(new Jenyak\I18nRouting\Provider\I18nRoutingServiceProvider()); $app['locale'] = 'en'; $app['i18n_routing.locales'] = array('en', 'eu', 'fr'); // You can translate patterns $app['translator.domains'] = array('routes' => array( 'fr' => array('test_route' => '/entsegu-bat'), )); // There's no need to put {_locale} in route pattern $app->get('/test', function () { //... })->bind('test_route');
匹配的 URL 将是
/en/test
- 默认区域设置的 URL,无前缀
/eu/entsegu-bat
- 带前缀和翻译的 URL
/fr/test
- 带前缀的 URL
禁用路由的 I18n
$app->get('/dont-translate', function() { //... })->bind('my_route')->getRoute()->setOption('i18n', false); # Careful when using Silex\Provider\TranslationServiceProvider ```php $app = new Application(); // when also using TranslationServiceProvider add your routes when registering it: $app->register(new Jenyak\I18nRouting\Provider\I18nRoutingServiceProvider()); ... $app->register(new \Silex\Provider\TranslationServiceProvider(), array( 'locale_fallbacks' => array('en'), 'translator.domains' => array( 'fr' => array('test_route' => '/entsegu-bat') ) ));