Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[RFC] Factor loading and caching out of Translator#14622

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
mpdude wants to merge4 commits intosymfony:2.8fromwebfactory:translator-factor-out-loading
Closed

[RFC] Factor loading and caching out of Translator#14622

mpdude wants to merge4 commits intosymfony:2.8fromwebfactory:translator-factor-out-loading

Conversation

mpdude
Copy link
Contributor

QA
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?not yet added to the code, but will follow
Tests pass?yes
Fixed tickets14622
LicenseMIT
Doc PRnone

See#14530 for a discussion what this PR tries to achieve.

This is WIP, so for the time being please comment on the general approach and not on CS glitches.

Todo:

  • Move fallback locales from theTranslator into the newDefaultProvider? That way the Providers would resemble (or could even implement)TranslatorBagInterface.
  • Discuss/finalize namings
  • Figure out how to deprecateprotected methods appropriately
  • Come up with a plan how the final result in 3.0 should look like.
  • Can I preserve git history for code moved around?
  • Refactor existing and possibly add new tests
  • Make sureassertValidLocale calls are put in a few but "strategically right" places to prevent fixed problems from re-appearing (also when possibly using new components in isolation).

@aitboudad
Copy link
Contributor

I'm not sure if we needMessageCatalogueProviderInterface here onlyTranslatorBagInterface is enough, I already started working on thishttps://gist.github.com/aitboudad/6eed3ff1187bd8930520#file-delegatingloader-php but couldn't find time to complete it :( maybe I provide an initial work this week-end.

@mpdude
Copy link
ContributorAuthor

@aitboudad Yes, I am not sure yet how we need to design those interfaces.

Let's see what we're aiming at:

The long-term goal is to get a better encapsulation ofMessageCatalogues inside theTranslator, so that theTranslator could use (for example) "inlined" fallback messages.

There are, however,use cases where clients need to access the full set of messages. Currently they can get those fromTranslator through theTranslatorBagInterface, but that would not work if theTranslator only has the "optimized" catalogues available (or it would need to juggle with the "full" and "optimized" catalogues at the same time).

So it would be helpful if theTranslator could handoffgetCatalogue() calls to some other (internal/helper) class or if clients could query that class directly. Also note that in order to accomplish its main task (seeTranslatorInterface), all theTranslator would need to have is some implementation ofTranslatorBagInterface.

That would also simplifyTranslator a lot, because most of its code (and the intricate call graph) actually results from loading and caching message catalogues (both on disk and in-memory), even allowing subclasses to override someprotected methods.

If the fallback locales were moved to theProvider part as well, theProvider could extend/implement theTranslatorBagInterface. And once we've got rid of theprotected methods inTranslator (loadCatalogue,initCatalogue,computeFallbackLocales) and remove the "configuration" things (addResource,setFallbackLocales,addLoader...), we'd pretty much be set withTranslator using aTranslatorBag and performing the translating part only.

So why do I currently need another interface?

InsideTranslator, there were already two distinct parts of code.initializeCacheCatalogue,dumpCatalogue andgetFallbackCatalogue are needed for caching only. They will eventually callinitializeCatalogue and its sub-methodsdoLoadCatalogue,loadFallbackCatalogue to do the actual loading.loadCatalogue would dispatch to either part, depending on caching being desired or not.

This naturally led to a decorator-based approach for the Providers. But the cache has at least to be aware of the resources used to correctly separate cached data. Thus, we needMessageCatalogueProviderInterface as a more powerful way of configuring and composing the load-and-cache related parts.

Does that make sense? In what direction should we proceed from here?

@aitboudad
Copy link
Contributor

@mpdude see#14671

@mpdudempdude changed the title[WIP] Factor loading and caching out of Translator[RFC] Factor loading and caching out of TranslatorOct 1, 2015
@nicolas-grekasnicolas-grekas added this to the3.x milestoneDec 6, 2016
@nicolas-grekas
Copy link
Member

nicolas-grekas commentedFeb 14, 2017
edited
Loading

I think we don't need this one: optimized caching is already dealt with on PHP7, where static arrays and static strings are far superior optimization strategies. Thus, no need to do anything more on our side to me.

@nicolas-grekas
Copy link
Member

Closing for the reason given above (and lack of contra-arguments :) )

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
3.4
Development

Successfully merging this pull request may close these issues.

4 participants
@mpdude@aitboudad@nicolas-grekas@javiereguiluz

[8]ページ先頭

©2009-2025 Movatter.jp