[Translation] [FrameworkBundle] Translation: Optimized loading (lazy loading) of domains #2570

wants to merge 2 commits into


None yet

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes (tests updated)
Fixes the following tickets: -

Website can have hundreds of messages in each domain. Some domains (and their translations) are not used during different requests (for example "admin" domain and their messages will not be used on public pages, "validation" domain will not be used until validating some entities/processing forms). This PR changes the way how messages are cached. Instead of storing all domains in one file (catalogue.en.php), domains are saved separately (/en/messages.php, /en/validators.php, etc.) and they are processing and loaded into memory only when they are required (to translate some text). This will optimize memory usage.

@fabpot fabpot and 1 other commented on an outdated diff Nov 23, 2011
@@ -41,6 +41,16 @@ interface MessageCatalogueInterface
function getDomains();
+ * Checks if catalogue has a given domain.
+ *
+ * @param string $domain
+ *
+ * @return Boolean
+ *
+ */
+ public function hasDomain($domain);
fabpot Nov 23, 2011

We cannot add this method to this interface as it is marked with an @api tag.

@Tobion Tobion and 1 other commented on an outdated diff Jan 3, 2012
- $cache = new ConfigCache($this->options['cache_dir'].'/catalogue.'.$locale.'.php', $this->options['debug']);
+ $s = 'test';
Symfony member

@pulzarraider is this PR still valid ? If yes, please rebase your branch. It conflicts with master because of the move of the tests. If no, please close it


@stof Yes, it's valid. I will update it in the next few days.

pulzarraider added some commits Nov 5, 2011
@pulzarraider pulzarraider Translation domain loading memory optimalisation
Fixing CS

Fixing CS

Minor optimalisation

updated unit tests for new dumpers

resolve conflict with @api tags

fix CS

Translation domain loading memory optimalisation

removed unused variable

fixed conflict
@pulzarraider pulzarraider CS fix fb137f2

@stof Rebase done, conflicts fixed.


@stof / @fabpot , please, merge this PR

Symfony member

@Koc only @fabpot merges pull requests. Other core devs are only allowed to review them (even if github would let us push the button to merge them as there is no difference between the write access to the repo and the right to manage the issue tracker and to get notifications)


Any new on this?

Symfony member

@fabpot should this PR be updated to be merged into 2.2 or do you think it should be rejected and closed ?


I've been using the Translation component separately with Silex, so no integrated caching at all.

My solution was to create a CachedLoader wrapper. I'm not familiar with the inner workings of Symfony, but maybe that could work here as well? It would definitely be an improvement to the standalone translation component at least.

Symfony member

I'm not convinced that this has a real performance impact. It would help if we had some simple benchmarks.


@fabpot The performance and memory consumption will depend on the number of translations in those domains, that are not used in a request. If the number of translations is small, it's OK to let them together in one file, because effect on performance is negligible and searching+loading+compiling+executing file costs something, too. But it will change if there exist hundreds or thousands of translations in different domains.

For example, I find completely unnecessary to automatically load translations of admin domain and store them in memory because I know that they won't be used in frontend request (public webpage). They will be used only in backend request (admin section). It's waste of resources.

Maybe we can make compromise solution and let small domains to be cached together in one file (to avoid existence of many small files in cache) and bigger domains store in cache separately (each domain in one file). This will not help webpage with many translations wrapped into a lot of domains, but I think that such cases are not frequent.

Anyway, I will update this PR for latest Symfony version and create some benchmarks in the next recent days with different number of translations to be sure my PR will not slow down the framework.


@pulzarraider Can you continue work on the PR, please?


@Koc I am a bit busy atm, but I will continue working on this PR.

Symfony member
Symfony member

one more ping @pulzarraider ;)

Symfony member

ping again @pulzarraider


I will continue working on this PR next week.

@Tobion Tobion referenced this pull request Feb 13, 2015

Translator performance #13676


A configurable threshold for merging smaller domains together would be great.

@aitboudad aitboudad referenced this pull request Mar 26, 2015

[2.7][Translation] added message cache. #13986

2 of 2 tasks complete

@aitboudad what do you think of this one?


OK you're on it, I just read the linked PR :)

Symfony member


@fabpot fabpot closed this Jan 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment