Login and form translations

This commit is contained in:
Emily 2019-05-12 20:02:23 +01:00
parent 66e35cf83c
commit 9826d12466
4 changed files with 129 additions and 66 deletions

View File

@ -2,6 +2,7 @@ from wtforms import Form, BooleanField, StringField, PasswordField, TextAreaFiel
from wtforms.fields.html5 import DateField, DecimalField, IntegerField from wtforms.fields.html5 import DateField, DecimalField, IntegerField
from wtforms.widgets import TextArea from wtforms.widgets import TextArea
from flask_login import UserMixin from flask_login import UserMixin
from flask_babel import gettext as _
from objects import glob from objects import glob
@ -10,56 +11,56 @@ FORM_RENDER_KW = {
} }
class BillForm(Form): class BillForm(Form):
payment_to = StringField("Payment to", [validators.DataRequired()]) payment_to = StringField(_("Payment to"), [validators.DataRequired()])
description = TextAreaField("Description", render_kw = { description = TextAreaField(_("Description"), render_kw = {
"cols": 55, "cols": 55,
"rows": 8 "rows": 8
}) })
sum = DecimalField("Sum") sum = DecimalField(_("Sum"))
kid = IntegerField("KID") kid = IntegerField(_("KID"))
date_due = DateField("Date due") date_due = DateField(_("Date due"))
class LoginForm(Form): class LoginForm(Form):
email = StringField("Email", [ email = StringField(_("Email"), [
validators.DataRequired(), validators.DataRequired(),
validators.Length(min=6, max=254) validators.Length(min=6, max=254)
], ],
render_kw = FORM_RENDER_KW) render_kw = FORM_RENDER_KW)
password = PasswordField("Password", [ password = PasswordField(_("Password"), [
validators.DataRequired(), validators.DataRequired(),
validators.Length(min=4, max=127) validators.Length(min=4, max=127)
], ],
render_kw = FORM_RENDER_KW) render_kw = FORM_RENDER_KW)
class RegisterForm(Form): class RegisterForm(Form):
email = StringField("Email", [ email = StringField(_("Email"), [
validators.DataRequired(), validators.DataRequired(),
validators.Length(min=6, max=254) validators.Length(min=6, max=254)
], ],
render_kw = FORM_RENDER_KW) render_kw = FORM_RENDER_KW)
password = PasswordField("Password", [ password = PasswordField(_("Password"), [
validators.DataRequired(), validators.DataRequired(),
validators.Length(min=4, max=127), validators.Length(min=4, max=127),
validators.EqualTo("confirm_password", message = "Passwords must match") validators.EqualTo("confirm_password", message = _("Passwords must match"))
], ],
render_kw = FORM_RENDER_KW) render_kw = FORM_RENDER_KW)
confirm_password = PasswordField("Repeat Password", render_kw = FORM_RENDER_KW) confirm_password = PasswordField(_("Repeat Password"), render_kw = FORM_RENDER_KW)
firstname = StringField("Firstname", [ firstname = StringField(_("Firstname"), [
validators.DataRequired(), validators.DataRequired(),
validators.Length(min=2, max=30) validators.Length(min=2, max=30)
], ],
render_kw = FORM_RENDER_KW) render_kw = FORM_RENDER_KW)
surname = StringField("Surname", [ surname = StringField(_("Surname"), [
validators.DataRequired(), validators.DataRequired(),
validators.Length(min=2, max=30) validators.Length(min=2, max=30)
], ],
render_kw = FORM_RENDER_KW) render_kw = FORM_RENDER_KW)
accept_tos = BooleanField("I accept the TOS", [validators.DataRequired()]) accept_tos = BooleanField(_("I accept the TOS"), [validators.DataRequired()])
class User(UserMixin): class User(UserMixin):
id = -1 id = -1
@ -86,10 +87,10 @@ class User(UserMixin):
cur.close() cur.close()
if user is None: if user is None:
raise Exception("Invalid login") raise Exception(_("Invalid login"))
if not glob.check_password(login[1], user[2]): if not glob.check_password(login[1], user[2]):
raise Exception("Incorrect password") raise Exception(_("Incorrect password"))
self.id, self.email, self.password, self.firstname, self.surname = user self.id, self.email, self.password, self.firstname, self.surname = user

View File

@ -154,8 +154,8 @@ function toggleform(caller) {
</script> </script>
<div class="sidenav"> <div class="sidenav">
<div class="login-main-text"> <div class="login-main-text">
<h2>Husstanden<br>Login Page</h2> <h2>Husstanden<br>{{ _("Login Page") }}</h2>
<p>Login is required to use this service.</p> <p>{{ _("Login is required to use this service.") }}</p>
</div> </div>
<div class="btn-group dropup m-2"> <div class="btn-group dropup m-2">
<div> <div>
@ -205,7 +205,7 @@ function toggleform(caller) {
<div class="login-form"> <div class="login-form">
{% macro render_field(field) %} {% macro render_field(field) %}
<div class="form-group"> <div class="form-group">
{{ field.label }} <label for="{{ field.label.field_id }}">{{ _(field.label.text) }}</label>
{{ field(**kwargs)|safe }} {{ field(**kwargs)|safe }}
{% if field.errors %} {% if field.errors %}
<ul class=errors> <ul class=errors>
@ -220,8 +220,8 @@ function toggleform(caller) {
<form method="post"> <form method="post">
{{ render_field(form.login.email) }} {{ render_field(form.login.email) }}
{{ render_field(form.login.password) }} {{ render_field(form.login.password) }}
<button class="btn btn-black">Login</button> <button class="btn btn-black">{{ _("Login") }}</button>
<span class="btn btn-secondary" onclick="toggleform(this)">Register</span> <span class="btn btn-secondary" onclick="toggleform(this)">{{ _("Register") }}</span>
</form> </form>
<form method="post"> <form method="post">
{{ render_field(form.register.email) }} {{ render_field(form.register.email) }}
@ -230,8 +230,8 @@ function toggleform(caller) {
{{ render_field(form.register.firstname) }} {{ render_field(form.register.firstname) }}
{{ render_field(form.register.surname) }} {{ render_field(form.register.surname) }}
{{ render_field(form.register.accept_tos) }} {{ render_field(form.register.accept_tos) }}
<span class="btn btn-secondary" onclick="toggleform(this)">Login</span> <span class="btn btn-secondary" onclick="toggleform(this)">{{ _("Login") }}</span>
<button class="btn btn-black">Register</button> <button class="btn btn-black">{{ _("Register") }}</button>
</form> </form>
</div> </div>
</div> </div>

View File

@ -23,7 +23,9 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
{% macro render_field(field) %} {% macro render_field(field) %}
<dt><label for="{{ field.label.field_id }}">{{ _(field.label.text) }}</label> <dt>
<label for="{{ field.label.field_id }}">{{ _(field.label.text) }}</label>
</dt>
<dd>{{ field(**kwargs)|safe }} <dd>{{ field(**kwargs)|safe }}
{% if field.errors %} {% if field.errors %}
<ul class=errors> <ul class=errors>

View File

@ -4,7 +4,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 0.4\n" "Project-Id-Version: 0.4\n"
"Report-Msgid-Bugs-To: noreply@osufx.com\n" "Report-Msgid-Bugs-To: noreply@osufx.com\n"
"POT-Creation-Date: 2019-05-12 15:57+0200\n" "POT-Creation-Date: 2019-05-12 20:59+0200\n"
"PO-Revision-Date: 2015-05-12 09:47+1000\n" "PO-Revision-Date: 2015-05-12 09:47+1000\n"
"Last-Translator: Emily Steinsvik <emily@osufx.com>\n" "Last-Translator: Emily Steinsvik <emily@osufx.com>\n"
"Language: no\n" "Language: no\n"
@ -15,26 +15,110 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.6.0\n" "Generated-By: Babel 2.6.0\n"
#: routes.py:70 routes.py:91 #: routes.py:70
msgid "Already logged in" msgid "Already logged in"
msgstr "" msgstr "Allerede logget inn"
#: routes.py:84 #: routes.py:80
msgid "Logged in"
msgstr "Logget inn"
#: routes.py:102
msgid "User registered" msgid "User registered"
msgstr "Bruker registrert" msgstr "Bruker registrert"
#: routes.py:110 #: routes.py:89
msgid "Logged in"
msgstr "Logget inn"
#: routes.py:103
msgid "Logged out" msgid "Logged out"
msgstr "Logget ut" msgstr "Logget ut"
#: routes.py:115 #: routes.py:108
msgid "Login is required" msgid "Login is required"
msgstr "Innlogging kreves" msgstr "Innlogging kreves"
#: forms/login.py:14 templates/pages/bills.html:60
msgid "Payment to"
msgstr "Betaling til"
#: forms/login.py:15 templates/pages/bills.html:61
msgid "Description"
msgstr "Tekst"
#: forms/login.py:19 templates/pages/bills.html:62
msgid "Sum"
msgstr "Sum"
#: forms/login.py:20 templates/pages/bills.html:63
msgid "KID"
msgstr "KID"
#: forms/login.py:21 templates/pages/bills.html:64
msgid "Date due"
msgstr "Forfallsdato"
#: forms/login.py:24 forms/login.py:37
msgid "Email"
msgstr "Epost"
#: forms/login.py:30 forms/login.py:43
msgid "Password"
msgstr "Passord"
#: forms/login.py:46
msgid "Passwords must match"
msgstr "Passordene må være like"
#: forms/login.py:49
msgid "Repeat Password"
msgstr "Gjenta passord"
#: forms/login.py:51
msgid "Firstname"
msgstr "Fornavn"
#: forms/login.py:57
msgid "Surname"
msgstr "Etternavn"
#: forms/login.py:63
msgid "I accept the TOS"
msgstr "Jeg aksepterer TOS"
#: forms/login.py:90
msgid "Invalid login"
msgstr "Ugyldig innlogging"
#: forms/login.py:93
msgid "Incorrect password"
msgstr "Feil passord"
#: templates/login.html:157
msgid "Login Page"
msgstr "Innlogging"
#: templates/login.html:158
msgid "Login is required to use this service."
msgstr "Innlogging kreves for å bruke denne tjenesten."
#: templates/login.html:165
msgid "Language"
msgstr "Språk"
#: templates/layout/includes/top_nav.html:72 templates/login.html:174
msgid "english"
msgstr "engelsk"
#: templates/layout/includes/top_nav.html:80 templates/login.html:182
msgid "norwegian"
msgstr "norsk"
#: templates/login.html:223 templates/login.html:233
msgid "Login"
msgstr "Login"
#: templates/login.html:224 templates/login.html:234
msgid "Register"
msgstr "Registrer"
#: templates/layout/includes/side_nav.html:108 #: templates/layout/includes/side_nav.html:108
msgid "Dashboard" msgid "Dashboard"
msgstr "Dashbord" msgstr "Dashbord"
@ -56,47 +140,23 @@ msgstr "Kvitteringer"
msgid "Warranties" msgid "Warranties"
msgstr "Garantier" msgstr "Garantier"
#: templates/layout/includes/top_nav.html:72 #: templates/layout/includes/top_nav.html:100
msgid "english"
msgstr "engelsk"
#: templates/layout/includes/top_nav.html:78
msgid "norwegian"
msgstr "norsk"
#: templates/layout/includes/top_nav.html:98
msgid "Sign out" msgid "Sign out"
msgstr "Logg ut" msgstr "Logg ut"
#: templates/pages/bills.html:15 templates/pages/bills.html:45 #: templates/pages/bills.html:15 templates/pages/bills.html:47
msgid "Add" msgid "Add"
msgstr "Legg til" msgstr "Legg til"
#: templates/pages/bills.html:49 #: templates/pages/bills.html:21
msgid "Add bill"
msgstr "Legg til regning"
#: templates/pages/bills.html:51
msgid "Close" msgid "Close"
msgstr "Lukk" msgstr "Lukk"
#: templates/pages/bills.html:58 #: templates/pages/bills.html:65
msgid "Payment to"
msgstr "Betaling til"
#: templates/pages/bills.html:59
msgid "Description"
msgstr "Tekst"
#: templates/pages/bills.html:60
msgid "Sum"
msgstr "Sum"
#: templates/pages/bills.html:61
msgid "KID"
msgstr "KID"
#: templates/pages/bills.html:62
msgid "Date due"
msgstr "Forfallsdato"
#: templates/pages/bills.html:63
msgid "Payment status" msgid "Payment status"
msgstr "Betalingsstatus" msgstr "Betalingsstatus"