~martijnbraam/filedropper

a0e1a3c649656bba1594c05c1865079eab9c4e79 — Martijn Braam 3 months ago e8a4460
Add i18n
M filedropper/__init__.py => filedropper/__init__.py +12 -1
@@ 5,8 5,9 @@ import logging
import getpass

import click
from flask import Flask
from flask import Flask, request, g
from flask.cli import with_appcontext
from flask_babel import Babel, gettext
from flask_login import LoginManager

from filedropper.config import Config


@@ 36,6 37,11 @@ db = SQLAlchemy(app)
login_manager = LoginManager(app)
login_manager.login_view = 'authentication.login'
migrate = Migrate(app, db, render_as_batch=True)
babel = Babel(app)

login_manager.login_message = gettext("Please log in to access this page.")
gettext("Username")
gettext("Password")

from filedropper import models
from filedropper.frontend.authentication import blueprint_auth


@@ 85,6 91,11 @@ def load_user(user_id):
    return models.User.get(user_id)


@babel.localeselector
def get_locale():
    return request.accept_languages.best_match(['nl', 'en'])


@app.cli.command('create-user')
@click.argument("username")
@click.option("--admin/--no-admin", default=False)

A filedropper/babel.cfg => filedropper/babel.cfg +3 -0
@@ 0,0 1,3 @@
[python: **.py]
[jinja2: **/templates/**.html]
encoding=utf8
\ No newline at end of file

M filedropper/templates/base-center.html => filedropper/templates/base-center.html +7 -3
@@ 11,12 11,16 @@
        <header class="home">
            <div class="currentuser">
                {% if current_user.is_authenticated %}
                    Logged in as:
                    {{ gettext("Logged in as") }}:
                    <a href="#" class="username">{{ current_user.username }}</a>
                    &mdash;
                    <a href="{{ url_for('authentication.logout') }}">Log out</a>
                    <a href="{{ url_for('authentication.logout') }}">
                        {{ gettext("Log out") }}
                    </a>
                {% else %}
                    <a href="{{ url_for('authentication.login') }}">Log in</a>
                    <a href="{{ url_for('authentication.login') }}">
                        {{ gettext("Log in") }}
                    </a>
                {% endif %}
            </div>
        </header>

M filedropper/templates/base.html => filedropper/templates/base.html +8 -4
@@ 10,17 10,21 @@
        <header>
            <div class="currentuser">
                {% if current_user.is_authenticated %}
                    Logged in as:
                    {{ gettext("Logged in as") }}:
                    <a href="#" class="username">{{ current_user.username }}</a>
                    &mdash;
                    <a href="{{ url_for('authentication.logout') }}">Log out</a>
                    <a href="{{ url_for('authentication.logout') }}">
                        {{ gettext("Log out") }}
                    </a>
                {% else %}
                    <a href="{{ url_for('authentication.login') }}">Log in</a>
                    <a href="{{ url_for('authentication.login') }}">
                        {{ gettext("Log in") }}
                    </a>
                {% endif %}
            </div>

            <div class="branding">
                <span><a href="/" class="brand">Filedropper</a></span>
                <span><a href="/" class="brand">{{ gettext("Filedropper") }}</a></span>
                <nav>
                    {% include "navigation.html" %}
                </nav>

M filedropper/templates/bin-admin.html => filedropper/templates/bin-admin.html +14 -10
@@ 1,48 1,52 @@
{% extends "base-center.html" %}

{% block title %}{% if new %}Create{% else %}Edit{% endif %} bin{% endblock %}
{% block title %}{% if new %}{{ gettext("Create bin") }}{% else %}{{ gettext("Edit bin") }}{% endif %}{% endblock %}

{% block main %}
    <form class="nice wide separators" method="post">
        <div>
            <label for="name">Name</label>
            <label for="name">{{ gettext("Name") }}</label>
            <input type="text" name="name" id="name" value="{{ bin.name }}">
        </div>
        <hr>

        <div>
            <label for="guest"><input type="checkbox" name="guest" id="guest"
                                      {% if bin.guest_upload %}checked{% endif %}> Allow guest uploads</label>
                                      {% if bin.guest_upload %}checked{% endif %}>
                {{ gettext("Allow guest uploads") }}
            </label>
        </div>
        <div>
            <label for="quota">Bin quota in megabytes, supports G and T suffix</label>
            <label for="quota">{{ gettext("Bin quota in megabytes, supports G and T suffix") }}</label>
            {% if bin.quota %}
                <input type="text" name="quota" id="quota" class="filesize" value="{{ bin.quota|filesizeformat(True) }}">
                <input type="text" name="quota" id="quota" class="filesize"
                       value="{{ bin.quota|filesizeformat(True) }}">
            {% else %}
                <input type="text" name="quota" id="quota" class="filesize">
            {% endif %}
        </div>
        <hr>
        <div>
            <label for="expire_upload">Expire files after upload [days]</label>
            <label for="expire_upload">{{ gettext("Expire files after upload [days]") }}</label>
            <input type="number" name="expire_upload" id="expire_upload" value="{{ bin.expire_after_upload }}">
        </div>

        <div>
            <label for="expire_download">Expire files after last download [days]</label>
            <label for="expire_download">{{ gettext("Expire files after last download [days]") }}</label>
            <input type="number" name="expire_download" id="expire_download"
                   value="{{ bin.expire_after_last_download }}">
        </div>

        <div>
            <label for="delete"><input type="checkbox" name="delete" id="delete"
                                       {% if bin.remove_after_last_file %}checked{% endif %}> Delete bin after all files
                expire</label>
                                       {% if bin.remove_after_last_file %}checked{% endif %}>
                {{ gettext("Delete bin after all files expire") }}
            </label>
        </div>


        <div>
            <input type="submit" value="Save">
            <input type="submit" value="{{ gettext("Save") }}">
        </div>
    </form>
{% endblock %}
\ No newline at end of file

M filedropper/templates/bin.html => filedropper/templates/bin.html +12 -6
@@ 11,11 11,13 @@
                    <td>
                        <a href="{{ url_for('home.download', id=bin.id, filename=file.name) }}">{{ file.name }}</a>
                        {% if delta_created %}
                            <div class="expire">Expires
                                in {{ ((delta_created - (now - file.created)) | string).split('.')[0] }}</div>
                            <div class="expire">
                                {{ gettext("Expires in %(time)s", time=((delta_created - (now - file.created)) | string).split('.')[0]) }}
                            </div>
                        {% elif delta_last %}
                            <div class="expire">Expires
                                in {{ ((delta_last - (now - file.created)) | string).split('.')[0] }}</div>
                            <div class="expire">
                                {{ gettext("Expires in %(time)s", time=((delta_last - (now - file.created)) | string).split('.')[0]) }}
                            </div>
                        {% endif %}
                    </td>
                    <td>


@@ 45,12 47,12 @@
    </div>

    <div class="description" {% if bin.files %}style="display: none;"{% endif %} id="nofiles">
        No files have been uploaded yet.
        {{ gettext("No files have been uploaded yet.") }}
    </div>

    {% if admin %}
        <div class="description">
            <a href="{{ url_for('home.manage_bin', id=bin.id) }}">Manage bin</a>
            <a href="{{ url_for('home.manage_bin', id=bin.id) }}">{{ gettext("Manage bin") }}</a>
        </div>
    {% endif %}



@@ 165,6 167,10 @@
                    tbody.appendChild(row);
                },
            };




        </script>
    {% endif %}
{% endblock %}
\ No newline at end of file

M filedropper/templates/index.html => filedropper/templates/index.html +4 -4
@@ 1,6 1,6 @@
{% extends "base-center.html" %}

{% block title %}Filedropper{% endblock %}
{% block title %}{{ gettext("Filedropper") }}{% endblock %}

{% block header %}
{% endblock %}


@@ 14,14 14,14 @@
            <h2><a href="{{ url_for('home.bin', id=bin.id) }}">{{ bin.name }}</a></h2>

            {% if bin.files %}
                {{ bin.files | count }} file(s)
                {{ ngettext("%(num)s file", "%(num)s files", bin.files | count) }}
            {% else %}
                No files have been added.
                {{ gettext("No files have been added.") }}
            {% endif %}
        </div>
    {% else %}
        <div class="description">
            No bins have been created yet. Create a new bin to send or receive files.
            {{ gettext("No bins have been created yet. Create a new bin to send or receive files.") }}
        </div>
    {% endfor %}
{% endblock %}
\ No newline at end of file

M filedropper/templates/login.html => filedropper/templates/login.html +2 -2
@@ 1,9 1,9 @@
{% extends "base.html" %}

{% block title %}Login{% endblock %}
{% block title %}{{ gettext("Log in") }}{% endblock %}

{% block main %}
    <h1>Login</h1>
    <h1>{{ gettext("Log in") }}</h1>
    <form method="post" class="nice">
        {% include "flash.html" %}
        {{ form.csrf_token }}

M filedropper/templates/navigation.html => filedropper/templates/navigation.html +2 -2
@@ 1,4 1,4 @@
{% if current_user.is_admin %}
    <a href="{{ url_for('home.home') }}">Bins</a>
    <a href="{{ url_for('home.create_bin') }}">Create bin</a>
    <a href="{{ url_for('home.home') }}">{{ gettext("Bins") }}</a>
    <a href="{{ url_for('home.create_bin') }}">{{ gettext("Create bin") }}</a>
{% endif %}

A filedropper/translations/nl/LC_MESSAGES/messages.po => filedropper/translations/nl/LC_MESSAGES/messages.po +119 -0
@@ 0,0 1,119 @@
# Dutch translations for PROJECT.
# Copyright (C) 2022 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2022.
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-08-07 12:39+0200\n"
"PO-Revision-Date: 2022-08-07 12:31+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: nl\n"
"Language-Team: nl <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.10.3\n"

#: __init__.py:42
msgid "Please log in to access this page."
msgstr "Log in om deze pagina te bekijken."

#: __init__.py:43
msgid "Username"
msgstr "Gebruikersnaam"

#: __init__.py:44
msgid "Password"
msgstr "Wachtwoord"

#: templates/base-center.html:14 templates/base.html:13
msgid "Logged in as"
msgstr "Ingelogt als"

#: templates/base-center.html:18 templates/base.html:17
msgid "Log out"
msgstr "Log uit"

#: templates/base-center.html:22 templates/base.html:21 templates/login.html:3
#: templates/login.html:6
msgid "Log in"
msgstr "Log in"

#: templates/base.html:27 templates/index.html:3
msgid "Filedropper"
msgstr "Bestanden"

#: templates/bin-admin.html:3 templates/navigation.html:3
msgid "Create bin"
msgstr "Maak map"

#: templates/bin-admin.html:3
msgid "Edit bin"
msgstr "Bewerk map"

#: templates/bin-admin.html:8
msgid "Name"
msgstr "Naam"

#: templates/bin-admin.html:16
msgid "Allow guest uploads"
msgstr "Gast uploads toestaan"

#: templates/bin-admin.html:20
msgid "Bin quota in megabytes, supports G and T suffix"
msgstr "Mapgrootte in megabytes"

#: templates/bin-admin.html:30
msgid "Expire files after upload [days]"
msgstr "Bestanden vervallen x dagen na upload"

#: templates/bin-admin.html:35
msgid "Expire files after last download [days]"
msgstr "Bestanden vervallen x dagen na de laatste download"

#: templates/bin-admin.html:43
msgid "Delete bin after all files expire"
msgstr "Map verwijderen als alle bestanden zijn vervallen"

#: templates/bin-admin.html:49
msgid "Save"
msgstr "Opslaan"

#: templates/bin.html:15 templates/bin.html:19
#, python-format
msgid "Expires in %(time)s"
msgstr "Verloopt in %(time)s"

#: templates/bin.html:50
msgid "No files have been uploaded yet."
msgstr "Er zijn nog geen bestanden geupload."

#: templates/bin.html:55
msgid "Manage bin"
msgstr "Map beheren"

#: templates/index.html:17
#, python-format
msgid "%(num)s file"
msgid_plural "%(num)s files"
msgstr[0] "%(num)s bestand"
msgstr[1] "%(num)s bestanden"

#: templates/index.html:19
msgid "No files have been added."
msgstr "Er zijn nog geen bestanden toegevoegt"

#: templates/index.html:24
msgid "No bins have been created yet. Create a new bin to send or receive files."
msgstr ""
"Er zij nog geen mappen gemaakt. Maak een nieuwe map om bestanden te "
"verzenden of ontvangen"

#: templates/navigation.html:2
msgid "Bins"
msgstr "Mappen"


M requirements.txt => requirements.txt +1 -0
@@ 3,5 3,6 @@ Flask-Login
Flask-Migrate
Flask-Wtf
Flask-Sqlalchemy
Flask-Babel
Sqlalchemy-utils
apscheduler
\ No newline at end of file