ehibes/silex-i18n-routing-service-provider

Silex i18n路由服务提供商。

1.0.x-dev 2016-02-04 15:22 UTC

This package is auto-updated.

Last update: 2024-09-25 19:37:15 UTC


README

Silex i18n路由服务提供商,灵感来源于 jenyak I18nRoutingServiceProvider

安装

推荐通过composer进行安装。只需将以下内容添加到您的composer.json文件中

Silex 1.3

{
    "require": {
        "ehibes/i18n-routing-service-provider": "~1.0"
    }
}

Silex 2

{
    "require": {
        "ehibes/i18n-routing-service-provider": "dev-master"
    }
}

注册

$app->register(new Ibes\I18nRouting\Provider\I18nRoutingServiceProvider());

参数

  • i18n_routing.locales:路由区域设置。默认值为array(en)
  • locale:默认路由区域设置。默认值为en

示例

$app = new Application();
//...
$app->register(new Ibes\I18nRouting\Provider\I18nRoutingServiceProvider());
$app['locale'] = 'en';
$app['i18n_routing.locales'] = array('en', 'eu', 'fr');

// There's no need to put {_locale} in route pattern
$app->get('/test', function () {
   //...
})->bind('test_route')->getRoute()->setOption('i18n', array('eu' => 'entsegu-bat'));

匹配的URL将是

/en/test - 默认区域设置前缀的url

/eu/entsegu-bat - 带前缀和翻译的url

/fr/test - 带前缀的url