From 6d294c63fd3175650fa65985b72996488eafd873 Mon Sep 17 00:00:00 2001 From: systeembeheerder <19684880+systeembeheerder@users.noreply.github.com> Date: Wed, 14 Feb 2024 21:38:23 +0100 Subject: [PATCH] add i18n to Snappass --- .gitignore | 4 + babel.cfg | 10 ++ snappass/main.py | 11 +- snappass/templates/base.html | 6 +- snappass/templates/confirm.html | 6 +- snappass/templates/expired.html | 6 +- snappass/templates/password.html | 8 +- snappass/templates/preview.html | 8 +- snappass/templates/set_password.html | 14 +-- .../translations/nl/LC_MESSAGES/messages.po | 112 ++++++++++++++++++ 10 files changed, 157 insertions(+), 28 deletions(-) create mode 100644 babel.cfg create mode 100644 snappass/translations/nl/LC_MESSAGES/messages.po diff --git a/.gitignore b/.gitignore index 6c53d83..ac9ab38 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,7 @@ htmlcov/ # virtualenv venv/ ENV/ + +# Translatio catalogs +*.mo +*.pot diff --git a/babel.cfg b/babel.cfg new file mode 100644 index 0000000..d6a43f6 --- /dev/null +++ b/babel.cfg @@ -0,0 +1,10 @@ +# Update Translations: +# (venv) $ pybabel extract -F babel.cfg -o messages.pot . +# (venv) $ pybabel update -i messages.pot -d snappass/translations +# (venv) $ pybabel compile -d snappass/translations +# Add a new language: +# (venv) $ pybabel extract -F babel.cfg -o messages.pot . +# (venv) $ pybabel init -i messages.pot -d snapppass/translations -l +[python: snappass/**.py] +[jinja2: snappass/templates/**.html] + diff --git a/snappass/main.py b/snappass/main.py index 0568154..17ec84c 100644 --- a/snappass/main.py +++ b/snappass/main.py @@ -5,18 +5,18 @@ import uuid import redis from cryptography.fernet import Fernet -from flask import abort, Flask, render_template, request, jsonify +from flask import abort, Flask, render_template, request, jsonify, g from redis.exceptions import ConnectionError from urllib.parse import quote_plus from urllib.parse import unquote_plus from distutils.util import strtobool +from flask_babel import Babel NO_SSL = bool(strtobool(os.environ.get('NO_SSL', 'False'))) URL_PREFIX = os.environ.get('URL_PREFIX', None) HOST_OVERRIDE = os.environ.get('HOST_OVERRIDE', None) TOKEN_SEPARATOR = '~' - # Initialize Flask Application app = Flask(__name__) if os.environ.get('DEBUG'): @@ -25,6 +25,11 @@ app.secret_key = os.environ.get('SECRET_KEY', 'Secret Key') app.config.update( dict(STATIC_URL=os.environ.get('STATIC_URL', 'static'))) +# Set up Babel +def get_locale(): + return request.accept_languages.best_match(['en', 'nl']) +babel = Babel(app, locale_selector=get_locale) + # Initialize Redis if os.environ.get('MOCK_REDIS'): from fakeredis import FakeStrictRedis @@ -56,7 +61,6 @@ def check_redis_alive(fn): return abort(500) return inner - def encrypt(password): """ Take a password string, encrypt it with Fernet symmetric encryption, @@ -212,6 +216,5 @@ def health_check(): def main(): app.run(host='0.0.0.0') - if __name__ == '__main__': main() diff --git a/snappass/templates/base.html b/snappass/templates/base.html index b199f42..1b8f910 100644 --- a/snappass/templates/base.html +++ b/snappass/templates/base.html @@ -1,7 +1,7 @@ - + - Snappass - Share Secrets + {{ _('Snappass - Share Secrets') }} @@ -13,7 +13,7 @@ diff --git a/snappass/templates/confirm.html b/snappass/templates/confirm.html index 7fe8b29..df28427 100644 --- a/snappass/templates/confirm.html +++ b/snappass/templates/confirm.html @@ -3,15 +3,15 @@ {% block content %}
- -

The secret has been temporarily saved. Send the following URL to your intended recipient.

+ +

{{ _('The secret has been temporarily saved. Send the following URL to your intended recipient.') }}

-
-

The secret has now been permanently deleted from the system, and the URL will no longer work. Refresh this page to verify.

+

{{ _('The secret has now been permanently deleted from the system, and the URL will no longer work. Refresh this page to verify.' }}

{% endblock %} diff --git a/snappass/templates/preview.html b/snappass/templates/preview.html index 1e54277..7b877b6 100644 --- a/snappass/templates/preview.html +++ b/snappass/templates/preview.html @@ -4,12 +4,12 @@
-

You can only reveal the secret once!

+

{{ _('You can only reveal the secret once!') }}

- +
@@ -20,4 +20,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/snappass/templates/set_password.html b/snappass/templates/set_password.html index d332ace..a05f733 100644 --- a/snappass/templates/set_password.html +++ b/snappass/templates/set_password.html @@ -3,27 +3,27 @@ {% block content %}
- +
- +
- +
diff --git a/snappass/translations/nl/LC_MESSAGES/messages.po b/snappass/translations/nl/LC_MESSAGES/messages.po new file mode 100644 index 0000000..3618555 --- /dev/null +++ b/snappass/translations/nl/LC_MESSAGES/messages.po @@ -0,0 +1,112 @@ +# Dutch translations for PROJECT. +# Copyright (C) 2024 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# FIRST AUTHOR , 2024. +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2024-02-14 21:09+0100\n" +"PO-Revision-Date: 2024-02-14 21:16+0100\n" +"Last-Translator: \n" +"Language: nl\n" +"Language-Team: nl \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.14.0\n" + +#: snappass/templates/base.html:4 +msgid "Snappass - Share Secrets" +msgstr "" + +#: snappass/templates/base.html:16 +msgid "Share Secret" +msgstr "Stel wachtwoord in" + +#: snappass/templates/confirm.html:6 +msgid "Share Secret Link" +msgstr "Deel wachtwoord link" + +#: snappass/templates/confirm.html:7 +msgid "" +"The secret has been temporarily saved. Send the following URL to your " +"intended recipient." +msgstr "" +"Het wachtwoord is tijdelijk opgeslagen. Deel de volgende URL aan de " +"bedoelde ontvanger." + +#: snappass/templates/confirm.html:14 +msgid "Copy to clipboard" +msgstr "Kopieer naar het klembord" + +#: snappass/templates/expired.html:6 +msgid "Secret not found" +msgstr "Wachtwoord niet gevonden" + +#: snappass/templates/expired.html:7 +msgid "" +"The requested URL was not found on the server. This could be because this" +" URL never contained a secret, or because it expired or was revealed " +"earlier." +msgstr "" +"De gevraagde URL is niet gevonden op de server. Dat kan omdat deze geen " +"wachtwoord bevat, het is verlopen of het al eerder getoond is." + +#: snappass/templates/expired.html:8 +msgid "" +"If this URL was sent to you by someone, make sure to check your spelling " +"or ask the person who sent it to you to send a new secret." +msgstr "" +"Als deze URL naar u is toegestuurd, controleer de spelling of vraag de " +"verzender om een nieuw wachtwoord link te versturen." + +#: snappass/templates/preview.html:7 +msgid "Secret" +msgstr "Wachtwoord" + +#: snappass/templates/preview.html:9 +msgid "You can only reveal the secret once!" +msgstr "Het wachtwoord wordt slechts eenmaal getoond!" + +#: snappass/templates/preview.html:12 +msgid "Reveal secret" +msgstr "Onthul wachtwoord" + +#: snappass/templates/set_password.html:6 +msgid "Set Secret" +msgstr "Stel wachtwoord in" + +#: snappass/templates/set_password.html:12 +msgid "" +"SnapPass allows you to share secrets in a secure, ephemeral way. Input a " +"single or multi-line secret, its expiration time, and click Generate URL." +" Share the one-time use URL with your intended recipient." +msgstr "" +"We stellen je in staat om wachtwoorden op een veilige, tijdelijke manier " +"te delen. Voer een enkel- of meerregelig wachwoord in, stel de vervaltijd" +" in, en klik op 'URL genereren'. Deel de eenmalig te gebruiken URL met de" +" beoogde ontvanger." + +#: snappass/templates/set_password.html:18 +msgid "Two Weeks" +msgstr "Twee weken" + +#: snappass/templates/set_password.html:19 +msgid "Week" +msgstr "Week" + +#: snappass/templates/set_password.html:20 +msgid "Day" +msgstr "Dag" + +#: snappass/templates/set_password.html:21 +msgid "Hour" +msgstr "Uur" + +#: snappass/templates/set_password.html:26 +msgid "Generate URL" +msgstr "URL genereren" +