symfony - Override TranslationsCacheWarmer service -
i have application contains lot of translation resources lot of different languages. warmup process takes long time because of this.
i support translation of site in few languages, i'd avoid generating catalogues languages don't support.
what did:
i overrode translationscachewarmer use own translator. custom translator decorates default translator overrides warmup method warmup files part of locales support.
the problem default warmer still runs generating files locales.
this code contains custom translator: https://gist.github.com/marcosdsanchez/e8e2cd19031a2fbcd894
and here's how i'm defining services:
<service id="web.translation.public_languages_translator" class="x\translation\publiclanguagestranslator" public="false"> <argument type="service" id="translator.default" /> <argument type="collection">%chess.translation.public_languages%</argument> </service> <service id="translation.warmer" class="symfony\bundle\frameworkbundle\cachewarmer\translationscachewarmer" public="false"> <argument type="service" id="web.translation.public_languages_translator" /> <tag name="kernel.cache_warmer" /> </service>
i'm using symfony 2.7.3
i ended doing different same result. instead of trying create custom cachewarmer, created compiler pass , modified definition of 'options' argument. in compiler pass, removed files don't have locale or language code.
code:
<?php namespace x\dependencyinjection\compiler; use x\entity\i18nlanguage; use symfony\component\dependencyinjection\compiler\compilerpassinterface; use symfony\component\dependencyinjection\containerbuilder; class translatorcompilerpass implements compilerpassinterface { /** * can modify container here before dumped php code. * * @param containerbuilder $container * * @api */ public function process(containerbuilder $container) { $definition = $container->getdefinition('translator.default'); $options = $definition->getargument(3); $keys = array_keys($options['resource_files']); $locales = i18nlanguage::public_locales; $langcodes = array(); foreach (i18nlanguage::public_locales $locale) { $langcodes[] = substr($locale, 0, strpos($locale, '_')); } $localesandlangcodes = array_merge($locales, $langcodes); foreach ($keys $key) { if (!in_array($key, $localesandlangcodes, true)) { unset($options['resource_files'][$key]); } } $arguments = $definition->getarguments(); $definition->setarguments(array($arguments[0], $arguments[1], $arguments[2], $options)); } }
that did trick me , can apply other optimizations removal of loaders, etc.
Comments
Post a Comment