summaryrefslogtreecommitdiffstats
path: root/gen_web_gettext.py
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2017-03-21 22:05:54 +0000
committerCalum Lind <calumlind+deluge@gmail.com>2017-03-21 22:05:54 +0000
commitf32c8aff90aaed559a1312fbbcc581727e12e46d (patch)
treee3a7227ff3dd79fa0644073682438384585e7b3d /gen_web_gettext.py
parent9aed7a7f0c0fad818f55cc94ed3a706a199b6eb6 (diff)
downloaddeluge-f32c8aff90aaed559a1312fbbcc581727e12e46d.tar.gz
deluge-f32c8aff90aaed559a1312fbbcc581727e12e46d.tar.bz2
deluge-f32c8aff90aaed559a1312fbbcc581727e12e46d.zip
Minor gettext script improvements
Diffstat (limited to 'gen_web_gettext.py')
-rwxr-xr-xgen_web_gettext.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/gen_web_gettext.py b/gen_web_gettext.py
index fb97228c9..a4f18049c 100755
--- a/gen_web_gettext.py
+++ b/gen_web_gettext.py
@@ -66,32 +66,34 @@ def check_missing_markup(js_dir):
return strings
+GETTEXT_TPL = (
+ 'GetText={maps:{},'
+ 'add:function(string,translation){this.maps[string]=translation},'
+ 'get:function(string){if (this.maps[string]){string=this.maps[string]} return string}};'
+ 'function _(string){return GetText.get(string)}')
+
+
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},'
- 'get:function(string){if (this.maps[string]){string=this.maps[string]} return string}};'
- 'function _(string){return GetText.get(string)}')
+ if filename.endswith('.js'):
+ filepath = os.path.join(root, filename)
+ with open(os.path.join(root, filename)) as _file:
+ for lineno, line in enumerate(_file, 1):
+ for match in string_re.finditer(line):
+ string = match.group(1)
+ locations = strings.get(string, [])
+ locations.append((filepath, lineno))
+ strings[string] = locations
gettext_file = os.path.join(os.path.dirname(js_dir), 'gettext.js')
with open(gettext_file, 'w') as fp:
- fp.write(gettext_tpl)
+ fp.write(GETTEXT_TPL)
for key in sorted(strings):
if DEBUG:
- fp.write('\n// %s\n' % ', '.join(['%s:%s' % x for x in strings[key]]))
+ fp.write('\n//: %s' % '//: '.join(['%s:%s\n' % x for x in strings[key]]))
fp.write('''GetText.add('%(key)s','${escape(_("%(key)s"))}')\n''' % locals())
return gettext_file