From e87827a9215163948d0a68b9a33e56af8709762e Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Tue, 31 Jul 2018 11:41:35 +0200 Subject: i18n, first batch. --- .../backoffice/static/logo-2018-dold.svg | 87 +++++++++++++++++ .../backoffice/templates/backoffice.html | 103 --------------------- .../backoffice/templates/backoffice.html.j2 | 103 +++++++++++++++++++++ talerbackoffice/backoffice/templates/base.html | 62 ------------- talerbackoffice/backoffice/templates/base.html.j2 | 62 +++++++++++++ talerbackoffice/backoffice/templates/i18nfix.py | 33 +++++++ .../backoffice/templates/javascript.html | 17 ---- .../backoffice/templates/javascript.html.j2 | 17 ++++ .../backoffice/templates/locale/babel.map | 12 +++ .../templates/locale/de/LC_MESSAGES/messages.po | 25 +++++ .../templates/locale/en/LC_MESSAGES/messages.po | 27 ++++++ .../templates/locale/fr/LC_MESSAGES/messages.po | 25 +++++ .../templates/locale/it/LC_MESSAGES/messages.po | 25 +++++ .../backoffice/templates/locale/messages.pot | 25 +++++ .../templates/locale/pt/LC_MESSAGES/messages.po | 25 +++++ .../templates/locale/ru/LC_MESSAGES/messages.po | 26 ++++++ talerbackoffice/backoffice/templates/template.py | 85 +++++++++++++++++ 17 files changed, 577 insertions(+), 182 deletions(-) create mode 100644 talerbackoffice/backoffice/static/logo-2018-dold.svg delete mode 100644 talerbackoffice/backoffice/templates/backoffice.html create mode 100644 talerbackoffice/backoffice/templates/backoffice.html.j2 delete mode 100644 talerbackoffice/backoffice/templates/base.html create mode 100644 talerbackoffice/backoffice/templates/base.html.j2 create mode 100644 talerbackoffice/backoffice/templates/i18nfix.py delete mode 100644 talerbackoffice/backoffice/templates/javascript.html create mode 100644 talerbackoffice/backoffice/templates/javascript.html.j2 create mode 100644 talerbackoffice/backoffice/templates/locale/babel.map create mode 100644 talerbackoffice/backoffice/templates/locale/de/LC_MESSAGES/messages.po create mode 100644 talerbackoffice/backoffice/templates/locale/en/LC_MESSAGES/messages.po create mode 100644 talerbackoffice/backoffice/templates/locale/fr/LC_MESSAGES/messages.po create mode 100644 talerbackoffice/backoffice/templates/locale/it/LC_MESSAGES/messages.po create mode 100644 talerbackoffice/backoffice/templates/locale/messages.pot create mode 100644 talerbackoffice/backoffice/templates/locale/pt/LC_MESSAGES/messages.po create mode 100644 talerbackoffice/backoffice/templates/locale/ru/LC_MESSAGES/messages.po create mode 100755 talerbackoffice/backoffice/templates/template.py diff --git a/talerbackoffice/backoffice/static/logo-2018-dold.svg b/talerbackoffice/backoffice/static/logo-2018-dold.svg new file mode 100644 index 0000000..ddb8425 --- /dev/null +++ b/talerbackoffice/backoffice/static/logo-2018-dold.svg @@ -0,0 +1,87 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/talerbackoffice/backoffice/templates/backoffice.html b/talerbackoffice/backoffice/templates/backoffice.html deleted file mode 100644 index b95f501..0000000 --- a/talerbackoffice/backoffice/templates/backoffice.html +++ /dev/null @@ -1,103 +0,0 @@ -{% extends "templates/base.html" %} -{% block main %} -

Taler backoffice

-

This is the Taler backoffice facility. Through it, - the user can see the money flow from Taler transactions to - wire transfers and viceversa.

- -
- -
- -
-
- Current instance: - -
-
-
-
-
- Track order id
- Track wire transfer
-
-
-
-
-
-
- - -
-
-
-
- - - - - - - - - - - - -
- -
- -
- -
-{% endblock main %} - -{% block styles %} - -{% endblock styles %} - -{% block scripts %} - -{% endblock scripts %} diff --git a/talerbackoffice/backoffice/templates/backoffice.html.j2 b/talerbackoffice/backoffice/templates/backoffice.html.j2 new file mode 100644 index 0000000..063a28f --- /dev/null +++ b/talerbackoffice/backoffice/templates/backoffice.html.j2 @@ -0,0 +1,103 @@ +{% extends "templates/base.html" %} +{% block main %} +

Taler backoffice

+

{% trans %}This is the Taler backoffice facility. Through it, + the user can see the money flow from Taler transactions to + wire transfers and viceversa.{% endtrans %}

+ +
+ +
+ +
+
+ Current instance: + +
+
+
+
+
+ Track order id
+ Track wire transfer
+
+
+
+
+
+
+ + +
+
+
+
+ + + + + + + + + + + + +
+ +
+ +
+ +
+{% endblock main %} + +{% block styles %} + +{% endblock styles %} + +{% block scripts %} + +{% endblock scripts %} diff --git a/talerbackoffice/backoffice/templates/base.html b/talerbackoffice/backoffice/templates/base.html deleted file mode 100644 index 4e8109c..0000000 --- a/talerbackoffice/backoffice/templates/base.html +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - Taler Back-office interface - - - - - - {% block styles %}{% endblock %} - {% block scripts %}{% endblock %} - - - -
-

Taler Demo

-

Backoffice

-

This is the back-office interface, you can monitor your cash flow with it.

- -

You can learn more about Taler on our main website.

-
- -
- - - - {% block main %} - This is the main content of the page. - {% endblock %} -
- -
- - diff --git a/talerbackoffice/backoffice/templates/base.html.j2 b/talerbackoffice/backoffice/templates/base.html.j2 new file mode 100644 index 0000000..4e8109c --- /dev/null +++ b/talerbackoffice/backoffice/templates/base.html.j2 @@ -0,0 +1,62 @@ + + + + + + Taler Back-office interface + + + + + + {% block styles %}{% endblock %} + {% block scripts %}{% endblock %} + + + +
+

Taler Demo

+

Backoffice

+

This is the back-office interface, you can monitor your cash flow with it.

+ +

You can learn more about Taler on our main website.

+
+ +
+ + + + {% block main %} + This is the main content of the page. + {% endblock %} +
+ +
+ + diff --git a/talerbackoffice/backoffice/templates/i18nfix.py b/talerbackoffice/backoffice/templates/i18nfix.py new file mode 100644 index 0000000..331706a --- /dev/null +++ b/talerbackoffice/backoffice/templates/i18nfix.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +# This file is in the public domain. + +""" +Extract translations from a Jinja2 template, stripping leading newlines. + +@author Florian Dold +""" + +import jinja2.ext +import re + +def normalize(message): + message = message.strip() + # collapse whitespaces (including newlines) into one space. + message = re.sub("\s+", " ", message) + return message + + +def babel_extract(fileobj, keywords, comment_tags, options): + res = jinja2.ext.babel_extract(fileobj, keywords, comment_tags, options) + for lineno, funcname, message, comments in res: + message = normalize(message) + yield lineno, funcname, message, comments + +def wrap_gettext(f): + """ + Call gettext with whitespace normalized. + """ + def wrapper(message): + message = normalize(message) + return f(message) + return wrapper diff --git a/talerbackoffice/backoffice/templates/javascript.html b/talerbackoffice/backoffice/templates/javascript.html deleted file mode 100644 index 8f27425..0000000 --- a/talerbackoffice/backoffice/templates/javascript.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - -
taler-wallet-lib.jsLGPLtaler-wallet-lib.js.tar.gz
dropdown-navbar_script.jsLGPLdropdown-navbar_script.js
- - diff --git a/talerbackoffice/backoffice/templates/javascript.html.j2 b/talerbackoffice/backoffice/templates/javascript.html.j2 new file mode 100644 index 0000000..8f27425 --- /dev/null +++ b/talerbackoffice/backoffice/templates/javascript.html.j2 @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + +
taler-wallet-lib.jsLGPLtaler-wallet-lib.js.tar.gz
dropdown-navbar_script.jsLGPLdropdown-navbar_script.js
+ + diff --git a/talerbackoffice/backoffice/templates/locale/babel.map b/talerbackoffice/backoffice/templates/locale/babel.map new file mode 100644 index 0000000..72b6f99 --- /dev/null +++ b/talerbackoffice/backoffice/templates/locale/babel.map @@ -0,0 +1,12 @@ +[extractors] +jinja2 = i18nfix:babel_extract + +[jinja2: **.j2] +encoding = utf-8 +lstrip_blocks = True +trim_blocks = True + +[jinja2: **.j2.inc] +encoding = utf-8 +lstrip_blocks = True +ltrim_blocks = True diff --git a/talerbackoffice/backoffice/templates/locale/de/LC_MESSAGES/messages.po b/talerbackoffice/backoffice/templates/locale/de/LC_MESSAGES/messages.po new file mode 100644 index 0000000..4b63635 --- /dev/null +++ b/talerbackoffice/backoffice/templates/locale/de/LC_MESSAGES/messages.po @@ -0,0 +1,25 @@ +# Translations template for PROJECT. +# Copyright (C) 2018 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# Marko Stanisky , 2018. +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2018-07-31 11:29+0200\n" +"PO-Revision-Date: 2018-07-31 11:37+0200\n" +"Last-Translator: Marcello Stanisci \n" +"Language-Team: German\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.3.4\n" +"Language: de\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: backoffice.html.j2:4 +msgid "" +"This is the Taler backoffice facility. Through it, the user can see the " +"money flow from Taler transactions to wire transfers and viceversa." +msgstr "" diff --git a/talerbackoffice/backoffice/templates/locale/en/LC_MESSAGES/messages.po b/talerbackoffice/backoffice/templates/locale/en/LC_MESSAGES/messages.po new file mode 100644 index 0000000..839d17f --- /dev/null +++ b/talerbackoffice/backoffice/templates/locale/en/LC_MESSAGES/messages.po @@ -0,0 +1,27 @@ +# Translations template for PROJECT. +# Copyright (C) 2018 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# Marko Stanisky , 2018. +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2018-07-31 11:29+0200\n" +"PO-Revision-Date: 2018-07-31 11:37+0200\n" +"Last-Translator: Marcello Stanisci \n" +"Language-Team: English\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.3.4\n" +"Language: en\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: backoffice.html.j2:4 +msgid "" +"This is the Taler backoffice facility. Through it, the user can see the " +"money flow from Taler transactions to wire transfers and viceversa." +msgstr "" +"This is the Taler backoffice facility. Through it, the user can see the " +"money flow from Taler transactions to wire transfers and viceversa." diff --git a/talerbackoffice/backoffice/templates/locale/fr/LC_MESSAGES/messages.po b/talerbackoffice/backoffice/templates/locale/fr/LC_MESSAGES/messages.po new file mode 100644 index 0000000..8baa214 --- /dev/null +++ b/talerbackoffice/backoffice/templates/locale/fr/LC_MESSAGES/messages.po @@ -0,0 +1,25 @@ +# Translations template for PROJECT. +# Copyright (C) 2018 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# Marko Stanisky , 2018. +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2018-07-31 11:29+0200\n" +"PO-Revision-Date: 2018-07-31 11:37+0200\n" +"Last-Translator: Marcello Stanisci \n" +"Language-Team: French\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.3.4\n" +"Language: fr\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#: backoffice.html.j2:4 +msgid "" +"This is the Taler backoffice facility. Through it, the user can see the " +"money flow from Taler transactions to wire transfers and viceversa." +msgstr "" diff --git a/talerbackoffice/backoffice/templates/locale/it/LC_MESSAGES/messages.po b/talerbackoffice/backoffice/templates/locale/it/LC_MESSAGES/messages.po new file mode 100644 index 0000000..c017fc7 --- /dev/null +++ b/talerbackoffice/backoffice/templates/locale/it/LC_MESSAGES/messages.po @@ -0,0 +1,25 @@ +# Translations template for PROJECT. +# Copyright (C) 2018 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# Marko Stanisky , 2018. +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2018-07-31 11:29+0200\n" +"PO-Revision-Date: 2018-07-31 11:37+0200\n" +"Last-Translator: Marcello Stanisci \n" +"Language-Team: Italian\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.3.4\n" +"Language: it\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: backoffice.html.j2:4 +msgid "" +"This is the Taler backoffice facility. Through it, the user can see the " +"money flow from Taler transactions to wire transfers and viceversa." +msgstr "" diff --git a/talerbackoffice/backoffice/templates/locale/messages.pot b/talerbackoffice/backoffice/templates/locale/messages.pot new file mode 100644 index 0000000..9400cb4 --- /dev/null +++ b/talerbackoffice/backoffice/templates/locale/messages.pot @@ -0,0 +1,25 @@ +# Translations template for PROJECT. +# Copyright (C) 2018 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# FIRST AUTHOR , 2018. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2018-07-31 11:29+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.3.4\n" + +#: backoffice.html.j2:4 +msgid "" +"This is the Taler backoffice facility. Through it, the user can see the " +"money flow from Taler transactions to wire transfers and viceversa." +msgstr "" + diff --git a/talerbackoffice/backoffice/templates/locale/pt/LC_MESSAGES/messages.po b/talerbackoffice/backoffice/templates/locale/pt/LC_MESSAGES/messages.po new file mode 100644 index 0000000..603e0e8 --- /dev/null +++ b/talerbackoffice/backoffice/templates/locale/pt/LC_MESSAGES/messages.po @@ -0,0 +1,25 @@ +# Translations template for PROJECT. +# Copyright (C) 2018 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# Marko Stanisky , 2018. +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2018-07-31 11:29+0200\n" +"PO-Revision-Date: 2018-07-31 11:37+0200\n" +"Last-Translator: Marcello Stanisci \n" +"Language-Team: Portuguese\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.3.4\n" +"Language: pt\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: backoffice.html.j2:4 +msgid "" +"This is the Taler backoffice facility. Through it, the user can see the " +"money flow from Taler transactions to wire transfers and viceversa." +msgstr "" diff --git a/talerbackoffice/backoffice/templates/locale/ru/LC_MESSAGES/messages.po b/talerbackoffice/backoffice/templates/locale/ru/LC_MESSAGES/messages.po new file mode 100644 index 0000000..1bb3f01 --- /dev/null +++ b/talerbackoffice/backoffice/templates/locale/ru/LC_MESSAGES/messages.po @@ -0,0 +1,26 @@ +# Translations template for PROJECT. +# Copyright (C) 2018 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# Marko Stanisky , 2018. +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2018-07-31 11:29+0200\n" +"PO-Revision-Date: 2018-07-31 11:37+0200\n" +"Last-Translator: Marcello Stanisci \n" +"Language-Team: Russian\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.3.4\n" +"Language: ru\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" + +#: backoffice.html.j2:4 +msgid "" +"This is the Taler backoffice facility. Through it, the user can see the " +"money flow from Taler transactions to wire transfers and viceversa." +msgstr "" diff --git a/talerbackoffice/backoffice/templates/template.py b/talerbackoffice/backoffice/templates/template.py new file mode 100755 index 0000000..eae04eb --- /dev/null +++ b/talerbackoffice/backoffice/templates/template.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +# This file is in the public domain. +# +# This script runs the jinja2 templating engine on an input template-file +# using the specified locale for gettext translations, and outputs +# the resulting (HTML) ouptut-file. +# +# Note that the gettext files need to be prepared first. This script +# is thus to be invoked via the Makefile. +import os +import os.path +import sys +import re +import gettext +import jinja2 +import glob +import codecs +import os +sys.path.append(os.getcwd()) +import i18nfix + +env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), + extensions=["jinja2.ext.i18n"], + lstrip_blocks=True, + trim_blocks=True, + undefined=jinja2.StrictUndefined, + autoescape=False) + +langs_full = {"en": "English", + "fr": "Français", + "it": "Italiano", + "es": "Español", + "de": "Deutsch", + "ru": "Ру́сский язы́к", + "pt": "Português"} + +for in_file in glob.glob("*.j2"): + name, ext = re.match(r"(.*)\.([^.]+)$", in_file.rstrip(".j2")).groups() + tmpl = env.get_template(in_file) + + def self_localized(other_locale): + """ + Return URL for the current page in another locale. + """ + return "../" + other_locale + "/" + in_file.rstrip(".j2") + + def url_localized(filename): + return "../" + locale + "/" + filename + + def svg_localized(filename): + lf = filename + "." + locale + ".svg" + if "en" == locale or not os.path.isfile (lf): + return "../" + filename + ".svg" + else: + return "../" + lf + + def url(x): + # TODO: look at the app root environment variable + # TODO: check if file exists + return "../" + x + + for l in glob.glob("locale/*/"): + locale = os.path.basename(l[:-1]) + + tr = gettext.translation("messages", + localedir="locale", + languages=[locale]) + + tr.gettext = i18nfix.wrap_gettext(tr.gettext) + + env.install_gettext_translations(tr, newstyle=True) + + + content = tmpl.render( + lang=locale, + lang_full=langs_full[locale], + url=url, + self_localized=self_localized, + url_localized=url_localized, + svg_localized=svg_localized, + filename=name + "." + ext) + out_name = "./" + locale + "/" + in_file.rstrip(".j2") + os.makedirs("./" + locale, exist_ok=True) + with codecs.open(out_name, "w", "utf-8") as f: + f.write(content) -- cgit v1.2.3