summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortg(x) <*@tg-x.net>2017-01-19 18:54:35 +0100
committertg(x) <*@tg-x.net>2017-01-19 18:54:35 +0100
commit856556bb33ed4bd881f9ed866696fc6c1e5af37f (patch)
treefac07dc0f2aff98a19a0dd587e0a1c134efab3a3
parentbade9dae384032a974dedc496ad44595072d99d9 (diff)
i18n: generate HTML files from templates for each language
-rw-r--r--Makefile7
-rwxr-xr-xtemplate.py29
-rwxr-xr-xtemplate.sh9
3 files changed, 43 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index b9a72a9a..84bf8218 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-all: locale
- cd web-common && tsc taler-wallet-lib.ts && cd ..
+all: template
+ cd web-common && tsc taler-wallet-lib.ts
locale/messages.pot: *.j2 common/*.j2
pybabel extract -F locale/babel.map -o locale/messages.pot .
@@ -19,3 +19,6 @@ locale-compile: locale-update
pybabel compile -d locale -l es --use-fuzzy
locale: locale-compile
+
+template: locale
+ ./template.sh
diff --git a/template.py b/template.py
new file mode 100755
index 00000000..86516bb6
--- /dev/null
+++ b/template.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import gettext
+import jinja2
+
+if len(sys.argv) < 3:
+ sys.exit("Usage: " + __file__ + " <template-file> <locale> <output-file>")
+
+in_file = sys.argv[1]
+locale = sys.argv[2]
+out_file = sys.argv[3]
+
+tr = gettext.translation("messages",
+ localedir="locale",
+ languages=[locale])
+
+env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
+ extensions=["jinja2.ext.i18n"],
+ autoescape=False)
+env.install_gettext_translations(tr, newstyle=True)
+
+tmpl = env.get_template(in_file)
+
+import codecs
+f = codecs.open(out_file, "w", "utf-8")
+f.write(tmpl.render())
+f.close()
diff --git a/template.sh b/template.sh
new file mode 100755
index 00000000..4d498c71
--- /dev/null
+++ b/template.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+for f in $(git ls-files *.j2 common/*.j2); do
+ for ld in locale/*/; do
+ l=$(basename $ld)
+ echo "$f: $l"
+ python template.py $f $l $(basename $f .html.j2).$l.html
+ done
+done