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');
}
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.
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.