summaryrefslogtreecommitdiff
path: root/template.py
diff options
context:
space:
mode:
Diffstat (limited to 'template.py')
-rwxr-xr-xtemplate.py29
1 files changed, 29 insertions, 0 deletions
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()