Skip to content

[2.3] [Translator][FrameworkBundle] Allow remote message sources #6978

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

Closed
wants to merge 2 commits into from
Closed

[2.3] [Translator][FrameworkBundle] Allow remote message sources #6978

wants to merge 2 commits into from

Conversation

canni
Copy link
Contributor

@canni canni commented Feb 5, 2013

Currently you have to create dummy empty files in yours Resources folder
when you use customized Translation Loader Interface, because loader from
Framework Bundle omits all loaders that don't have file.

This PR attempts to fix this behaviour without BC breaks;

Example usage:
You have messages stored in MongoDB, collections are yours message domains groups.
Via DI you inject Mongo connection to loader, and then through yours implementation discover avaliable domains.

Q A
Bug fix? yes - by feature addition
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #6930
License MIT
Doc PR -

TODO if feature gets positive feedback

  • submit changes to the documentation
  • write unit tests

@canni
Copy link
Contributor Author

canni commented Feb 6, 2013

I've added some unit tests, and make code more readable, I'll update CHANGELOG and docs when we'll know if this fits into 2.2 or to master

@mpdude
Copy link
Contributor

mpdude commented Feb 27, 2013

I'd rather not create a new type of LoaderInterface for that.

The problem is that scanning for files drives the process of using the loaders. Instead, there should be a set of loaders that are used. Your database loader would be among these, probably DI based (tagged). Additionally, a list of file-based loaders would be compiled based on the translation files found.

@canni
Copy link
Contributor Author

canni commented Feb 27, 2013

@mpdude other ways of doing this breaks BC

@mpdude
Copy link
Contributor

mpdude commented Feb 28, 2013

Hm. From the docs:

If you're loading translations from a database, you'll still need a resource file, but it might either be blank or contain a little bit of information about loading those resources from the database. The file is key to trigger the load method on your custom loader.

That sounds like a deliberate design decision and it would be nice to know why it is that (file-centric) way.

@canni
Copy link
Contributor Author

canni commented Feb 28, 2013

IMO This is totally wrong... The reason you want to load translations from DB source, is that you want to generate and edit it easily. This behaviour triggers additional Point of concern that can lead to unneeded work... You always has to create dummy empty files when your remote source have new translations or domains.

@mpdude
Copy link
Contributor

mpdude commented Feb 28, 2013

Yes, I agree :-).

Currently, the Resource/translations folder is scanned for files and so a list of message domains (basename) + types (file ext) is obtained. The respective loaders are then used to load the messages for the domains.

IMHO there should be another mechanism to figure out how messages for a particular domain that is needed can be loaded. Scanning for files is only one option (easy to use), but additionally a configured loader (like the DB loader in your example) could be tagged (or queried for?) the message domains it can provide.

Update: See the way the Config/Loader/LoaderInterface is defined. That does not 100% fit Translations as the domain and locale have to be taken care of, but basically that allows to have a set of loaders and find the one (or those?) that can load a particular resource - in this case, a message domain + locale set.

@Alex-Sh
Copy link

Alex-Sh commented Jun 14, 2014

some changes for this issue?

@mpdude
Copy link
Contributor

mpdude commented Apr 11, 2015

I've come across this again recently. IIRC all you need to do is to 1) add your custom loader to the Translator (in the DIC) and 2) add an addResoure call for every locale and domain that finally triggers your loader.

The FrameworkBundle (?) adds the resources based on the files found, but in fact, you don't need the files when you add the resources yourself.

@fabpot
Copy link
Member

fabpot commented Jun 9, 2016

@mpdude Is it still relevant in Symfony 3?

@tgalopin
Copy link
Contributor

@fabpot I think this is still revelant and I think there is room for improvement here, especially by creating a native PDO based loader for translations. However, to do that would probably require BC breaks given the current implementations of the Translator loaders.

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@mpdude
Copy link
Contributor

mpdude commented Jun 3, 2017

I am pretty sure that you don't need to create these dummy files, just tweak the DIC and add addResource calls to the translator.default.

We have a custom bundle to load messages from a database, and it works without dummy files. So I'd say this can be closed and/or is not relevant for Symfony 3.

(Yes, there is a little issue regarding the loading order of these resources, see #23057.)

@fabpot fabpot closed this Jun 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants