-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS Translation Regex leads to unexpected results and untranslatable strings #7403
Comments
@thlassche thank you for your report. |
@veloraven 2.1.2 |
This is the faulty regex: It is defined here: https://github.com/magento/magento2/blob/develop/app/code/Magento/Translation/etc/di.xml#L63
It is also the root cause of #5509, #5820 and #9967, which are basically strings concatenated using Another case where this check fails is if |
Internal ticket to track issue progress: MAGETWO-71380 |
I am seeing this problem too and trying out #10445 does not seem to fix it entirely. I am getting an error when compiling static files, core file i18n.js:
..see this regex101 paste for an example of a core file being messed up by this bug As an aside this might also be the root cause of #5967 (MAGETWO-70599 apparently) |
@thlassche, thank you for your report. |
Hi is there a plan to fix it in 2.2.x? |
To add some more info to this ticket, because it is a long time ago since there was some activity here. This problem was fixed in Magento 2.2.1 by commit: 27149cb I've now just created a backport of these fixes for Magento 2.1 over here: #14349 |
Hi @thlassche. Thank you for your report. The fix will be available with the upcoming 2.1.14 release. |
…ding-standard AC-2080: Release magento-coding-standard
Preconditions
Magento version: 2.1.2
Translate a string in javascript, for example like this (taken from
mage/validation.js
):The string should be for example concatted in JavaScript with the
+
sine.Steps to reproduce
Look up the page where the translated string should appear (in this case: the register account page)
Expected result
The password error message is translated
Actual result
The password error message is not translated
Cause
The root cause of this, is the regex that selects JS strings for translation, as found in:
/app/code/Magento/Translation/etc/di.xml
. It's is very buggy and not fail safe. It skips every string that is not strictly formatted according to this regex. In this case the '+' sign causes the string to be skipped by the regex, but there are many more cases where this regex is skipped in JS files (e.g. iteration over parts of strings to translate them). See:magento2/app/code/Magento/Translation/etc/di.xml
Lines 60 to 62 in 0be91a5
Looks like the implementation of the
js-translation.json
file should be a bit refactored.Workaround
A workaround I use in production is to create a JS file which calls the
$.mage.__()
with the string that I would like to translate, e.g.:The text was updated successfully, but these errors were encountered: