From 4d4a0350d92b590cc85d107889e19ce12d4ee508 Mon Sep 17 00:00:00 2001
From: Dominik George <dominik.george@teckids.org>
Date: Tue, 17 Aug 2021 23:04:30 +0200
Subject: [PATCH] Use Jinja2 for template translation

---
 pelican_theme_teckids/pelicanconf.py          |  3 +++
 pelican_theme_teckids/templates/archives.html |  4 ++--
 pelican_theme_teckids/templates/article.html  |  2 +-
 pelican_theme_teckids/templates/author.html   |  4 ++--
 pelican_theme_teckids/templates/base.html     | 21 ++++++++++++-------
 pelican_theme_teckids/templates/page.html     |  2 ++
 .../templates/page_text.html                  |  2 ++
 7 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/pelican_theme_teckids/pelicanconf.py b/pelican_theme_teckids/pelicanconf.py
index fd67594..a54fc24 100644
--- a/pelican_theme_teckids/pelicanconf.py
+++ b/pelican_theme_teckids/pelicanconf.py
@@ -42,6 +42,9 @@ MARKDOWN = {
         "markdown.extensions.md_in_html": {}
     }
 }
+JINJA_ENVIRONMENT = {
+    "extensions": ["jinja2.ext.i18n"]
+}
 
 MENUITEMS = [
     ("Startseite", "index.html"),
diff --git a/pelican_theme_teckids/templates/archives.html b/pelican_theme_teckids/templates/archives.html
index 7838774..d41ae5a 100644
--- a/pelican_theme_teckids/templates/archives.html
+++ b/pelican_theme_teckids/templates/archives.html
@@ -1,11 +1,11 @@
 {% extends "base.html" %}
 
-{% block title %}{{ SITENAME }} — Archives{% endblock %}
+{% block title %}{% trans %}Artikel{% endtrans %}{% endblock %}
 {% block template_content_head %}
 <div class="container">
     <div class="row">
     <div class="col-sm-12">
-        <h1>News</h1>
+        <h1>{% trans %}Artikel{% endtrans %}</h1>
         {% for article in (articles|list + webring_articles|list)|sort(reverse=True, attribute="date") %}
           {% if article.source_link %}
            {# This is a webring article #}
diff --git a/pelican_theme_teckids/templates/article.html b/pelican_theme_teckids/templates/article.html
index aece2f6..a528668 100644
--- a/pelican_theme_teckids/templates/article.html
+++ b/pelican_theme_teckids/templates/article.html
@@ -1,6 +1,6 @@
 {% extends "base.html" %}
 
-{% block title %}{{ article.title|striptags }} - {{ SITETITLE }}{% endblock %}
+{% block title %}{{ article.title|striptags }}{% endblock %}
 
 {% block head %}
   {{ super() }}
diff --git a/pelican_theme_teckids/templates/author.html b/pelican_theme_teckids/templates/author.html
index 187399b..40accb0 100644
--- a/pelican_theme_teckids/templates/author.html
+++ b/pelican_theme_teckids/templates/author.html
@@ -1,6 +1,6 @@
 {% extends "page.html" %}
 
-{% block title %}{{ SITENAME }} — Articles by {{ author }}{% endblock %}
+{% block title %}{% trans %}Artikel von {{ author }}{% endtrans %}{% endblock %}
 {% block content_title %}
-<h2>Articles by {{ author }}</h2>
+<h2>{% trans %}Artikel von {{ author }}{% endtrans %}</h2>
 {% endblock %}
diff --git a/pelican_theme_teckids/templates/base.html b/pelican_theme_teckids/templates/base.html
index 14ce9a1..fc1f95e 100644
--- a/pelican_theme_teckids/templates/base.html
+++ b/pelican_theme_teckids/templates/base.html
@@ -16,7 +16,7 @@
     <meta http-equiv="X-UA-Compatible" content="IE=edge" />
     <meta name="viewport" content="width=device-width, initial-scale=1" />
     <meta name="description" content="{{ DESCRIPTION }}" />
-    <meta name="author" content="Teckids e.V." />
+    <meta name="author" content="{{ AUTHOR }}" />
     <style>
         :root {
             --teckids-primary-light: {{ PRIMARY_LIGHT }}ff;
@@ -44,7 +44,7 @@
     <link rel="shortcut icon" href="{{ FAVICON }}" />
 
     <title>
-        {{ SITENAME }}
+        {{ SITENAME }} – {% block title %}{% endblock %}
     </title>
 </head>
 
@@ -106,7 +106,7 @@
         <div class="container">
             <div class="row">
                 <div class="col s12 m6" id="sponsors-box">
-                    <h3 class="black-text sponsorheading">Sponsoren</h3>
+                    <h3 class="black-text sponsorheading">{% trans %}Sponsoren{% endtrans %}</h3>
                     {% for alt, image, url, before in SPONSORS %}
 		        {% if before >= TODAY %}
                             <a href="{{ url }}"><img src="{{ image }}" href="{{ url }}" alt="{{ alt }}" title="{{ alt }}" class="sponsorslogo" /></a>
@@ -142,19 +142,24 @@
 			{{ FOOTERTEXT }}
                     </p>
         <p class="licence">
+            {% trans %}Dieser Inhalt ist lizenziert unter{% endtrans %}
 	    {% if article is defined %}
-	        {{ LICENCETEXTS[article.lang|default(DEFAULT_LANG)] }} {{ article.metadata.licence|default(LICENCE_DEFAULT) }}
+	        {{ article.metadata.licence|default(LICENCE_DEFAULT) }}
 	    {% elif page is defined %}
-	        {{ LICENCETEXTS[DEFAULT_LANG] }} {{ page.metadata.licence|default(LICENCE_DEFAULT) }}
+	        {{ page.metadata.licence|default(LICENCE_DEFAULT) }}
+            {% else %}
+                {{ LICENCE_DEFAULT }}
 	    {% endif %}
             <br/>
 	    {% if article is defined %}
-	        <a href="{{ GITWEB_BASE }}/content/{{ article.relative_source_path }}">Edit in source repository</a>
+	        <a href="{{ GITWEB_BASE }}/content/{{ article.relative_source_path }}">
 	    {% elif page is defined %}
-	        <a href="{{ GITWEB_BASE }}/content/{{ page.relative_source_path }}">Edit in source repository</a>
+	        <a href="{{ GITWEB_BASE }}/content/{{ page.relative_source_path }}">
             {% else %}
-                <a href="{{ GITWEB_BASE }}/content">Edit in source repository</a>
+                <a href="{{ GITWEB_BASE }}/content">
             {% endif %}
+                {% trans %}Im Quell-Repository editieren{% endtrans %}
+            </a>
 	</p>
 
                 </div>
diff --git a/pelican_theme_teckids/templates/page.html b/pelican_theme_teckids/templates/page.html
index a5086ce..2bded04 100644
--- a/pelican_theme_teckids/templates/page.html
+++ b/pelican_theme_teckids/templates/page.html
@@ -1,5 +1,7 @@
 {% extends "base.html" %}
 
+{% block title %}{{ page.title|striptags }}{% endblock %}
+
 {% block head %}
 {{ super() }}
         <link rel='stylesheet' type='text/css' href="/theme/css/page.css" />
diff --git a/pelican_theme_teckids/templates/page_text.html b/pelican_theme_teckids/templates/page_text.html
index 66161a2..16eb9f7 100644
--- a/pelican_theme_teckids/templates/page_text.html
+++ b/pelican_theme_teckids/templates/page_text.html
@@ -1,5 +1,7 @@
 {% extends "base.html" %}
 
+{% block title %}{{ page.title|striptags }}{% endblock %}
+
 {% block content %}
 <section class='page_content'>
     <div class="container">
-- 
GitLab