summaryrefslogtreecommitdiffstats
path: root/gen_web_gettext.py
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2015-08-20 19:51:09 +0200
committerCalum Lind <calumlind+deluge@gmail.com>2015-08-20 19:51:09 +0200
commit90db2b4c5c01e526fbdc6a0ba74c239f0c937660 (patch)
tree55d906fc2fc1e91613342f04a3f918f5040398f0 /gen_web_gettext.py
parent[WebUI] Fix i18n issue in Connection Manager (diff)
downloaddeluge-90db2b4c5c01e526fbdc6a0ba74c239f0c937660.tar.xz
deluge-90db2b4c5c01e526fbdc6a0ba74c239f0c937660.zip
Minor updates to the translation scripts
* General cleanup of code. * Add commandline folder option to js gettext script. * Include webui render html files to pot template creation.
Diffstat (limited to 'gen_web_gettext.py')
-rwxr-xr-xgen_web_gettext.py60
1 files changed, 29 insertions, 31 deletions
diff --git a/gen_web_gettext.py b/gen_web_gettext.py
index 9b6126492..c591b01ad 100755
--- a/gen_web_gettext.py
+++ b/gen_web_gettext.py
@@ -12,20 +12,35 @@
import os
import re
+import sys
+
+if len(sys.argv) != 2:
+ WEBUI_JS_DIR = 'deluge/ui/web/js/deluge-all'
+else:
+ WEBUI_JS_DIR = os.path.abspath(sys.argv[1])
+
+OUTPUT_FILE = os.path.join(os.path.dirname(WEBUI_JS_DIR), 'gettext.js')
+STRING_RE = re.compile('_\\(\'(.*?)\'\\)')
-output_file = "js/gettext.js"
-string_re = re.compile('_\\(\'(.*?)\'\\)')
strings = {}
+for root, dnames, files in os.walk(WEBUI_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)
+ locations = strings.get(string, [])
+ locations.append((os.path.basename(filename), lineno + 1))
+ strings[string] = locations
+keys = strings.keys()
+keys.sort()
-gettext_tpl = """## -*- coding: utf-8 -*-
-/*
+gettext_tpl = """/*!
* Script: gettext.js
- * A script file that is run through the template renderer in order for
- * translated strings to be used.
+ * A script file that is run through the template renderer in order for translated strings to be used.
*
- * Copyright:
- * (c) 2009 Damien Churchill <damoxc@gmail.com>
+ * Copyright (c) 2009 Damien Churchill <damoxc@gmail.com>
*/
GetText = {
@@ -48,27 +63,10 @@ function _(string) {
"""
-for root, dnames, files in os.walk('js/deluge-all'):
- for filename in files:
- if filename.startswith('.'):
- continue
- if not filename.endswith('.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
-
-
-keys = strings.keys()
-keys.sort()
+with open(OUTPUT_FILE, 'w') as fp:
+ fp.write(gettext_tpl)
+ for key in keys:
+ fp.write('// %s\n' % ', '.join(map(lambda x: '%s:%s' % x, strings[key])))
+ fp.write("GetText.add('%(key)s', '${escape(_(\"%(key)s\"))}')\n\n" % locals())
-fp = open(output_file, 'w')
-fp.write(gettext_tpl)
-for key in keys:
- fp.write('// %s\n' % ', '.join(map(lambda x: '%s:%s' % x, strings[key])))
- fp.write("GetText.add('%(key)s', '${escape(_(\"%(key)s\"))}')\n\n" % locals())
-fp.close()
+print "Created %s" % OUTPUT_FILE