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

Multiple dynamic translation paths #495

Open
eotin opened this issue Oct 19, 2023 · 2 comments
Open

Multiple dynamic translation paths #495

eotin opened this issue Oct 19, 2023 · 2 comments

Comments

@eotin
Copy link

eotin commented Oct 19, 2023

Hi,

I've a app that support multi language (fr & en) and is available for different "countries". This country parameters depends on a route (so we have 2 parameters that operate on the translation , locale + country
What I would like to do is to be able to override some translation keys per country for the same language.

Example :
Http call to http://MyApp/en/germany/myForm will give me a different than http://MyApp/en/france/myForm because the translator nows that for 'france' it should get the translation from another path than for 'germany'. So it will override the default folder that includes all default translations ..

I was wondering how to create multiple translator instances that have it's proper paths of translations files, and have a factory that return the right translatorService regarding the country parameter.

What is the best way to achieve that ?

Thanks for helping

@bocharsky-bw
Copy link
Member

Ideally you need to use specific country in the locale, i.e. instead of just en you need to use en_GB, en_US, etc. And so instead messages.en.yaml you would create different translation files for the specific country, i.e. messages.en_GB.yaml, messages.en_US.yaml, see some examples from the Symfony Demo: https://github.com/symfony/demo/tree/main/translations . In this case Symfony translator would handle everything for you picking up correct translation base on country. But in case you want to handle it yourself via a special route parameter - not sure, it would lead to a workaround and extra work from your side probably.

I hope this helps

@eotin
Copy link
Author

eotin commented Oct 19, 2023

Thanks for your reply.

This solution would not fit as I used a country parameter as example but it could be another.
Do you have any example where I can override some paths of the translator ? or create different instances ?
Thanks for your help

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