From 520c115b3a787b6509b003f28dd45d3b1894fad9 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 15 Mar 2017 12:59:41 +0100 Subject: templating and i18n --- common/base.j2 | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 123 --------------------------------------------------------- index.html.j2 | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ template.py | 80 +++++++++++++++++++++++++++++++++++++ 4 files changed, 325 insertions(+), 123 deletions(-) create mode 100644 common/base.j2 delete mode 100644 index.html create mode 100644 index.html.j2 create mode 100755 template.py diff --git a/common/base.j2 b/common/base.j2 new file mode 100644 index 0000000..9a54048 --- /dev/null +++ b/common/base.j2 @@ -0,0 +1,122 @@ + + + + + Taler Demonstration Framework + + + + + + + + + +
+ + +

Taler Demo

+
+ + + +
+
+

Step 1: Install the Taler wallet

+ Install the wallet from the installation page. + It only takes one click. +

+ You don't have a wallet installed yet. +

+

+ Congratulations, you have installed the Taler wallet correctly. + You can now proceed with the next steps. +

+
+ +
+

Step 2: Withdraw coins

+

+ + Now you can withdraw coins into your wallet by going to our bank. + + In this demo you're paying with KUDOS, an imaginary currency. When you + create an account at our bank, you'll get 100 KUDOS for free. +

+

+ We can't check if you were able to complete this step, since websites + can't see the balance in your wallet. Please click on the Taler icon + in your browser to check your balance. +

+
+ +
+

Step 3: Pay

+ We have two demo merchants where you can spend your coins: +
    +
  • + The essay store, where you can pay KUDOS for + individual chapters of Richard Stallman's book "Free Software, Free + Society", which is also available for free at the FSF. +
  • +
  • + The project donation Web site, where + you can show respect to a software project of your choice + by giving them KUDOS. +
  • +
+
+
+

Step 4: Back office

+ Finally, you can take the perspective of the merchant, who just + sold articles using taler. +
    +
  • + The back office Web site + allows you to track the transactions of the merchant. +
  • +
  • + The public accounts page at the bank + allow you to observe transactions of certain bank accounts, including + those of the shops, from the perspective of the bank. +
  • +
+
+
+

Step 5: Reach out to us

+ Let us know what you think by contacting us. +
+
+ + + diff --git a/index.html b/index.html deleted file mode 100644 index 2d4470d..0000000 --- a/index.html +++ /dev/null @@ -1,123 +0,0 @@ - - - - - Taler Demo - - - - - - - - -
-

Taler Demo

-

Introduction

-

This is the entry point of the Taler demo. Follow the instructions and try Taler with the other pages linked below!

- -

You can learn more about Taler on our main website.

-
-
-
-

Step 1: Install the Taler wallet

- Install the wallet from the installation page. - It only takes one click. -

- You don't have a wallet installed yet. -

-

- Congratulations, you have installed the Taler wallet correctly. - You can now proceed with the next steps. -

-
- -
-

Step 2: Withdraw coins

-

- - Now you can withdraw coins into your wallet by going to our bank. - - In this demo you're paying with KUDOS, an imaginary currency. When you - create an account at our bank, you'll get 100 KUDOS for free. -

-

- We can't check if you were able to complete this step, since websites - can't see the balance in your wallet. Please click on the Taler icon - in your browser to check your balance. -

-
- -
-

Step 3: Pay

- We have two demo merchants where you can spend your coins: -
    -
  • - The essay store, where you can pay KUDOS for - individual chapters of Richard Stallman's book "Free Software, Free - Society", which is also available for free at the FSF. -
  • -
  • - The project donation Web site, where - you can show respect to a software project of your choice - by giving them KUDOS. -
  • -
-
-
-

Step 4: Back office

- Finally, you can take the perspective of the merchant, who just - sold articles using taler. -
    -
  • - The back office Web site - allows you to track the transactions of the merchant. -
  • -
  • - The public accounts page at the bank - allow you to observe transactions of certain bank accounts, including - those of the shops, from the perspective of the bank. -
  • -
-
-
-

Step 5: Reach out to us

- Let us know what you think by contacting us. -
-
- -
- - diff --git a/index.html.j2 b/index.html.j2 new file mode 100644 index 0000000..60a1da3 --- /dev/null +++ b/index.html.j2 @@ -0,0 +1,123 @@ + + + + + Taler Demo + + + + + + + + +
+

Taler Demo

+

Introduction

+

This is the entry point of the Taler demo. Follow the instructions and try Taler with the other pages linked below!

+ +

You can learn more about Taler on our main website.

+
+
+
+

Step 1: Install the Taler wallet

+ Install the wallet from the installation page. + It only takes one click. +

+ You don't have a wallet installed yet. +

+

+ Congratulations, you have installed the Taler wallet correctly. + You can now proceed with the next steps. +

+
+ +
+

Step 2: Withdraw coins

+

+ + Now you can withdraw coins into your wallet by going to our bank. + + In this demo you're paying with KUDOS, an imaginary currency. When you + create an account at our bank, you'll get 100 KUDOS for free. +

+

+ We can't check if you were able to complete this step, since websites + can't see the balance in your wallet. Please click on the Taler icon + in your browser to check your balance. +

+
+ +
+

Step 3: Pay

+ We have two demo merchants where you can spend your coins: +
    +
  • + The essay store, where you can pay KUDOS for + individual chapters of Richard Stallman's book "Free Software, Free + Society", which is also available for free at the FSF. +
  • +
  • + The project donation Web site, where + you can show respect to a software project of your choice + by giving them KUDOS. +
  • +
+
+
+

Step 4: Back office

+ Finally, you can take the perspective of the merchant, who just + sold articles using taler. +
    +
  • + The back office Web site + allows you to track the transactions of the merchant. +
  • +
  • + The public accounts page at the bank + allow you to observe transactions of certain bank accounts, including + those of the shops, from the perspective of the bank. +
  • +
+
+
+

Step 5: Reach out to us

+ Let us know what you think by contacting us. +
+
+ +
+ + diff --git a/template.py b/template.py new file mode 100755 index 0000000..0bb4092 --- /dev/null +++ b/template.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# This file is in the public domain. +# +# This script runs the jinga2 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 +import os.path + +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) + +default_ctx = {} +default_ctx["merchant_blog_url"] = os.environ.get("TALER_ENV_URL_MERCHANT_BLOG", "#") +default_ctx["merchant_donations_url"] = os.environ.get("TALER_ENV_URL_MERCHANT_DONATIONS", "#") +default_ctx["intro_url"] = os.environ.get("TALER_ENV_URL_INTRO", "#") +default_ctx["bank_url"] = os.environ.get("TALER_ENV_URL_BANK", "#") +default_ctx["auditor_url"] = os.environ.get("TALER_ENV_URL_AUDITOR", "#") + + +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 url(x): + # TODO: look at the app root environment variable + # TODO: check if file exists + return "../" + x + + for l in ("en", "de", "it", "es"): + locale = os.path.basename(l) + + if os.path.isdir(os.path.join("./locale/", locale)): + tr = gettext.translation("messages", + localedir="locale", + languages=[locale]) + + env.install_gettext_translations(tr, newstyle=True) + else: + print("warning: locale {} not found".format(locale)) + + ctx = dict( + lang=locale, + url=url, + self_localized=self_localized, + url_localized=url_localized, + filename=name + "." + ext) + ctx.update(default_ctx) + + content = tmpl.render(**ctx) + 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