I use 2 different loader for symfony translations :
- Yaml basic loader (already implemented).
- A custom loader who save translations into a db table.
The first loader is for developer purpose (having a translation when the code is displayed in localhost without having to maintain a db). The second is for the stage / production env. Basically, POs are using this solution and developers don't have to trigger all the CI/CD process for just change one or two translations.
So, we have the same keys into the two loaders. I want the database Loader to be displayed in priority if the translation key exists in the table, else the yaml Loader take the lead.
Unfortunately, I can display database translation for some keys but, since I have multiple yaml files for the translation, some of them are not overwritten.
Is it possible in Symfony 4 to set a default Loader, or to define priorities ? If yes, how ?
If no, can we easely force the loading of all translation files in a certain order to be sure that the last file loading is the db file ?
You have multiple possibilities:
your custom loader can have a priority (higher means it called earlier). When your DB service should be last, set it to a negative number:
Implement a new service that decorates the
\Symfony\Contracts\Translation\TranslatorInterfaceservice. Within this new service, overridedoLoadCatalogue. This function is responsible for loading all data from the configured loaders. In the overridden function you can customize the logic completely.