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

[question] Configure locales in database?

Open yellow1912 opened this issue 6 years ago • 5 comments

This is not an issue, but rather a question. In our system we configure the list of locales in database for easy removal, addition and such. At the point where the DependencyInjection runs, I don't think we can populate these information from database to the bundle configs yet. I wonder if the locales can be set at run time? Or maybe they are not even needed to be set at all? I'm under the assumption that locales variable is needed only for editing translation.

yellow1912 avatar Feb 04 '18 15:02 yellow1912

For symfony there is no need to set these locales.

For this bundle however, yes we need a list of locales to be able to show you proper data in web UI and some more places. Can you just add "all" possible locales in the config? It does not really matter if one locale is not used or active.

Nyholm avatar Feb 04 '18 15:02 Nyholm

@Nyholm thank you for your quick response.

Basically, what we build is a CMS on top of SF, I don't know what locales the customers will use. So the possibility will be all the locales in the world which I don't think we should put in. I took a very quick look at the code and believe with some minor changes it could be possible to do this in run time, for example:

$c['locales'] = $config['locales'];
$configurationServiceId = 'php_translation.configuration.'.$name;
$configDef = $container->register($configurationServiceId, ConfigurationModel::class);
$configDef->setPublic(false)->addArgument($c);

configDef could be tagged for easy retrieval outside of the bundle, and the ConfigurationModel could allow updating configs after intialization. On the side note, I wonder why it is necessary to set the locales to $configDef, because from the way it looks every $configDef will have the exact same locales anyway. May make more sense to set that $configurationManager.

I don't know the code deep enough to know if setting the configs at run time maybe too late for anything (my assumption is that translation service is not needed very early during run time anyway). If you think this looks good I can fork the bundle and try to run my own version first. If all is fine I can create a PR. The changes I propose should not present and BC because all current configs should work just fine.

yellow1912 avatar Feb 04 '18 15:02 yellow1912

Hm I see.

Each Configuration object needs the locale because they should be self-contained. Ie "here is everything you need to know about this configuration". I do also see updates in the future where one can have different locales on different configurations.

Adding a tag on $configDef to let you change its values in a CompilerPass sounds like a good idea. (If you are able to create your logic in a compiler pass). I'll be happy to review such PR.

Nyholm avatar Feb 04 '18 16:02 Nyholm

Hi @yellow1912, is there any update about your needs?

welcoMattic avatar Jan 20 '20 21:01 welcoMattic

Hi, Does anyone have a solution?

abozhinov avatar Dec 30 '20 20:12 abozhinov