summaryrefslogtreecommitdiffstats
path: root/pavement.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-08-10 11:59:53 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-08-10 11:59:53 +0200
commit6bb376d57d4a5f8ed0e54039ffefa94ea5e61baf (patch)
treef2e665e15c7d169205f56dc88f4849cfffcb489a /pavement.py
parentnew account page layout, added translations for webui (diff)
downloadpyload-6bb376d57d4a5f8ed0e54039ffefa94ea5e61baf.tar.xz
parse string from template files, added some translations for webu
Diffstat (limited to 'pavement.py')
-rw-r--r--pavement.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/pavement.py b/pavement.py
index ff9e61a9c..d168f23bb 100644
--- a/pavement.py
+++ b/pavement.py
@@ -152,6 +152,8 @@ def generate_locale():
makepot("webUI", path("pyload") / "web" / "app", ["components", "vendor", "gettext"], endings=[".js", ".html"],
xxargs="--language=Python --force-po".split(" "))
+ makehtml("webUI", path("pyload") / "web" / "app" / "templates")
+
path("includes.txt").remove()
print "Locale generated"
@@ -332,3 +334,63 @@ def makepot(domain, p, excludes=[], includes="", endings=[".py"], xxargs=[]):
with open("locale/%s.pot" % domain, "wb") as f:
f.write(content)
+
+def makehtml(domain, p):
+ """ Parses entries from html and append them to existing pot file"""
+
+ pot = path("locale") / "%s.pot" % domain
+
+ with open(pot, 'rb') as f:
+ content = f.readlines()
+
+ msgids = {}
+ # parse existing ids and line
+ for i, line in enumerate(content):
+ if line.startswith("msgid "):
+ msgid = line[6:-1].strip('"')
+ msgids[msgid] = i
+
+ # TODO: parses only n=2 plural
+ single = re.compile(r'\{\{ ?(?:gettext|_) "((?:\\.|[^"\\])*)" ?\}\}')
+ plural = re.compile(r'\{\{ ?(?:ngettext) *"((?:\\.|[^"\\])*)" *"((?:\\.|[^"\\])*)"')
+
+ for f in p.walkfiles():
+ if not f.endswith("html"): continue
+ with open(f, "rb") as html:
+ for i, line in enumerate(html.readlines()):
+ key = None
+ nmessage = plural.search(line)
+ message = single.search(line)
+ if nmessage:
+ key = nmessage.group(1)
+ keyp = nmessage.group(2)
+
+ if key not in msgids:
+ content.append("\n")
+ content.append('msgid "%s"\n' % key)
+ content.append('msgid_plural "%s"\n' % keyp)
+ content.append('msgstr[0] ""\n')
+ content.append('msgstr[1] ""\n')
+ msgids[key] = len(content) - 4
+
+
+ elif message:
+ key = message.group(1)
+
+ if key not in msgids:
+ content.append("\n")
+ content.append('msgid "%s"\n' % key)
+ content.append('msgstr ""\n')
+ msgids[key] = len(content) - 2
+
+ if key:
+ content.insert(msgids[key], "#: %s:%d\n" % (f, i))
+ msgids[key] += 1
+
+
+ with open(pot, 'wb') as f:
+ f.writelines(content)
+
+ print "Parsed html files"
+
+