Can anyone please shed some light on the js-translation.json and where it pulls the phrases in from?

We have a Spanish store view and we have 934 phrases translated in our app/i18n/vendor/es_es/es_ES.csv language package.

We also have custom modules, some of which include translations in their app/code/Vendor/ModuleName/i18n/es_ES.csv

After setup:static-content:deploy es_ES (and all caches cleared etc etc) the js-translation.json file generates and IS populated but it only contains 194 phrases, some of which are specifically from custom modules, some of which are from the main language package.

If a phrase is included in the js-translation.json which has come from a custom module I would expect all phrases from that custom module would be included, but this is not the case.

I would also expect that if the js-translation.json contains phrases from the main language package then it would contain them all, which is not the case.

I can confirm that ALL translations are actually working on the frontend but my question is why are only some translations included in the js-translation.json and not all?

Thanks in advance for any light you can shed on this!

1 Answer 1


Turns out that only phrases rendered in javascript or html templates are included in the js-translation.json.

If you look in vendor/magento/module-translation/etc/di.xml you will see the regex which retrieves these:

<type name="Magento\Translation\Model\Js\Config">
        <argument name="patterns" xsi:type="array">
            <item name="i18n_translation" xsi:type="string"><![CDATA[~i18n\:\s*(["'])(.*?)(?<!\\)\1~]]></item>
            <item name="translate_wrapping" xsi:type="string"><![CDATA[~translate\=("')([^\'].*?)\'\"~]]></item>
            <item name="mage_translation_widget" xsi:type="string"><![CDATA[~(?:\$|jQuery)\.mage\.__\((?s)[^'"]*?(['"])(.+?)(?<!\\)\1(?s).*?\)~]]></item>
            <item name="mage_translation_static" xsi:type="string"><![CDATA[~\$t\((?s)[^'"]*?(["'])(.+?)\1(?s).*?\)~]]></item>

Thanks to Vinai Kopp!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.