That bundle allows you to configure host+prefix per locale.
For the following websites:
- www.website.com (english)
- www.website.de (german)
- www.website.be/fr/ (french of Belgium)
- www.website.be/nl/ (dutch of Belgium)
The configuration will be:
# config/packages/jms_i18n_routing.yaml
jms_i18n_routing:
locales:
en: //www.website.com
de: //www.website.de
fr_BE: //www.website.be/fr
nl_BE: //www.website.be/nl
To translate the route named "contact_page" in german :
# translations/routes.de.yml
contact_page: /kontakt
Thus the route named contact_page will be used when calling:
To disable i18n feature for specific route:
@Route("/api", options={"i18n"=false})
or
# app/config/routing.yaml
apiendpoint:
...
options: { i18n: false }
To enable the routes only for a subset of locales:
@Route("/about", options={"i18n_locales"={"en", "de"}})
Thoses locales must be configured in jms_i18n_routing.locales
composer req remmel/i18n-routing-bundle
// config/bundles.php
return [
// ...
JMS\I18nRoutingBundle\JMSI18nRoutingBundle::class => ['all' => true],
];
Simple configuration with 2 "folders" :
# config/packages/jms_i18n_routing.yaml
jms_i18n_routing:
locales:
en: /eng
de: /deu
When updating that config, it might be needed to clear cache: bin/console cache:clear
Check that configuration is fine running bin/console debug:router
Full Symfony application example
That code is based on JMSI18nRoutingBundle.
That fork has been simplified to only keep the code related to the prefix/host per locale.
Symfony 4.1 now handle the translation of route and the prefix.
Symfony 5.1 now handle the different host per locale.
Thus, that extension is usefull if you want to externalize route translations (eg in routes.xx.yml).
That bundle will be useless when that feature will be implemented and translations externalized in routes.??.yml files.