aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fietsboek/locale/de/html/home.html11
-rw-r--r--fietsboek/locale/en/html/home.html11
-rw-r--r--fietsboek/templates/home.jinja22
-rw-r--r--fietsboek/util.py29
-rw-r--r--fietsboek/views/default.py6
5 files changed, 58 insertions, 1 deletions
diff --git a/fietsboek/locale/de/html/home.html b/fietsboek/locale/de/html/home.html
new file mode 100644
index 0000000..9e866e6
--- /dev/null
+++ b/fietsboek/locale/de/html/home.html
@@ -0,0 +1,11 @@
+<p>Willkommen bei Fietsboek!</p>
+<p>
+ Hier kannst Du &hellip;
+ <ul>
+ <li>Rad- und Wanderstrecken, die mit einem GPS-Gerät aufgezeichnet wurden, hochladen</li>
+ <li>Diese Strecken mit anderen Nutzern teilen, oder Freunden Links zu den Strecken senden</il>
+ <li>Strecken anderer Nutzer kommentieren</li>
+ <li>Strecken finden, die Du selbst fahren oder wandern möchtest</li>
+ <li>Eine Zusammenfassung der pro Monat/Jahr zurückgelegten Strecke sehen</li>
+ </ul>
+</p>
diff --git a/fietsboek/locale/en/html/home.html b/fietsboek/locale/en/html/home.html
new file mode 100644
index 0000000..bac0391
--- /dev/null
+++ b/fietsboek/locale/en/html/home.html
@@ -0,0 +1,11 @@
+<p>Welcome to Fietsboek!</p>
+<p>
+ Here you can &hellip;
+ <ul>
+ <li>Upload cycling and hiking tours that you recorded with a GPS device</li>
+ <li>Share those tours with other users, or send links to the tours to friends</li>
+ <li>Comment on tours that other people have uploaded</li>
+ <li>Find tours that you'd like to do as well</li>
+ <li>Get a summary of how far you've traveled per month/year/in total</li>
+ </ul>
+</p>
diff --git a/fietsboek/templates/home.jinja2 b/fietsboek/templates/home.jinja2
index 5c7e0c8..6825c62 100644
--- a/fietsboek/templates/home.jinja2
+++ b/fietsboek/templates/home.jinja2
@@ -22,6 +22,8 @@
<p>
{{ _("page.home.total") }}: {{ (summary.total_length / 1000) | round(2) | format_decimal }} km
</p>
+ {% elif home_content %}
+ {{ home_content | safe }}
{% endif %}
</div>
{% endblock %}
diff --git a/fietsboek/util.py b/fietsboek/util.py
index 368cfcd..e24f96a 100644
--- a/fietsboek/util.py
+++ b/fietsboek/util.py
@@ -2,6 +2,7 @@
import random
import string
import datetime
+import importlib.resources
import babel
import markdown
@@ -260,3 +261,31 @@ def check_password_constraints(password, repeat_password=None):
raise ValueError(_("password_constraint.mismatch"))
if len(password) < 8:
raise ValueError(_("password_constraint.length"))
+
+
+def read_localized_resource(locale_name, path):
+ """Reads a localized resource.
+
+ Localized resources are located in the ``fietsboek/locale/**`` directory.
+ Note that ``path`` may contain slashes, which are automatically replaced
+ with the right separators.
+
+ If the resource could not be found, a placeholder string is returned instead.
+
+ :param locale_name: Name of the locale.
+ :type locale_name: str
+ :return: The text content of the resource.
+ :rtype: str
+ """
+ parts = path.split("/")
+ package = ".".join(parts[:-1])
+ package = f"fietsboek.locale.{locale_name}.{package}"
+ try:
+ return importlib.resources.read_text(package, parts[-1])
+ except (FileNotFoundError, ModuleNotFoundError, NotADirectoryError):
+ # Second chance: If the locale is a specific form of a more general
+ # locale, try the general locale as well.
+ if "_" in locale_name:
+ main_locale = locale_name.split("_", 1)[0]
+ return read_localized_resource(main_locale, path)
+ return f"{locale_name}:{path}"
diff --git a/fietsboek/views/default.py b/fietsboek/views/default.py
index 913266d..042e48c 100644
--- a/fietsboek/views/default.py
+++ b/fietsboek/views/default.py
@@ -22,7 +22,11 @@ def home(request):
:rtype: pyramid.response.Response
"""
if not request.identity:
- return {}
+ locale = request.localizer.locale_name
+ content = util.read_localized_resource(locale, "html/home.html")
+ return {
+ 'home_content': content,
+ }
all_tracks = request.identity.all_tracks
summary = summaries.Summary()