diff options
author | tg(x) <*@tg-x.net> | 2017-01-19 18:54:35 +0100 |
---|---|---|
committer | tg(x) <*@tg-x.net> | 2017-01-19 18:54:35 +0100 |
commit | 856556bb33ed4bd881f9ed866696fc6c1e5af37f (patch) | |
tree | fac07dc0f2aff98a19a0dd587e0a1c134efab3a3 | |
parent | bade9dae384032a974dedc496ad44595072d99d9 (diff) | |
download | www-856556bb33ed4bd881f9ed866696fc6c1e5af37f.tar.gz www-856556bb33ed4bd881f9ed866696fc6c1e5af37f.zip |
i18n: generate HTML files from templates for each language
-rw-r--r-- | Makefile | 7 | ||||
-rwxr-xr-x | template.py | 29 | ||||
-rwxr-xr-x | template.sh | 9 |
3 files changed, 43 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | all: locale | 1 | all: template |
2 | cd web-common && tsc taler-wallet-lib.ts && cd .. | 2 | cd web-common && tsc taler-wallet-lib.ts |
3 | 3 | ||
4 | locale/messages.pot: *.j2 common/*.j2 | 4 | locale/messages.pot: *.j2 common/*.j2 |
5 | pybabel extract -F locale/babel.map -o locale/messages.pot . | 5 | pybabel extract -F locale/babel.map -o locale/messages.pot . |
@@ -19,3 +19,6 @@ locale-compile: locale-update | |||
19 | pybabel compile -d locale -l es --use-fuzzy | 19 | pybabel compile -d locale -l es --use-fuzzy |
20 | 20 | ||
21 | locale: locale-compile | 21 | locale: locale-compile |
22 | |||
23 | template: locale | ||
24 | ./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 @@ | |||
1 | #!/usr/bin/env python | ||
2 | |||
3 | import os | ||
4 | import sys | ||
5 | import gettext | ||
6 | import jinja2 | ||
7 | |||
8 | if len(sys.argv) < 3: | ||
9 | sys.exit("Usage: " + __file__ + " <template-file> <locale> <output-file>") | ||
10 | |||
11 | in_file = sys.argv[1] | ||
12 | locale = sys.argv[2] | ||
13 | out_file = sys.argv[3] | ||
14 | |||
15 | tr = gettext.translation("messages", | ||
16 | localedir="locale", | ||
17 | languages=[locale]) | ||
18 | |||
19 | env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), | ||
20 | extensions=["jinja2.ext.i18n"], | ||
21 | autoescape=False) | ||
22 | env.install_gettext_translations(tr, newstyle=True) | ||
23 | |||
24 | tmpl = env.get_template(in_file) | ||
25 | |||
26 | import codecs | ||
27 | f = codecs.open(out_file, "w", "utf-8") | ||
28 | f.write(tmpl.render()) | ||
29 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | for f in $(git ls-files *.j2 common/*.j2); do | ||
4 | for ld in locale/*/; do | ||
5 | l=$(basename $ld) | ||
6 | echo "$f: $l" | ||
7 | python template.py $f $l $(basename $f .html.j2).$l.html | ||
8 | done | ||
9 | done | ||