diff options
author | Calum Lind <calumlind+deluge@gmail.com> | 2014-02-20 17:24:11 +0000 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2014-02-20 17:38:51 +0000 |
commit | 9290cc1f7a49edcd121ec961dbbaec873c143af6 (patch) | |
tree | 528bbbaa0a3eb8c4c55c8f4ea190a6fc52edcf66 /gen_web_gettext.py | |
parent | c64da3ceb4a1312efde6cfbb39c9ab0309ce8acd (diff) | |
download | deluge-9290cc1f7a49edcd121ec961dbbaec873c143af6.tar.gz deluge-9290cc1f7a49edcd121ec961dbbaec873c143af6.tar.bz2 deluge-9290cc1f7a49edcd121ec961dbbaec873c143af6.zip |
Fix building the code documentation with sphinx
Updated Sphinx conf and tested with Sphinx 1.2.1
Moved webui gen_gettext script
Fixed docstring warning in code
Renamed console update-tracker to update_tracker
Diffstat (limited to 'gen_web_gettext.py')
-rwxr-xr-x | gen_web_gettext.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/gen_web_gettext.py b/gen_web_gettext.py new file mode 100755 index 000000000..49730dba5 --- /dev/null +++ b/gen_web_gettext.py @@ -0,0 +1,66 @@ +#!/usr/bin/python +""" +Script to go through the javascript files and dynamically generate gettext.js +""" +import os +import re + +output_file = "js/gettext.js" +string_re = re.compile('_\\(\'(.*?)\'\\)') +strings = {} + + +gettext_tpl = """## -*- coding: utf-8 -*- +/* + * Script: gettext.js + * 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> + */ + +GetText = { + maps: {}, + add: function(string, translation) { + this.maps[string] = translation; + }, + get: function(string) { + if (this.maps[string]) { + return this.maps[string]; + } else { + return string; + } + } +} + +function _(string) { + return GetText.get(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() + +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() |