lajax / yii2-translate-manager

Translation Manager
MIT License
227 stars 89 forks source link

Javascript translation not being found by scan #133

Open krissce opened 4 years ago

krissce commented 4 years ago

Hi there, I've spent hours tracing odd issue where Scan function was not finding lajax.t() translations in my js code. After long time I narrowed it to this js code:

function x(str, attribute) { str = str.replace(/style="/gi, 'style="' + attribute + ': ' + ';');
str = str.replace(new RegExp(attribute + '="[^<>"]*"', "gi"), ''); //translation below will not be found by scanner! lajax.t('testing'); }

What this method does does not matter now, because it was just extracted from whole function code, but this just code is valid. Anyway, after debugging I found out that token_get_all was failing to match tokens properly. This is the line from code: https://github.com/lajax/yii2-translate-manager/blob/218f41bf6cdcd455cb188c8bfdbcde71b1dc7ca1/services/scanners/ScannerFile.php#L173

If you try code I've pasted above Scan will not add new string translation called 'testing'. If you remove first line from this function, that is: str = str.replace(/style="/gi, 'style="' + attribute + ': ' + ';'); - then Scan will find 'testing' string for translation.

Anyway, this is just in case someone was not sure why translation is not being found.