aboutsummaryrefslogtreecommitdiff
path: root/template.py
blob: aab6fddda37765e2cb5428f60dbb0ac473d6fde2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/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)

def url(x):
    # TODO: look at the app root environment variable
    # TODO: check if file exists
    return x

import codecs
f = codecs.open(out_file, "w", "utf-8")
f.write(tmpl.render(lang=locale, url=url))
f.close()