schmittjoh/JMSI18nRoutingBundle

Translate URL

Opened this issue · 5 comments

Hello,

I'm trying to translate url.
Example:

Now:

domain.com/en/category/1
domain.com/cs/category/1
domain.com/it/category/1

Expected:

domain.com/en/category/1
domain.com/cs/kategorie/1
domain.com/it/categoria/1

I'm searching on google but can't find the solution or hint for this.

My config:

parameters:
    locale: 'cs'
    app_locales: [cs, en, it]
jms_i18n_routing:
    default_locale: cs
    locales: "%app_locales%"
    strategy: prefix_except_default

My route:

@Route("/category/{categoryID}", name="category_products")

Good question! I wonder it too. In docs I see we can use custom strategy to solve this:
http://jmsyst.com/bundles/JMSI18nRoutingBundle/master/configuration#scenario-something-else

But there's not enough information about it :/

@bocharsky-bw
I've figured it out.

Create routes.locale.yml file and put there your routes translation. Example from my project:

routes.en.yml

accessories_index: /accessories
accessories_list: '/accessories/{category}'
accessories_list_paginated: '/accessories/{category}/page/{page}'
accessory_detail: 'accessories/{url}'
contact_index: /contact-us

routes.cs.yml

accessories_index: /prislusenstvi
accessories_list: '/prislusenstvi/{category}'
accessories_list_paginated: '/prislusenstvi/{category}/stranka/{page}'
accessory_detail: 'prislusenstvi/{url}'
contact_index: /kontakty

Hey @kironet ,

That's great! And thanks for this ping! Just want to clarify a bit, do you need to create those routes.%locale%.yml files in a specific directory? Or it's no difference, you just need to require it in main routing.yml?

@bocharsky-bw
For symfony flex(SF 3.4/4.0+)

Directory: /translations

For symfony standard(../3.3/3.4)

the app/Resources/translations directory;
the app/Resources/[bundle name]/translations directory;
the Resources/translations/ directory inside of any bundle.

Ah, ok, thanks again! I'll give it a try. Btw, would you like to create a PR to the docs about this feature?