Download the PHP package sentence/i18n-routing-bundle without Composer
On this page you can find all versions of the php package sentence/i18n-routing-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sentence/i18n-routing-bundle
More information about sentence/i18n-routing-bundle
Files in sentence/i18n-routing-bundle
Package i18n-routing-bundle
Short Description Full routing internationalized on your Symfony2 project
License MIT
Homepage https://github.com/Sentence/BeSimpleI18nRoutingBundle
Informations about the package i18n-routing-bundle
I18nRoutingBundle, generate your I18N Routes for Symfony2
If you have a website multilingual, this bundle avoids of copy paste your routes for different languages. Additionally it allows to translate given routing parameters between languages in Router#match and UrlGenerator#generate using either a Symfony Translator or a Doctrine DBAL (+Cache) based backend.
Information
When you create an I18N route and you go on it with your browser, the locale will be updated.
Installation
Update your configuration
Create your routing
To define internationalized routes in XML or YAML, you need to import the
routing file by using the be_simple_i18n
type:
You can optionally specify a prefix or translated prefixes as shown above.
Yaml routing file
XML routing file
Note that the XML file uses a different namespace than when using the core
loader: http://besim.pl/schema/i18n_routing
.
PHP routing file
Controller annotations
Annotation loading is only supported for Symfony 2.5 and greater and needs to be enabled as followed.
You can insert classic route in your routing
Yaml routing file
XML routing file
PHP routing file
Advanced locale support
By default this bundle allows any locale to be used and there is no check if a locale is missing for a specific route. This is great but sometimes you may wish to be strict, let take a look at the following configuration:
The locales.supported
specifies which locales are supported.
The locales.filter
option is responsible for filtering out any unknown locales so only routes for 'en' and 'nl' are available.
The locales.strict
option when set to true
is responsible for throwing a exception when a i18n route is found where the locale is unknown or where a locale is missing.
This option can also be set to null
to disable locale is missing for a route exception and false
to disable exceptions.
The locales.allowed
specifies which locales are allowed, the rest will throw a RouteNotFoundException.
Route naming
By default all routes that are imported are named '
The service must implement the BeSimple\I18nRoutingBundle\Routing\RouteGenerator\NameInflector\RouteNameInflectorInterface
interface.
There are currently 2 inflectors available by default be_simple_i18n_routing.route_name_inflector.default_postfix
.
Default postfix inflector
The default postfix inflector changed the behaviour of to only add a locale postfix when the locale is not the default locale. A example configuration is as followed.
Generate a route in your templates
Specify a locale
Twig
{{ path('homepage.en') }}
{{ path('homepage', { 'locale': 'en' }) }}
{{ path('homepage.fr') }}
{{ path('homepage', { 'locale': 'fr' }) }}
{{ path('homepage.de') }}
{{ path('homepage', { 'locale': 'de' }) }}
PHP
Use current locale of user
Twig
{{ path('homepage') }}
PHP
Translating the route attributes
If the static parts of your routes are translated you get to the point really fast when dynamic parts such as product slugs, category names or other dynamic routing parameters should be translated. The bundle provides 2 implementations.
After configuring the backend you want to use (see below for each one), you can define a to be translated attribute in your route defaults:
The same goes with generating routes, now backwards:
{{ path("product_view", {"slug": product.slug, "translate": "slug"}) }}
{{ path("product_view2", {"slug": product.slug, "translate": ["slug", "category]}) }}
The reverse translation is only necessary if you have the "original" values in your templates. If you have access to the localized value of the current locale then you can just pass this and do not hint to translate it with the "translate" key.
Doctrine DBAL Backend
Configure the use of the DBAL backend
The Doctrine Backend has the following table structure:
Lookups are made through the combination of route name, locale and attribute of the route to be translated.
Every lookup is cached in a Doctrine\Common\Cache\Cache instance that you should configure to be APC, Memcache or Xcache for performance reasons.
If you are using Doctrine it automatically registers a listener for SchemaTool to create the routing_translations table for your database backend, you only have to call:
./app/console doctrine:schema:update --dump-sql
./app/console doctrine:schema:update --force
Translator backend
This implementation uses the Symfony2 translator to translate the attributes.
The translation domain will be created using the pattern <route name>_<attribute name>
Custom backend
If you want to use a different implementation, simply create a service implementing
BeSimple\I18nRoutingBundle\Routing\Translator\AttributeTranslatorInterface
.
License
This bundle is under the MIT License (MIT). Please see License File for more information.
All versions of i18n-routing-bundle with dependencies
symfony/routing Version ~2.3 || ~3.0
symfony/config Version ~2.3 || ~3.0