Skip to content

Commit

Permalink
[public] Add translations to the jinja templates
Browse files Browse the repository at this point in the history
  • Loading branch information
amrsoll committed Apr 28, 2024
1 parent 24ceb2f commit e8be12e
Show file tree
Hide file tree
Showing 21 changed files with 213 additions and 21 deletions.
2 changes: 1 addition & 1 deletion public/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN npm install -g [email protected]

RUN npm i -g npm sass

RUN pip3 install flask gunicorn
RUN pip3 install flask flask_babel gunicorn

RUN mkdir -p /work/src && mkdir -p /work/dist/js

Expand Down
12 changes: 12 additions & 0 deletions public/babel.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Extraction from Python files
[python: **.py]

# Extraction from Jinja2 template files
[jinja2: templates/**.jinja2]
encoding = utf-8

[jinja2: src/templates/**.html]
encoding = utf-8

# [javascript: **.tsx]
# extract_messages = t
77 changes: 77 additions & 0 deletions public/en.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Translations template for PROJECT.
# Copyright (C) 2024 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2024.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-04-28 23:17+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.12.1\n"

#: src/templates/cart.html:4 src/templates/product.html:24
msgid "Shopping Cart"
msgstr ""

#: src/templates/cart.html:4 src/templates/history.html:4
#: src/templates/licenses.html:4 src/templates/login.html:4
#: src/templates/member.html:4 src/templates/product.html:4
#: src/templates/receipt.html:4 src/templates/shop.html:4
msgid "Webshop"
msgstr ""

#: src/templates/courses.html:4
msgid "Courses"
msgstr ""

#: src/templates/history.html:4
msgid "Purchase History"
msgstr ""

#: src/templates/licenses.html:4
msgid "Licenses and discounts"
msgstr ""

#: src/templates/member.html:4
msgid "Members Page"
msgstr ""

#: src/templates/payment_form.html:2
msgid "Pay with bank card via Stripe"
msgstr ""

#: src/templates/payment_form.html:21
msgid "Pay"
msgstr ""

#: src/templates/product.html:21
msgid "Back"
msgstr ""

#: src/templates/register.html:4
msgid "Become a Member"
msgstr ""

#: src/templates/reset_password.html:4
msgid "Recover Password"
msgstr ""

#: src/templates/statistics.html:4
msgid "Statistics"
msgstr ""

#: src/templates/statistics.html:22
msgid "Statistics for the makerspace"
msgstr ""

#: src/templates/quiz/questions.html:4 src/templates/quiz/quiz.html:4
msgid "Quiz"
msgstr ""
13 changes: 13 additions & 0 deletions public/src/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import flask
from flask import Blueprint, Flask, redirect, send_from_directory, url_for
from flask_babel import Babel

basicConfig(
format="%(asctime)s %(levelname)s [%(process)d/%(threadName)s %(pathname)s:%(lineno)d]: %(message)s",
Expand Down Expand Up @@ -37,6 +38,17 @@ def route(self, path, **kwargs):
return super().route(self.url(path), **kwargs)


def get_locale():
# # if a user is logged in, use the locale from the user settings
# user = getattr(g, 'user', None)
# if user is not None:
# return user.locale
# otherwise try to guess the language from the user accept
# header the browser transmits. We support de/fr/en in this
# example. The best match wins.
return flask.request.accept_languages.best_match(['en', 'sv'])


def render_template(path: str, **kwargs: Any) -> str:
return flask.render_template(path, banner=banner, sidebar_additional_classes=sidebar_additional_classes, **kwargs)

Expand Down Expand Up @@ -130,6 +142,7 @@ def reset_password():

static_hash = os.environ["STATIC_PREFIX_HASH"]
app = Flask(__name__, static_url_path=f"/static{static_hash}", static_folder="../static")
babel = Babel(app, locale_selector=get_locale)
sys.stderr.write("STATIC URL PATH" + app.static_url_path + "\n")
app.register_blueprint(shop)
app.register_blueprint(member)
Expand Down
4 changes: 3 additions & 1 deletion public/src/templates/cart.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<!doctype html>
<html>
<head>
<title>Kundvagn - Stockholm Makerspace Webshop</title>
<title>
{{ _("Shopping Cart") }} - Stockholm Makerspace {{ _("Webshop") }}
</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand Down
2 changes: 1 addition & 1 deletion public/src/templates/courses.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Kurser - Stockholm Makerspace</title>
<title>{{ _("Courses") }}: - Stockholm Makerspace</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand Down
5 changes: 4 additions & 1 deletion public/src/templates/history.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<!doctype html>
<html>
<head>
<title>Köphistorik - Stockholm Makerspace Webshop</title>
<title>
{{ _("Purchase History") }} - Stockholm Makerspace {{ _("Webshop")
}}
</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand Down
5 changes: 4 additions & 1 deletion public/src/templates/licenses.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<!doctype html>
<html>
<head>
<title>Licenser och Rabatter - Stockholm Makerspace Webshop</title>
<title>
{{ _("Licenses and discounts") }} - Stockholm Makerspace {{
_("Webshop") }}
</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand Down
2 changes: 1 addition & 1 deletion public/src/templates/login.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Stockholm Makerspace Webshop</title>
<title>Stockholm Makerspace {{ _("Webshop") }}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
Expand Down
4 changes: 3 additions & 1 deletion public/src/templates/member.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<!doctype html>
<html>
<head>
<title>Medlemssidor - Stockholm Makerspace Webshop</title>
<title>
{{ _("Members Page") }} - Stockholm Makerspace {{ _("Webshop") }}
</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand Down
6 changes: 3 additions & 3 deletions public/src/templates/payment_form.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<form id="pay">
<h3>Betala med kort via Stripe</h3>
<h3>{{ _("Pay with bank card via Stripe") }}</h3>
<div class="form-row">
{# <label for="card-element"> Credit or debit card </label> #}
{# <label for="card-element">{{ _("Credit or debit card") }}</label> #}
<div id="payment_element"></div>
<div id="card-element">
<!-- A Stripe Element will be inserted here. -->
Expand All @@ -18,6 +18,6 @@ <h3>Betala med kort via Stripe</h3>
disabled
>
<div class="progress-spinner" uk-spinner></div>
<span>Betala / Pay<span id="cart-sum"></span></span>
<span>{{ _("Pay") }}<span id="cart-sum"></span></span>
</button>
</form>
8 changes: 5 additions & 3 deletions public/src/templates/product.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Stockholm Makerspace Webshop</title>
<title>Stockholm Makerspace {{ _("Webshop") }}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand All @@ -18,10 +18,12 @@
<div id="single-page-content">
<div class="product-nav-buttons">
<a class="product-nav-left" href='{{ url("/") }}'
><span uk-icon="arrow-left"></span> Tillbaka</a
><span uk-icon="arrow-left"></span> {{ _("Back") }}</a
>
<a class="product-nav-right" href='{{ url("/cart") }}'
>Min kundvagn<span id="cart-sum"></span>
>{{ _("Shopping Cart") }}Min kundvagn<span
id="cart-sum"
></span>
<span uk-icon="cart"></span
></a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion public/src/templates/quiz/questions.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Quiz - Stockholm Makerspace</title>
<title>{{ _("Quiz") }} - Stockholm Makerspace</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand Down
2 changes: 1 addition & 1 deletion public/src/templates/quiz/quiz.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Quiz - Stockholm Makerspace</title>
<title>{{ _("Quiz") }} - Stockholm Makerspace</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand Down
2 changes: 1 addition & 1 deletion public/src/templates/receipt.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Stockholm Makerspace Webshop</title>
<title>Stockholm Makerspace {{ _("Webshop") }}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand Down
2 changes: 1 addition & 1 deletion public/src/templates/register.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Bli medlem, Become a member - Stockholm Makerspace</title>
<title>{{ _("Become a Member") }} - Stockholm Makerspace</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand Down
2 changes: 1 addition & 1 deletion public/src/templates/reset_password.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Återställ Lösenord - Stockholm Makerspace</title>
<title>{{ _("Recover Password") }} - Stockholm Makerspace</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand Down
2 changes: 1 addition & 1 deletion public/src/templates/shop.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Stockholm Makerspace Webshop</title>
<title>Stockholm Makerspace {{ _("Webshop") }}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand Down
4 changes: 2 additions & 2 deletions public/src/templates/statistics.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Statistik - Stockholm Makerspace</title>
<title>{{ _("Statistics") }} - Stockholm Makerspace</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="{{ STATIC }}/uikit/css/uikit.min.css" />
Expand All @@ -19,7 +19,7 @@
</head>
<body>
<div id="single-page-content" class="statistics-page">
<h1>Statistik för Stockholm Makerspace</h1>
<h1>{{ _("Statistics for the makerspace") }}</h1>
</div>
</body>
</html>
Binary file not shown.
78 changes: 78 additions & 0 deletions public/sv.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Translations template for PROJECT.
# Copyright (C) 2024 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2024.
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-04-28 23:15+0200\n"
"PO-Revision-Date: 2024-04-28 23:17+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: sv\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.12.1\n"
"X-Generator: Poedit 3.4\n"

#: src/templates/cart.html:4 src/templates/product.html:24
msgid "Shopping Cart"
msgstr "Kundvagn"

#: src/templates/cart.html:4 src/templates/history.html:4
#: src/templates/licenses.html:4 src/templates/login.html:4
#: src/templates/member.html:4 src/templates/product.html:4
#: src/templates/receipt.html:4 src/templates/shop.html:4
msgid "Webshop"
msgstr "Webshop"

#: src/templates/courses.html:4
msgid "Courses"
msgstr "Kurser"

#: src/templates/history.html:4
msgid "Purchase History"
msgstr "Köphistorik"

#: src/templates/licenses.html:4
msgid "Licenses and discounts"
msgstr "Licenser och Rabatter"

#: src/templates/member.html:4
msgid "Members Page"
msgstr "Medlemssidor"

#: src/templates/payment_form.html:2
msgid "Pay with bank card via Stripe"
msgstr "Betala med kort via Stripe"

#: src/templates/payment_form.html:21
msgid "Pay"
msgstr "Betala"

#: src/templates/product.html:21
msgid "Back"
msgstr "Tillbaka"

#: src/templates/register.html:4
msgid "Become a member"
msgstr "Bli Medlem"

#: src/templates/reset_password.html:4
msgid "Recover Password"
msgstr "Återställ Lösenord"

#: src/templates/statistics.html:4
msgid "Statistics"
msgstr "Statistik"

#: src/templates/statistics.html:22
msgid "Statistics for the makerspace"
msgstr "Statistik för Stockholm Makerspace"

#: src/templates/quiz/questions.html:4 src/templates/quiz/quiz.html:4
msgid "Quiz"
msgstr "Quiz"

0 comments on commit e8be12e

Please sign in to comment.