Carlos Vázquez
Carlos Vázquez

Reputation: 388

Different host and routes in Symfony witho JMS i18n

I want different host and different routes in my multicountry web with Symfony 3. I used the JMS i18n routing for this. My config YML file:

jms_i18n_routing:
    default_locale: es_ES
    locales: [es_ES, fr_FR, en_GB]
    strategy: custom
    hosts:
        es_ES: www.aaa.local
        fr_FR: www.aaa-fr.local
        en_GB: www.aaa-uk.local
    redirect_to_host: true

With this, I can use different host correctly, but I don't know how I can "translate" the routes, f.ex: /contacto /contact and /contact.

I want load differents routing.yml depends on the locale.

Upvotes: 0

Views: 457

Answers (1)

toooni
toooni

Reputation: 345

When using the JMSI18nRoutingBundle your routes are being Translated automatically based on your route_name using the routes domain (Symfony Translation Component). So, assumed your route_name is contact, just create a Translations like this:

id/source: contact
domain: routes
locale: en
translation/target: /contact

id/source: contact
domain: routes
locale: es
translation/target: /contacto

Now your routes using the Symfony router (which is wrapped by the one from the bundle) will return automatically the translated route from the current locale. If you want to translate it to a specific locale, just add the route parameter _locale like this:

{{ path("contact", {"_locale": "es"}) }}

or

$this->get('router')->generate('contact', array('_locale' => 'es'));

Upvotes: 2

Related Questions