lajax / yii2-translate-manager

Translation Manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Javascript translation not being found by scan

krissce opened this issue · comments

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:

$tokens = token_get_all($subject);

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.