In the "file vendor/magento/module-ui/view/base/web/js/lib/validation/rules.js" in line 433 Magento2 can't translate this sentence. rules.js file of translate But after remove "+" the translation is perfect.

How I can translate correct without rewrite "rules.js"?

1 Answer 1


Translation behavior depends on strategy set in Stores -> Configuration -> Advanced -> Developer -> JavaScript Setting -> Translation Strategy.

Take a look at full explanation here: What is the Translation Strategy

However, both strategies rely on regex pattern for replacing/collecting translatable strings. So the problem here is that string does not match the pattern.

So the only solution I see, without overriding rules.js, is to add the pattern for gathering translation files. You can do it from your module's di.xml like:

<type name="Magento\Translation\Model\Js\Config">
        <argument name="patterns" xsi:type="array">
            <item name="custom_pattern" xsi:type="string">~regex-pattern~</item>

See existing patterns here: https://github.com/magento/magento2/blob/develop/app/code/Magento/Translation/etc/di.xml#L63

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.