diff --git a/util/mod_translation_updater.py b/util/mod_translation_updater.py old mode 100644 new mode 100755 index a6b3286b3..b2feaaf15 --- a/util/mod_translation_updater.py +++ b/util/mod_translation_updater.py @@ -8,7 +8,6 @@ # 2023 Wuzzy. # License: LGPLv2.1 or later (see LICENSE file for details) -from __future__ import print_function import os, fnmatch, re, shutil, errno from sys import argv as _argv from sys import stderr as _stderr @@ -121,17 +120,43 @@ def main(): # Group 2 will be the string, groups 1 and 3 will be the delimiters (" or ') # See https://stackoverflow.com/questions/46967465/regex-match-text-in-either-single-or-double-quote -pattern_lua_quoted = re.compile(r'[\.=^\t,{\(\s]N?F?S\s*\(\s*(["\'])((?:\\\1|(?:(?!\1)).)*)(\1)[\s,\)]', re.DOTALL) +pattern_lua_quoted = re.compile( + r'(?:^|[\.=,{\(\s])' # Look for beginning of file or anything that isn't a function identifier + r'N?F?S\s*\(\s*' # Matches S, FS, NS or NFS function call + r'(["\'])((?:\\\1|(?:(?!\1)).)*)(\1)' # Quoted string + r'[\s,\)]', # End of call or argument + re.DOTALL) # Handles the [[ ... ]] string delimiters -pattern_lua_bracketed = re.compile(r'[\.=^\t,{\(\s]N?F?S\s*\(\s*\[\[(.*?)\]\][\s,\)]', re.DOTALL) +pattern_lua_bracketed = re.compile( + r'(?:^|[\.=,{\(\s])' # Same as for pattern_lua_quoted + r'N?F?S\s*\(\s*' # Same as for pattern_lua_quoted + r'\[\[(.*?)\]\]' # [[ ... ]] string delimiters + r'[\s,\)]', # Same as for pattern_lua_quoted + re.DOTALL) # Handles "concatenation" .. " of strings" pattern_concat = re.compile(r'["\'][\s]*\.\.[\s]*["\']', re.DOTALL) -pattern_tr = re.compile(r'(.*?[^@])=(.*)') +# Handles a translation line in *.tr file. +# Group 1 is the source string left of the equals sign. +# Group 2 is the translated string, right of the equals sign. +pattern_tr = re.compile( + r'(.*)' # Source string + # the separating equals sign, if NOT preceded by @, unless + # that @ is preceded by another @ + r'(?:(?