Made sure all translatable strings in the code are evaluated the same way PHP evaluates them when running the code. That includes all sorts of escape sequences, which may or may not differ based on whether you're using single or double quotes. Edit: Sadly, this caused Codacy to complain over the use of the eval function, but doing this in any other way would likely require a serious overhaul of the way the strings are parsed. Edit 2: Avoided using eval by using stripcslashes for double quoted strings, and simply replacing escaped single quotes and backslashes otherwise, which should mimic the behavior of PHP exactly.
Previously, when a string included a closing parenthesis, the parser would count it as the ending parenthesis of the translation function, which would break the detection of the string (usually resulting in a truncated result, or even no detection at all in certain cases). I refactored the parsing function to account for such cases properly.
Added JSON_UNESCAPED_UNICODE flag to the json_encode() function call when writing the translations file. This avoids ugly escape sequences in the results as well as the case where existing keys were not found due to previously escaped unicode characters being present in the JSON file but unescaped in the actual string used in the translation function call.
A minor one, but spaces before and after the opening parentheses of the translation function calls are also now supported.
I have made a few more improvements to the code:
eval
function, but doing this in any other way would likely require a serious overhaul of the way the strings are parsed. Edit 2: Avoided usingeval
by usingstripcslashes
for double quoted strings, and simply replacing escaped single quotes and backslashes otherwise, which should mimic the behavior of PHP exactly.JSON_UNESCAPED_UNICODE
flag to thejson_encode()
function call when writing the translations file. This avoids ugly escape sequences in the results as well as the case where existing keys were not found due to previously escaped unicode characters being present in the JSON file but unescaped in the actual string used in the translation function call.