Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate URL #218

Open
kironet opened this issue Dec 7, 2017 · 5 comments
Open

Translate URL #218

kironet opened this issue Dec 7, 2017 · 5 comments

Comments

@kironet
Copy link

kironet commented Dec 7, 2017

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")

@bocharsky-bw
Copy link

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 :/

@kironet
Copy link
Author

kironet commented Dec 19, 2017

@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

@bocharsky-bw
Copy link

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?

@kironet
Copy link
Author

kironet commented Dec 19, 2017

@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.

@bocharsky-bw
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants