diff options
Diffstat (limited to 'template.py')
-rwxr-xr-x | template.py | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/template.py b/template.py index 6d587954..acf79b70 100755 --- a/template.py +++ b/template.py | |||
@@ -7,19 +7,31 @@ | |||
7 | # | 7 | # |
8 | # Note that the gettext files need to be prepared first. This script | 8 | # Note that the gettext files need to be prepared first. This script |
9 | # is thus to be invoked via the Makefile. | 9 | # is thus to be invoked via the Makefile. |
10 | # | ||
11 | # We import unicode_literals until people have understood how unicode | ||
12 | # with bytes and strings changed in python2->python3. | ||
13 | from __future__ import unicode_literals | ||
10 | import os | 14 | import os |
11 | import os.path | 15 | import os.path |
12 | import sys | 16 | import sys |
13 | import re | 17 | import re |
14 | import gettext | 18 | import gettext |
15 | import jinja2 | ||
16 | import glob | 19 | import glob |
17 | import codecs | 20 | import codecs |
18 | import os | 21 | import jinja2 |
19 | sys.path.append(os.getcwd()) | 22 | |
20 | # ImportError: attempted relative import with no known parent package | 23 | # FIXME: lint will complain about this. Do NOT! fix this by writing |
21 | #from . import i18nfix | 24 | # import i18nfix again, send an email to our developer list if you |
22 | import i18nfix | 25 | # have a problem with your system specific python integration! |
26 | # PACKAGE_PARENT = '..' | ||
27 | # SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))) | ||
28 | # sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT))) | ||
29 | # sys.path.append(os.getcwd()) | ||
30 | #from www import i18nfix | ||
31 | try: | ||
32 | from . import i18nfix | ||
33 | except ImportError: | ||
34 | import i18nfix | ||
23 | 35 | ||
24 | env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), | 36 | env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), |
25 | extensions=["jinja2.ext.i18n"], | 37 | extensions=["jinja2.ext.i18n"], |
@@ -27,6 +39,7 @@ env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__ | |||
27 | trim_blocks=True, | 39 | trim_blocks=True, |
28 | undefined=jinja2.StrictUndefined, | 40 | undefined=jinja2.StrictUndefined, |
29 | autoescape=False) | 41 | autoescape=False) |
42 | print(sys.path) | ||
30 | 43 | ||
31 | langs_full = {"en": "English", "fr": "Français", "it": "Italiano", "es": "Español", "de": "Deutsch"} | 44 | langs_full = {"en": "English", "fr": "Français", "it": "Italiano", "es": "Español", "de": "Deutsch"} |
32 | 45 | ||
@@ -45,7 +58,7 @@ for in_file in glob.glob("*.j2"): | |||
45 | 58 | ||
46 | def svg_localized(filename): | 59 | def svg_localized(filename): |
47 | lf = filename + "." + locale + ".svg" | 60 | lf = filename + "." + locale + ".svg" |
48 | if "en" == locale or not os.path.isfile(lf): | 61 | if locale == "en" or not os.path.isfile(lf): |
49 | return "../" + filename + ".svg" | 62 | return "../" + filename + ".svg" |
50 | else: | 63 | else: |
51 | return "../" + lf | 64 | return "../" + lf |
@@ -66,15 +79,14 @@ for in_file in glob.glob("*.j2"): | |||
66 | 79 | ||
67 | env.install_gettext_translations(tr, newstyle=True) | 80 | env.install_gettext_translations(tr, newstyle=True) |
68 | 81 | ||
69 | content = tmpl.render( | 82 | content = tmpl.render(lang=locale, |
70 | lang=locale, | 83 | lang_full=langs_full[locale], |
71 | lang_full=langs_full[locale], | 84 | url=url, |
72 | url=url, | 85 | self_localized=self_localized, |
73 | self_localized=self_localized, | 86 | url_localized=url_localized, |
74 | url_localized=url_localized, | 87 | svg_localized=svg_localized, |
75 | svg_localized=svg_localized, | 88 | filename=name + "." + ext) |
76 | filename=name + "." + ext) | ||
77 | out_name = "./" + locale + "/" + in_file.rstrip(".j2") | 89 | out_name = "./" + locale + "/" + in_file.rstrip(".j2") |
78 | os.makedirs("./" + locale, exist_ok=True) | 90 | os.makedirs("./" + locale, exist_ok=True) |
79 | with codecs.open(out_name, "w", "utf-8") as f: | 91 | with codecs.open(out_name, "w", encoding='utf-8') as f: |
80 | f.write(content) | 92 | f.write(content) |