I'm looking for an elegant way to have the following behavior in Symfony 6.
I use DoctrineBehaviors/translatable to store some fields in several languages, let's say 'en', 'fr' and 'de'.
The users have a small dropdown on my navbar, with which they can choose the locale in which they read the site. Changing the locale in this dropdown, triggers a redirection to the routes in the format given below, to display the entities in the chosen locale:
/{_locale}/entity/{id}
Now the tricky part: I would like to have two default locales, 'en' and 'fr', as fallbacks for a reader whose 'de' translation is missing.
Let's say my entities have the following translations (--
means translation is ABSENT from database, not empty string):
A : [ en fr de ]
B : [ en -- -- ]
C : [ -- fr -- ]
D : [ en fr -- ]
I would like the following routes to display text like this:
/en/entity/A --> en
/fr/entity/A --> fr
/de/entity/A --> de
/en/entity/B --> en
/fr/entity/B --> en
/de/entity/B --> en
/en/entity/C --> fr
/fr/entity/C --> fr
/de/entity/C --> fr
/en/entity/D --> en
/fr/entity/D --> fr
/de/entity/D --> (not important as long as either en or fr is displayed)
Today, as I can have only one default_locale
, I must choose either 'fr' or 'en', but if I choose 'en', then /de/entity/C will display an empty 'en' translation, and if I choose 'fr', then /de/entity/B will display an empty 'fr' translation.
I've tried to setup two fallbacks in translations.yaml but it doesn't work, I fear it's more used by translations in translation files, and not in database.
framework:
default_locale: en
translator:
fallbacks: ['fr', 'en']
Thanks in advance if you can help me