symfony-bundle icon indicating copy to clipboard operation
symfony-bundle copied to clipboard

Multiple dynamic translation paths

Open eotin opened this issue 1 year ago • 2 comments

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

eotin avatar Oct 19 '23 11:10 eotin

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

bocharsky-bw avatar Oct 19 '23 12:10 bocharsky-bw

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

eotin avatar Oct 19 '23 13:10 eotin