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.
This commit is contained in:
parent
8dd918f2a4
commit
90db2b4c5c
|
@ -23,9 +23,11 @@ from deluge.common import path_join, utf8_encoded
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Dummy tranlation dict so Torrent states text is available for Translators
|
||||
# All entries in deluge.common.TORRENT_STATE should be here. It does not need importing
|
||||
# as the string matches the translation text so using the _() function is enough.
|
||||
# Dummy translation dicts so Torrent and Tracker states are available for Translators.
|
||||
#
|
||||
# All entries in deluge.common.TORRENT_STATE should be added here.
|
||||
#
|
||||
# No need to import these, just simply use the `_()` function around a status variable.
|
||||
def _(message):
|
||||
return message
|
||||
STATE_TRANSLATION = {
|
||||
|
|
|
@ -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
|
||||
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())
|
||||
|
||||
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()
|
||||
print "Created %s" % OUTPUT_FILE
|
||||
|
|
|
@ -24,18 +24,19 @@ EXCLUSIONS = [
|
|||
"deluge/i18n",
|
||||
"deluge/tests",
|
||||
]
|
||||
webui_js_dir = "deluge/ui/web/js/deluge-all"
|
||||
infiles_list = "infiles.list"
|
||||
pot_filepath = os.path.join("deluge", "i18n", "deluge.pot")
|
||||
WEBUI_JS_DIR = "deluge/ui/web/js/deluge-all"
|
||||
WEBUI_RENDER_DIR = "deluge/ui/web/render"
|
||||
INFILES_LIST = "infiles.list"
|
||||
POT_FILEPATH = os.path.join("deluge", "i18n", "deluge.pot")
|
||||
|
||||
re_exc_plugin_build = re.compile("deluge\/plugins\/.*\/build")
|
||||
RE_EXC_PLUGIN_BUILD = re.compile("deluge\/plugins\/.*\/build")
|
||||
|
||||
xgettext_cmd = [
|
||||
"xgettext",
|
||||
"--from-code=UTF-8",
|
||||
"-kN_:1",
|
||||
"-f%s" % infiles_list,
|
||||
"-o%s" % pot_filepath,
|
||||
"-f%s" % INFILES_LIST,
|
||||
"-o%s" % POT_FILEPATH,
|
||||
"--package-name=%s" % "Deluge",
|
||||
"--copyright-holder=%s" % "Deluge Team",
|
||||
"--package-version=%s" % get_version(prefix='deluge-', suffix='.dev0'),
|
||||
|
@ -45,7 +46,7 @@ xgettext_cmd = [
|
|||
to_translate = []
|
||||
for (dirpath, dirnames, filenames) in os.walk("deluge"):
|
||||
for filename in filenames:
|
||||
if dirpath not in EXCLUSIONS and not re_exc_plugin_build.match(dirpath):
|
||||
if dirpath not in EXCLUSIONS and not RE_EXC_PLUGIN_BUILD.match(dirpath):
|
||||
filepath = os.path.join(dirpath, filename)
|
||||
if os.path.splitext(filepath)[1] in (".py", ".glade"):
|
||||
to_translate.append(filepath)
|
||||
|
@ -56,7 +57,7 @@ for (dirpath, dirnames, filenames) in os.walk("deluge"):
|
|||
call(["intltool-extract", "--quiet", "--type=gettext/glade", filepath])
|
||||
to_translate.append(filepath + ".h")
|
||||
|
||||
with open(infiles_list, "wb") as f:
|
||||
with open(INFILES_LIST, "wb") as f:
|
||||
for line in to_translate:
|
||||
f.write(line + "\n")
|
||||
|
||||
|
@ -65,24 +66,30 @@ call(xgettext_cmd)
|
|||
|
||||
# find javascript files
|
||||
js_to_translate = []
|
||||
for (dirpath, dirnames, filenames) in os.walk(webui_js_dir):
|
||||
for (dirpath, dirnames, filenames) in os.walk(WEBUI_JS_DIR):
|
||||
for filename in filenames:
|
||||
if os.path.splitext(filename)[1] == ".js":
|
||||
js_to_translate.append(os.path.join(dirpath, filename))
|
||||
|
||||
with open(infiles_list, "wb") as f:
|
||||
# find render html files
|
||||
for (dirpath, dirnames, filenames) in os.walk(WEBUI_RENDER_DIR):
|
||||
for filename in filenames:
|
||||
if os.path.splitext(filename)[1] == ".html":
|
||||
js_to_translate.append(os.path.join(dirpath, filename))
|
||||
|
||||
with open(INFILES_LIST, "wb") as f:
|
||||
for line in js_to_translate:
|
||||
f.write(line + "\n")
|
||||
|
||||
# Force xgettext language to parse javascript and update pot file
|
||||
# Note: For javascript files xgettext will parse comments, so single apostrophes or quotes are
|
||||
# flagged as a 'warning: untermined string'. Either ignore warning or edit javascript comment.
|
||||
output = call(xgettext_cmd + ["--language=Python", "-j"])
|
||||
call(xgettext_cmd + ["--language=Python", "-j"])
|
||||
|
||||
# Replace YEAR and PACKAGE in the copyright message
|
||||
with open(pot_filepath, "r") as f:
|
||||
with open(POT_FILEPATH, "r") as f:
|
||||
lines = f.readlines()
|
||||
with open(pot_filepath, "w") as f:
|
||||
with open(POT_FILEPATH, "w") as f:
|
||||
for line in lines:
|
||||
if "YEAR" in line:
|
||||
line = line.replace("YEAR", str(datetime.now().year))
|
||||
|
@ -91,9 +98,9 @@ with open(pot_filepath, "w") as f:
|
|||
f.write(line)
|
||||
|
||||
# Clean up temp files
|
||||
os.remove(infiles_list)
|
||||
os.remove(INFILES_LIST)
|
||||
for filepath in to_translate:
|
||||
if filepath.endswith(".h"):
|
||||
os.remove(filepath)
|
||||
|
||||
print "Created %s" % pot_filepath
|
||||
print "Created %s" % POT_FILEPATH
|
||||
|
|
Loading…
Reference in New Issue