jenyak / i18n-routing-service-provider
Silex i18n 路由服务提供商。
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-28 18:15:58 UTC
README
Silex i18n 路由服务提供商,受 JMSI18nRoutingBundle 启发。
安装
推荐通过 composer 安装。只需将以下内容添加到您的 composer.json
文件中
Silex 1.3
{
"require": {
"jenyak/i18n-routing-service-provider": "~1.0"
}
}
Silex 2
{
"require": {
"jenyak/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', 'hu', 'ua'); // You can translate patterns $app['translator.domains'] = array('routes' => array( 'hu' => array('test_route' => '/teszt'), )); // There's no need to put {_locale} in route pattern $app->get('/test', function () { //... })->bind('test_route');
匹配的 URL 将是
/test
- 默认区域设置的无前缀 URL
/hu/teszt
- 带前缀和翻译的 URL
/ua/test
- 带前缀的 URL