Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add i18n to Snappass #330

Merged
merged 8 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ htmlcov/
# virtualenv
venv/
ENV/

# Translation catalogs
*.mo
*.pot
10 changes: 10 additions & 0 deletions babel.cfg
Original file line number Diff line number Diff line change
@@ -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 snappass/translations -l <language_code>
[python: snappass/**.py]
[jinja2: snappass/templates/**.html]

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Jinja2==3.1.2
MarkupSafe==2.1.1
redis==5.0.1
Werkzeug==3.0.1
flask-babel
9 changes: 6 additions & 3 deletions snappass/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
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'):
Expand All @@ -25,6 +25,11 @@
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', 'es', 'de', 'nl'])
babel = Babel(app, locale_selector=get_locale)

# Initialize Redis
if os.environ.get('MOCK_REDIS'):
from fakeredis import FakeStrictRedis
Expand Down Expand Up @@ -56,7 +61,6 @@ def inner(*args, **kwargs):
return abort(500)
return inner


def encrypt(password):
"""
Take a password string, encrypt it with Fernet symmetric encryption,
Expand Down Expand Up @@ -212,6 +216,5 @@ def health_check():
def main():
app.run(host='0.0.0.0')


if __name__ == '__main__':
main()
6 changes: 3 additions & 3 deletions snappass/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<html lang="{{ _('en') }}">
<head>
<title>Snappass - Share Secrets</title>
<title>{{ _('Snappass - Share Secrets') }}</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

Expand All @@ -13,7 +13,7 @@
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/">Share Secret</a>
<a class="navbar-brand" href="/">{{ _('Share Secret') }}</a>
</div>
</div>
</nav>
Expand Down
6 changes: 3 additions & 3 deletions snappass/templates/confirm.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
{% block content %}
<div class="container">
<section>
<div class="page-header"><h1>Share Secret Link</h1></div>
<p>The secret has been temporarily saved. Send the following URL to your intended recipient.</p>
<div class="page-header"><h1>{{ _('Share Secret Link') }}</h1></div>
<p>{{ _('The secret has been temporarily saved. Send the following URL to your intended recipient.') }}</p>
<div class="row">
<div class="col-sm-6 margin-bottom-10">
<input type="text" class="form-control" id="password-link" value="{{ password_link }}" readonly="readonly">
</div>

<div class="col-sm-6">
<button title="Copy to clipboard" type="button" class="btn btn-primary copy-clipboard-btn"
<button title="{{ _('Copy to clipboard') }}" type="button" class="btn btn-primary copy-clipboard-btn"
id="copy-clipboard-btn" data-clipboard-target="#password-link"
data-placement='bottom'>
<i class="fa fa-clipboard"></i>
Expand Down
6 changes: 3 additions & 3 deletions snappass/templates/expired.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
{% block content %}
<div class="container">
<section>
<div class="page-header"><h1>Secret not found</h1></div>
<p class="lead">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.</p>
<p class="lead">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.</p>
<div class="page-header"><h1>{{ _('Secret not found') }}</h1></div>
<p class="lead">{{ _('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.') }}</p>
<p class="lead">{{ _('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.') }}</p>
</section>
</div>
{% endblock %}
8 changes: 4 additions & 4 deletions snappass/templates/password.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
{% block content %}
<div class="container">
<section>
<div class="page-header"><h1>Secret</h1></div>
<p>Save the following secret to a secure location.</p>
<div class="page-header"><h1>{{ _('Secret') }}</h1></div>
<p>{{ _('Save the following secret to a secure location.') }}</p>
<div class="row">
<div class="col-sm-6 margin-bottom-10">
<textarea class="form-control" rows="10" cols="50" id="password-text" name="password-text" readonly="readonly">{{ password }}</textarea>
</div>

<div class="col-sm-6">
<button title="Copy to clipboard" type="button" class="btn btn-primary copy-clipboard-btn"
<button title="{{ _('Copy to clipboard') }}" type="button" class="btn btn-primary copy-clipboard-btn"
id="copy-clipboard-btn" data-clipboard-target="#password-text"
data-placement='bottom'>
<i class="fa fa-clipboard"></i>
</button>
</div>
</div>
<p>The secret has now been permanently deleted from the system, and the URL will no longer work. Refresh this page to verify.</p>
<p>{{ _('The secret has now been permanently deleted from the system, and the URL will no longer work. Refresh this page to verify.') }}</p>
</section>
</div>
{% endblock %}
Expand Down
8 changes: 4 additions & 4 deletions snappass/templates/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<div class="container">
<section>
<div class="page-header">
<h1>Secret</h1>
<h1>{{ _('Secret') }}</h1>
</div>
<p class="lead">You can only reveal the secret once!</p>
<p class="lead">{{ _('You can only reveal the secret once!') }}</p>
<div class="row">
<div class="col-sm-6 margin-bottom-10">
<button id="revealSecret" type="button" class="btn-lg btn-primary">Reveal secret</button>
<button id="revealSecret" type="button" class="btn-lg btn-primary">{{ _('Reveal secret') }}</button>
</div>
</div>
</section>
Expand All @@ -20,4 +20,4 @@ <h1>Secret</h1>
<script src="{{ config.STATIC_URL }}/clipboardjs/clipboard.min.js"></script>
<script src="{{ config.STATIC_URL }}/snappass/scripts/clipboard_button.js"></script>
<script src="{{ config.STATIC_URL }}/snappass/scripts/preview.js"></script>
{% endblock %}
{% endblock %}
14 changes: 7 additions & 7 deletions snappass/templates/set_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
{% block content %}
<div class="container">
<section>
<div class="page-header"><h1>Set Secret</h1></div>
<div class="page-header"><h1>{{ _('Set Secret') }}</h1></div>
<div class="row">
<form role="form" id="password_create" method="post" autocomplete="off">
<div class="col-sm-6 margin-bottom-10">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span></span>
<textarea rows="10" cols="50" id="password" name="password" autofocus="true" class="form-control" placeholder="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." aria-describedby="basic-addon1" autocomplete="off" required></textarea>
<textarea rows="10" cols="50" id="password" name="password" autofocus="true" class="form-control" placeholder="{{ _('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.') }}" aria-describedby="basic-addon1" autocomplete="off" required></textarea>
</div>
</div>

<div class="col-sm-2 margin-bottom-10">
<select class="form-control" name="ttl">
<option value="Two Weeks">Two Weeks</option>
<option value="Week" selected="selected">Week</option>
<option value="Day">Day</option>
<option value="Hour">Hour</option>
<option value="Two Weeks">{{ _('Two Weeks') }}</option>
<option value="Week" selected="selected">{{ _('Week') }}</option>
<option value="Day">{{ _('Day') }}</option>
<option value="Hour">{{ _('Hour') }}</option>
</select>
</div>

<div class="col-sm-4">
<button type="submit" class="btn btn-primary" id="submit">Generate URL</button>
<button type="submit" class="btn btn-primary" id="submit">{{ _('Generate URL') }}</button>
</div>
</form>
</div>
Expand Down
115 changes: 115 additions & 0 deletions snappass/translations/de/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# German translations 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-02-16 10:38+0100\n"
"PO-Revision-Date: 2024-02-16 09:29+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: de\n"
"Language-Team: de <LL@li.org>\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:2
msgid "en"
msgstr "de"

#: snappass/templates/base.html:4
msgid "Snappass - Share Secrets"
msgstr "Snappass - Passwort teilen"

#: snappass/templates/base.html:16
msgid "Share Secret"
msgstr "Passwort teilen"

#: snappass/templates/confirm.html:6
msgid "Share Secret Link"
msgstr "Geheimen Link teilen"

#: snappass/templates/confirm.html:7
msgid ""
"The secret has been temporarily saved. Send the following URL to your "
"intended recipient."
msgstr ""
"Das Geheimnis wurde vorübergehend gespeichert. Senden Sie die folgende URL an Ihre "
"gewünschten Empfänger."

#: snappass/templates/confirm.html:14
msgid "Copy to clipboard"
msgstr "In Zwischenablage kopieren"

#: snappass/templates/expired.html:6
msgid "Secret not found"
msgstr "Passwort nicht gefunden"

#: 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 ""
"Die angeforderte URL wurde auf dem Server nicht gefunden. Dies könnte daran liegen, dass dies"
"Die URL enthielt nie ein Passwort, oder weil sie abgelaufen ist oder offengelegt wurde "

#: 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 ""
"Wenn Ihnen diese URL von jemandem gesendet wurde, überprüfen Sie unbedingt Ihre Rechtschreibung "
"oder bitten Sie die Person, die es Ihnen geschickt hat, ein neues Passwort zu senden."

#: snappass/templates/preview.html:7
msgid "Secret"
msgstr "Geheim"

#: snappass/templates/preview.html:9
msgid "You can only reveal the secret once!"
msgstr "Du kannst das Passwort nur einmal lüften!"

#: snappass/templates/preview.html:12
msgid "Reveal secret"
msgstr "Passwort lüften"

#: snappass/templates/set_password.html:6
msgid "Set Secret"
msgstr "Geheimen Schlüssel festlegen"

#: 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 ""
"SnapPass ermöglicht es Ihnen, Passwörter auf sichere, kurzlebige Weise zu teilen. Input a "
"ein- oder mehrzeiliges Passwort, die Ablaufzeit und klicken Sie auf URL generieren."
"Teilen Sie die URL für den einmaligen Gebrauch mit dem beabsichtigten Empfänger."

#: snappass/templates/set_password.html:18
msgid "Two Weeks"
msgstr "Zwei Wochen"

#: snappass/templates/set_password.html:19
msgid "Week"
msgstr "Woche"

#: snappass/templates/set_password.html:20
msgid "Day"
msgstr "Tag"

#: snappass/templates/set_password.html:21
msgid "Hour"
msgstr "Stunde"

#: snappass/templates/set_password.html:26
msgid "Generate URL"
msgstr "URL generieren"

Loading
Loading