diff options
author | Calum Lind <calumlind+deluge@gmail.com> | 2016-05-11 23:36:42 +0200 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2016-05-14 12:16:28 +0200 |
commit | bf8f71f215f6eb860e13a981e85f1c617593f35d (patch) | |
tree | 979ad5036fc825b6ffe5f1962917287345ce47bc /gen_web_gettext.py | |
parent | [WebUI] Add missing translation markup (diff) | |
download | deluge-bf8f71f215f6eb860e13a981e85f1c617593f35d.tar.xz deluge-bf8f71f215f6eb860e13a981e85f1c617593f35d.zip |
[WebUI] Update gettext script to find any missed marked-up text
Added a new function to the gettext script that will check common
extjs attributes for missing markup text strings and print the result.
Diffstat (limited to 'gen_web_gettext.py')
-rwxr-xr-x | gen_web_gettext.py | 66 |
1 files changed, 59 insertions, 7 deletions
diff --git a/gen_web_gettext.py b/gen_web_gettext.py index b9c1c734c..519edf7bd 100755 --- a/gen_web_gettext.py +++ b/gen_web_gettext.py @@ -20,19 +20,65 @@ WEBUI_JS_DIR = 'deluge/ui/web/js/deluge-all' DEBUG = False -def create_gettext_js(js_dir): - string_re = re.compile('_\\(\'(.*?)\'\\)') +def check_missing_markup(js_dir): + """Search js to check for missed translation markup.""" + + # A list of common extjs attributes that are usually marked for translation. + attr_list = [ + "text: '", + "msg: '", + "title: '", + "fieldLabel: '", + "boxLabel: '", + "tooltip: '", + "header: '", + "defaultText: '", + "unit: '", + r"setText\('", + r"addButton\('", + ] + + # Don't match against any of these chars at start of string value. + except_chars = "' &#" + + # A list of strings that should be skipped shuold the match contain them. + skip = ["HTTP:"] + + # Create a list of the matching strings to search for with the except_chars appended to each one. + string_re = re.compile( + "(" + ")|(".join(["%s[^" + except_chars + "].*'"]*len(attr_list)) % tuple(attr_list) + ")" + ) strings = {} for root, dnames, files in os.walk(js_dir): for filename in files: - if os.path.splitext(filename)[1] == '.js': - for lineno, line in enumerate(open(os.path.join(root, filename))): - for match in string_re.finditer(line): - string = match.group(1) + if os.path.splitext(filename)[1] != '.js': + continue + for lineno, line in enumerate(open(os.path.join(root, filename))): + for match in string_re.finditer(line): + for string in match.groups(): + # Ignore string that contains only digits or specificied strings in skip. + if not string or string.split("'")[1].isdigit() or any(x in string for x in skip): + continue locations = strings.get(string, []) - locations.append((os.path.basename(filename), lineno + 1)) + locations.append((os.path.join(root, filename), str(lineno + 1))) strings[string] = locations + return strings + + +def create_gettext_js(js_dir): + string_re = re.compile('_\\(\'(.*?)\'\\)') + strings = {} + for root, dnames, files in os.walk(js_dir): + for filename in files: + if os.path.splitext(filename)[1] != '.js': + continue + for lineno, line in enumerate(open(os.path.join(root, filename))): + for match in string_re.finditer(line): + string = match.group(1) + locations = strings.get(string, []) + locations.append((os.path.basename(filename), lineno + 1)) + strings[string] = locations gettext_tpl = '''GetText={maps:{},\ add:function(string,translation) {this.maps[string]=translation},\ @@ -52,3 +98,9 @@ def create_gettext_js(js_dir): if __name__ == '__main__': gettext_fname = create_gettext_js(WEBUI_JS_DIR) print("Created '%s'" % gettext_fname) + missed_markup = check_missing_markup(WEBUI_JS_DIR) + if missed_markup: + print("Possible missed text for translation markup:") + for text, filenames in missed_markup.iteritems(): + for filename_lineno in filenames: + print("{0:<58} {1}".format(':'.join(filename_lineno), text)) |