Add translated strings
Some checks reported errors
continuous-integration/drone/push Build encountered an error
continuous-integration/drone Build is failing

This commit is contained in:
Jannis Portmann 2023-05-16 23:36:40 +02:00
parent db85a5f20a
commit 799f0be53e
21 changed files with 131 additions and 124 deletions

View file

@ -2,6 +2,7 @@ from django import forms
from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.forms import UserCreationForm
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from friendly_captcha.fields import FrcCaptchaField from friendly_captcha.fields import FrcCaptchaField
from django.utils.translation import gettext_lazy as _
from .models import Offer, PflaenzliUser, Wish from .models import Offer, PflaenzliUser, Wish
@ -22,11 +23,11 @@ class RegistrationForm(UserCreationForm):
class FilterForm(forms.Form): class FilterForm(forms.Form):
text = forms.CharField(max_length=128, required=False, label=mark_safe( text = forms.CharField(max_length=128, required=False, label=mark_safe(
'<i class="fa-solid fa-magnifying-glass"></i> Search')) f'<i class="fa-solid fa-magnifying-glass"></i> {_("Search")}'))
zipcode = forms.CharField(max_length=4, required=False, label=mark_safe( zipcode = forms.CharField(max_length=4, required=False, label=mark_safe(
'<i class="fa-solid fa-location-dot"></i> Zipcode')) f'<i class="fa-solid fa-location-dot"></i> {_("ZIP code")}'))
distance = forms.IntegerField(required=False, label=mark_safe( distance = forms.IntegerField(required=False, label=mark_safe(
'<i class="fa-solid fa-signs-post"></i> Distance (km)')) f'<i class="fa-solid fa-signs-post"></i> {_("Entfernung")} (km)'))
class WishForm(forms.ModelForm): class WishForm(forms.ModelForm):

View file

@ -1,6 +1,7 @@
from django.core.mail import EmailMessage, EmailMultiAlternatives from django.core.mail import EmailMessage, EmailMultiAlternatives
from django.urls import reverse from django.urls import reverse
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
def send_offer_email(request, offer, sender_user, recipient_user): def send_offer_email(request, offer, sender_user, recipient_user):
@ -9,7 +10,7 @@ def send_offer_email(request, offer, sender_user, recipient_user):
plain_text = get_offer_text(request, offer, sender_user, recipient_user) plain_text = get_offer_text(request, offer, sender_user, recipient_user)
message = EmailMultiAlternatives( message = EmailMultiAlternatives(
f'{sender_user.username} wants to trade', f'{sender_user.username} {_("wants to trade")}',
plain_text, plain_text,
'no-reply@pflaenz.li', 'no-reply@pflaenz.li',
[recipient_user.email], [recipient_user.email],
@ -22,4 +23,4 @@ def send_offer_email(request, offer, sender_user, recipient_user):
def get_offer_text(request, offer, sender_user, recipient_user): def get_offer_text(request, offer, sender_user, recipient_user):
return f"Hello {recipient_user.username},\n\nThe user {sender_user.username} would like to trade '{offer.title}' with you!\n\nIf you would like to trade with {sender_user.username}, just reply to this email to get in touch with them.\n\nYou can also view their offers here: {request.scheme}://{request.get_host()}{reverse('user_detail', args=[sender_user.id])}" return f"{_('Hello')} {recipient_user.username},\n\n{sender_user.username} {_('is interested in')} {offer.title}!\n\n{_('Checkout their offers')}: {request.scheme}://{request.get_host()}{reverse('user_detail', args=[sender_user.id])}\n\n{_('Contact')} {sender_user.username}, {_('by replying to this mail')}."

View file

@ -5,26 +5,27 @@ from django.dispatch import receiver
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from django.utils import timezone from django.utils import timezone
from django.core.files.storage import default_storage from django.core.files.storage import default_storage
from django.utils.translation import gettext_lazy as _
class PflaenzliUser(AbstractUser): class PflaenzliUser(AbstractUser):
email = models.EmailField(max_length=254) email = models.EmailField(max_length=254)
zipcode = models.PositiveIntegerField(blank=True, null=True) zipcode = models.PositiveIntegerField(blank=True, null=True, verbose_name=_('ZIP Code'))
class Offer(models.Model): class Offer(models.Model):
created = models.DateTimeField(default=timezone.now) created = models.DateTimeField(default=timezone.now)
user = models.ForeignKey(PflaenzliUser, on_delete=models.CASCADE) user = models.ForeignKey(PflaenzliUser, on_delete=models.CASCADE)
title = models.CharField(max_length=50) title = models.CharField(max_length=50, verbose_name=_('Title'))
description = models.TextField(max_length=5000) description = models.TextField(max_length=5000, verbose_name=_('Description'))
zipcode = models.IntegerField(blank=True, default=0) zipcode = models.IntegerField(blank=True, default=0, verbose_name=_('ZIP Code'))
image = models.ImageField(upload_to="uploads/") image = models.ImageField(upload_to="uploads/", verbose_name=_('Image'))
class Wish(models.Model): class Wish(models.Model):
created = models.DateTimeField(default=timezone.now) created = models.DateTimeField(default=timezone.now)
user = models.ForeignKey(PflaenzliUser, on_delete=models.CASCADE) user = models.ForeignKey(PflaenzliUser, on_delete=models.CASCADE)
title = models.CharField(max_length=200) title = models.CharField(max_length=200, verbose_name=_('Title'))
@receiver(models.signals.post_delete, sender=Offer) @receiver(models.signals.post_delete, sender=Offer)

View file

@ -1,5 +1,6 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load static %} {% load static %}
{% load i18n %}
{% block title %}Home{% endblock %} {% block title %}Home{% endblock %}
{% block meta %}<meta name="description" content="A platform to trade plants.">{% endblock %} {% block meta %}<meta name="description" content="A platform to trade plants.">{% endblock %}
{% block background %}home-background{% endblock %} {% block background %}home-background{% endblock %}
@ -9,18 +10,18 @@
<div class="home-background"></div> <div class="home-background"></div>
<div class="pfl-home-logo xl-align-self-center col-lg h-100 mb-3"></div> <div class="pfl-home-logo xl-align-self-center col-lg h-100 mb-3"></div>
<div class="col-lg"> <div class="col-lg">
<h1 class="display-5 fw-bold">Welcome to Pflänz.li</h1> <h1 class="display-5 fw-bold">{% trans "Welcome to Pflänz.li" %}</h1>
<p class="fs-4"> <p class="fs-4">
This is a platform to trade plants. You can offer plants and setup a wishlist what you want to trade it for. {% trans "This is a platform to trade plants. You can offer plants and setup a wishlist what you want to trade it for." %}
</p> </p>
<hr /> <hr />
<p>To offer your plants, please register first.</p> <p>{% trans "To offer your plants, please register first." %}</p>
<a href="{% url 'list_offers' %}" <a href="{% url 'list_offers' %}"
class="btn btn-pfl btn-lg mb-3" class="btn btn-pfl btn-lg mb-3"
type="button">Show Offers</a> type="button">{% trans "Offers" %}</a>
<a href="{% url 'register_user' %}" <a href="{% url 'register_user' %}"
class="btn btn-secondary btn-lg mb-3" class="btn btn-secondary btn-lg mb-3"
type="button">Register</a> type="button">{% trans "Register" %}</a>
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,4 +1,5 @@
{% load static %} {% load static %}
{% load i18n %}
<!doctype html> <!doctype html>
<html lang="en" class="h-100"> <html lang="en" class="h-100">
<head> <head>
@ -6,12 +7,6 @@
{% block title %}{% endblock %} {% block title %}{% endblock %}
</title> </title>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<!--
<link rel="icon" type="image/png" sizes="32x32" href="{% static 'favicons/favicon-32x32.png' %}">
<link rel="icon" type="image/png" sizes="16x16" href="{% static 'favicons/favicon-16x16.png' %}">
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'favicons/apple-touch-icon.' %}png">
<link rel="manifest" href="{% static 'favicons/manifest.json' %}">
-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css"
rel="stylesheet" rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD"
@ -44,6 +39,10 @@
sizes="16x16" sizes="16x16"
href="{% static 'favicon/favicon-16x16.png' %}"> href="{% static 'favicon/favicon-16x16.png' %}">
<link rel="manifest" href="{% static 'favicon/site.webmanifest' %}"> <link rel="manifest" href="{% static 'favicon/site.webmanifest' %}">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
crossorigin="anonymous"></script>
<script src="{% static 'bootstrap-color-toggler.js' %}"></script>
{% block head %}{% endblock %} {% block head %}{% endblock %}
</head> </head>
<body class="d-flex flex-column h-100 justify-content-between {% block background %}{% endblock background %}"> <body class="d-flex flex-column h-100 justify-content-between {% block background %}{% endblock background %}">
@ -61,17 +60,17 @@
data-bs-target="#navbarSupportedContent" data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-expanded="false"
aria-label="Toggle navigation"> aria-label="{% trans 'Toggle navigation' %}%">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
<div class="collapse navbar-collapse justify-content-between" <div class="collapse navbar-collapse justify-content-between"
id="navbarSupportedContent"> id="navbarSupportedContent">
<ul class="navbar-nav mr-auto"> <ul class="navbar-nav mr-auto">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{% url 'list_offers' %}"><i class="fa-solid fa-seedling"></i><span class="ms-2">Offers</span></a> <a class="nav-link" href="{% url 'list_offers' %}"><i class="fa-solid fa-seedling"></i><span class="ms-2">{% trans "Offers" %}</span></a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{% url 'create_offer' %}"><i class="fa-solid fa-square-plus"></i><span class="ms-2">New Offer</span></a> <a class="nav-link" href="{% url 'create_offer' %}"><i class="fa-solid fa-square-plus"></i><span class="ms-2">{% trans "New Offer" %}</span></a>
</li> </li>
</ul> </ul>
<ul class="navbar-nav mr-auto"> <ul class="navbar-nav mr-auto">
@ -82,7 +81,7 @@
aria-expanded="false" aria-expanded="false"
data-bs-toggle="dropdown" data-bs-toggle="dropdown"
data-bs-display="static"> data-bs-display="static">
<i class="fa-solid fa-circle-half-stroke"></i><span class="d-lg-none ms-2">Change theme</span> <i class="fa-solid fa-circle-half-stroke"></i><span class="d-lg-none ms-2">{% trans "Change theme" %}</span>
</button> </button>
<ul class="dropdown-menu dropdown-menu-end" <ul class="dropdown-menu dropdown-menu-end"
aria-labelledby="bd-theme" aria-labelledby="bd-theme"
@ -91,14 +90,14 @@
<button type="button" <button type="button"
class="dropdown-item d-flex align-items-center" class="dropdown-item d-flex align-items-center"
data-bs-theme-value="light"> data-bs-theme-value="light">
<i class="fa-solid fa-sun"></i><span class="ms-2">Light</span> <i class="fa-solid fa-sun"></i><span class="ms-2">{% trans "Light" %}</span>
</button> </button>
</li> </li>
<li> <li>
<button type="button" <button type="button"
class="dropdown-item d-flex align-items-center" class="dropdown-item d-flex align-items-center"
data-bs-theme-value="dark"> data-bs-theme-value="dark">
<i class="fa-solid fa-moon"></i><span class="ms-2">Dark</span> <i class="fa-solid fa-moon"></i><span class="ms-2">{% trans "Dark" %}</span>
</button> </button>
</li> </li>
<li> <li>
@ -128,7 +127,7 @@
</a> </a>
</li> </li>
<li class="dropdown-item"> <li class="dropdown-item">
<a class="nav-link" href="{% url 'wishlist' user.id %}"><i class="fa-solid fa-star"></i><span class="ms-2">Wishlist</span></a> <a class="nav-link" href="{% url 'wishlist' user.id %}"><i class="fa-solid fa-star"></i><span class="ms-2">{% trans "Wishlist" %}</span></a>
</li> </li>
</ul> </ul>
</li> </li>
@ -179,15 +178,11 @@
<a href="{% url 'faq' %}">FAQ</a> <a href="{% url 'faq' %}">FAQ</a>
</li> </li>
<li> <li>
<a href="{% url 'imprint' %}">Imprint</a> <a href="{% url 'imprint' %}">{% trans "Imprint" %}</a>
</li> </li>
</ul> </ul>
</div> </div>
</div> </div>
</footer> </footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
crossorigin="anonymous"></script>
<script src="{% static 'bootstrap-color-toggler.js' %}"></script>
</body> </body>
</html> </html>

View file

@ -1,4 +1,5 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n %}
{% block title %}Offer: {{ offer.title }}{% endblock %} {% block title %}Offer: {{ offer.title }}{% endblock %}
{% block meta %} {% block meta %}
<meta name="description" <meta name="description"
@ -6,7 +7,9 @@
<meta name="author" content="{{ offer.user.username }}"> <meta name="author" content="{{ offer.user.username }}">
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% if offer.user == request.user %}<div class="alert alert-info" role="alert">This is your offer!</div>{% endif %} {% if offer.user == request.user %}
<div class="alert alert-info" role="alert">{% trans "This is your offer!" %}</div>
{% endif %}
<div class="show-offer-container row gx-5"> <div class="show-offer-container row gx-5">
<div class="show-img-container col-12 col-md-6"> <div class="show-img-container col-12 col-md-6">
<img class="mb-3 img-fluid rounded" <img class="mb-3 img-fluid rounded"
@ -19,7 +22,7 @@
<p class="mr-3"> <p class="mr-3">
<i class="fas fa-user"></i> <i class="fas fa-user"></i>
{% if offer.user == user %} {% if offer.user == user %}
Me {% trans "You" %}
{% else %} {% else %}
{{ offer.user.username }} {{ offer.user.username }}
{% endif %} {% endif %}
@ -33,7 +36,7 @@
</p> </p>
{% endif %} {% endif %}
</div> </div>
<h3>Description</h3> <h3>{% trans "Description" %}</h3>
<p>{{ offer.description }}</p> <p>{{ offer.description }}</p>
</div> </div>
</div> </div>
@ -55,34 +58,34 @@
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Delete offer</h1> <h1 class="modal-title fs-5" id="exampleModalLabel">{% trans "Delete offer" %}</h1>
<button type="button" <button type="button"
class="btn-close" class="btn-close"
data-bs-dismiss="modal" data-bs-dismiss="modal"
aria-label="Close"></button> aria-label="{% trans 'Close' %}"></button>
</div> </div>
<div class="modal-body">Do you really want to delete this offer? This can't be undone.</div> <div class="modal-body">{% trans "Do you really want to delete this offer? This can't be undone." %}</div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans "Cancel" %}</button>
<a href="{% url 'offer_delete' offer.id %}" <a href="{% url 'offer_delete' offer.id %}"
type="button" type="button"
class="btn btn-danger">Delete</a> class="btn btn-danger">{% trans "Delete" %}</a>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{% else %} {% else %}
<h3>Wishes</h3> <h3>{% trans "Wishes" %}</h3>
<p>{{ offer.user.username }} would like some of the following in return:</p> <p>{{ offer.user.username }} {% trans "would like some of the following in return" %}:</p>
<div class="mb-3"> <div class="mb-3">
{% if wishes %} {% if wishes %}
<ul class="list-group"> <ul class="list-group">
{% for wish in wishes %}<li class="list-group-item">{{ wish.title }}</li>{% endfor %} {% for wish in wishes %}<li class="list-group-item">{{ wish.title }}</li>{% endfor %}
</ul> </ul>
{% else %} {% else %}
<div class="alert alert-warning" role="alert">There are currently no wishes!</div> <div class="alert alert-warning" role="alert">{% trans "There are currently no wishes!" %}</div>
{% endif %} {% endif %}
</div> </div>
<a class="btn btn-pfl mb-3" href="{% url 'offer_trade' offer.id %}">Offer trade</a> <a class="btn btn-pfl mb-3" href="{% url 'offer_trade' offer.id %}">{% trans "Offer trade" %}</a>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View file

@ -1,16 +0,0 @@
{% extends 'base.html.twig' %}
{% block title %}Edit offer{% endblock %}
{% block content %}
{% for message in app.flashes('error') %}
<div class="alert alert-error" role="alert">{{ message }}</div>
{% endfor %}
<h1 class="mb-3">Edit offer</h1>
{{ form_start(offer_form) }}
{{ form_row(offer_form.title) }}
{{ form_row(offer_form.zipCode) }}
{{ form_row(offer_form.description) }}
{{ form_row(offer_form.photo, {
label: 'Choose file'
}) }}
{{ form_end(offer_form) }}
{% endblock %}

View file

@ -1,17 +1,20 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load static %} {% load static %}
{% load i18n %}
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% block title %}Offers{% endblock %} {% block title %}
{% trans 'Filter' %}
{% endblock %}
{% block content %} {% block content %}
<h1 class="mt-3"> <h1 class="mt-3">
Offers {% trans 'Filter' %}
<button class="btn btn-pfl" <button class="btn btn-pfl"
type="button" type="button"
data-bs-toggle="collapse" data-bs-toggle="collapse"
data-bs-target="#filterCollapse" data-bs-target="#filterCollapse"
aria-expanded="true" aria-expanded="true"
aria-controls="filterCollapse"> aria-controls="filterCollapse">
<i class="fa-solid fa-filter"></i> Filter <i class="fa-solid fa-filter"></i> {% trans 'Filter' %}
</button> </button>
</h1> </h1>
<form method="post" <form method="post"
@ -20,7 +23,7 @@
id="filterCollapse"> id="filterCollapse">
{% csrf_token %} {% csrf_token %}
{{ form|crispy }} {{ form|crispy }}
<button type="submit" class="btn btn-pfl">Filter</button> <button type="submit" class="btn btn-pfl">{% trans 'Filter' %}</button>
</form> </form>
{% if offers %} {% if offers %}
<div class="row row-cols-1 row-cols-md-2 row-cols-xl-3 mt-3 mb-3 row-gap-5"> <div class="row row-cols-1 row-cols-md-2 row-cols-xl-3 mt-3 mb-3 row-gap-5">
@ -50,6 +53,6 @@
{% endfor %} {% endfor %}
</div> </div>
{% else %} {% else %}
<div class="alert alert-warning" role="alert">There are no active offers with the current filter.</div> <div class="alert alert-warning" role="alert">{% trans 'There are no active offers with the current filter.' %}</div>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View file

@ -1,13 +1,10 @@
<h1>Welcome to pflänz.li!</h1> <h1>{% trans "Welcome to pflänz.li" %}!</h1>
<h3>{% trans "Please confirm your email" %}</h3>
<h3>Please confirm your email</h3>
<p> <p>
Please confirm your email address by clicking the following link: <br><br> {% trans "Please confirm your email address by clicking the following link" %}:
<a href="{{ signedUrl|raw }}">Confirm my Email</a>. <br>
This link will expire in {{ expiresAtMessageKey|trans(expiresAtMessageData, 'VerifyEmailBundle') }}. <br>
</p> <a href="{{ signedUrl|raw }}">{% trans "Confirm my email" %}</a>.
{% trans "This link will expire in" %} {{ expiresAtMessageKey|trans(expiresAtMessageData, 'VerifyEmailBundle') }}.
<p>
Cheers!
</p> </p>
<p>Cheers!</p>

View file

@ -1,11 +1,14 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load i18n %}
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% block content %} {% block content %}
{% if next %} {% if next %}
{% if user.is_authenticated %} {% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed, please login with an account that has access.</p> <div class="alert alert-warning">
{% trans "Your account doesn't have access to this page. To proceed, please login with an account that has access." %}
</div>
{% else %} {% else %}
<p>Please login to see this page.</p> <div class="alert alert-info">{% trans "Please login to see this page." %}</div>
{% endif %} {% endif %}
{% endif %} {% endif %}
<h1 class="mb-3">Login</h1> <h1 class="mb-3">Login</h1>
@ -16,6 +19,6 @@
<input type="hidden" name="next" value="{{ next }}"> <input type="hidden" name="next" value="{{ next }}">
</form> </form>
<p> <p>
<a href="{% url 'password_reset' %}">Forgot password?</a> <a href="{% url 'password_reset' %}">{% trans "Forgot password?" %}</a>
</p> </p>
{% endblock %} {% endblock %}

View file

@ -1,5 +1,6 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n %}
{% block content %} {% block content %}
<h1>Reset password</h1> <h1>{% trans "Reset password" %}</h1>
<p>New password was set successfully. Please login again.</p> <p>{% trans "New password was set successfully. Please login again." %}</p>
{% endblock %} {% endblock %}

View file

@ -1,8 +1,9 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n %}
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% block content %} {% block content %}
<h1>Reset password</h1> <h1>{% trans "Reset password" %}</h1>
<p>Choose a new password.</p> <p>{% trans "Choose a new password." %}</p>
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form|crispy }} {{ form|crispy }}

View file

@ -1,5 +1,8 @@
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block title %}Register{% endblock %} {% load i18n %}
{% block title %}
{% trans "Register" %}
{% endblock %}
{% block meta %}<meta name="description" content="Register for pflänz.li" />{% endblock %} {% block meta %}<meta name="description" content="Register for pflänz.li" />{% endblock %}
{% block javascripts %}{{ encore_entry_script_tags('captcha') }}{% endblock %} {% block javascripts %}{{ encore_entry_script_tags('captcha') }}{% endblock %}
{% block content %} {% block content %}
@ -9,7 +12,7 @@
{% for message in app.flashes('error') %} {% for message in app.flashes('error') %}
<div class="alert alert-danger" role="alert">{{ message }}</div> <div class="alert alert-danger" role="alert">{{ message }}</div>
{% endfor %} {% endfor %}
<h1>Register</h1> <h1>{% trans "Register" %}</h1>
{{ form_start(registrationForm) }} {{ form_start(registrationForm) }}
{{ form_widget(registrationForm) }} {{ form_widget(registrationForm) }}
<div class="form-group row"> <div class="form-group row">

View file

@ -1,8 +1,9 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n %}
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% block content %} {% block content %}
<h1>Reset password</h1> <h1>{% trans "Reset password" %}</h1>
<p>Enter the email of your account, you'll then recieve a reset link.</p> <p>{% trans "Enter the email of your account, you'll then recieve a reset link." %}</p>
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form|crispy }} {{ form|crispy }}

View file

@ -1,10 +1,11 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n %}
{% block content %} {% block content %}
<h1>Reset password</h1> <h1>{% trans "Reset password" %}</h1>
<p> <p>
We've emailed you instructions for setting your password, if an account exists with the email you entered. You should receive them shortly. {% trans "We've emailed you instructions for setting your password, if an account exists with the email you entered. You should receive them shortly." %}
</p> </p>
<p> <p>
If you don't receive an email, please make sure you've entered the address you registered with, and check your spam folder. {% trans "If you don't receive an email, please make sure you've entered the address you registered with, and check your spam folder." %}
</p> </p>
{% endblock %} {% endblock %}

View file

@ -1,18 +1,19 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n %}
{% block title %}User{% endblock %} {% block title %}User{% endblock %}
{% block content %} {% block content %}
<h1 class="mb-4"> <h1 class="mb-4">
User details <span class="badge bg-secondary">{{ user.username }}</span> User details <span class="badge bg-secondary">{{ user.username }}</span>
</h1> </h1>
<div class="alert alert-warning">Some functions do not work yet!</div> <div class="alert alert-warning">{% trans "Some functions do not work yet!" %}</div>
<div class="mb-5"> <div class="mb-5">
<h2>Settings</h2> <h2>{% trans "Settings" %}</h2>
<a class="btn btn-pfl" href="{% url 'user_edit' %}">Edit Account</a> <a class="btn btn-pfl" href="{% url 'user_edit' %}">{% trans "Edit Account" %}</a>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<h2>Delete Account</h2> <h2>{% trans "Delete Account" %}</h2>
<button class="btn btn-danger"> <button class="btn btn-danger">
<i class="me-1 fa-solid fa-triangle-exclamation"></i>Delete Account <i class="me-1 fa-solid fa-triangle-exclamation"></i>{% trans "Delete Account" %}
</button> </button>
</div> </div>
{% endblock %} {% endblock %}

View file

@ -3,7 +3,7 @@
{% block title %}User {{ username }}{% endblock %} {% block title %}User {{ username }}{% endblock %}
{% block content %} {% block content %}
<div class="mb-3"> <div class="mb-3">
<h1>{{ user.username }}'s Profile</h1> <h1>{{ user.username }}'s {% trans "Profile" %}</h1>
</div> </div>
<h2 class="h3">Wishlist</h2> <h2 class="h3">Wishlist</h2>
<div class="mb-4"> <div class="mb-4">
@ -12,7 +12,7 @@
{% for wish in wishes %}<li class="list-group-item">{{ wish.title }}</li>{% endfor %} {% for wish in wishes %}<li class="list-group-item">{{ wish.title }}</li>{% endfor %}
</ul> </ul>
{% else %} {% else %}
<div class="alert alert-warning" role="alert">{{ user.username }} has currently no wishes!</div> <div class="alert alert-warning" role="alert">{{ user.username }} {% trans "has currently no wishes" %}!</div>
{% endif %} {% endif %}
</div> </div>
<div class="mb-3"> <div class="mb-3">
@ -46,6 +46,6 @@
{% endfor %} {% endfor %}
</div> </div>
{% else %} {% else %}
<div class="alert alert-warning" role="alert">There are currently no active offers.</div> <div class="alert alert-warning" role="alert">{% trans "There are currently no active offers" %}.</div>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View file

@ -1,5 +1,6 @@
<p>Hello {{ recipient_user.username }}</p> {% load i18n %}
<h1>{{ sender_user.username }} wants to trade '{{ offer.title }}'!</h1> <p>{% trans "Hello" %} {{ recipient_user.username }}</p>
<p>Checkout their offers:</p> <h1>{{ sender_user.username }} {% trans "is interested in" %} '{{ offer.title }}'!</h1>
<a href="{{ request.scheme }}://{{ request.get_host }}{% url 'user_detail' sender_user.id %}">Link</a> <p>{% trans "Checkout their offers" %}:</p>
<p>Just reply to get in contact with {{ sender_user.username }}.</p> <a href="{{ request.scheme }}://{{ request.get_host }}{% url 'user_detail' sender_user.id %}">{{ request.user.username }}'s {% trans "offers" %}</a>
<p>{% trans "Contact" %} {{ sender_user.username }} {% trans "by replying to this mail" %}.</p>

View file

@ -1,9 +1,12 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n %}
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% block title %}Whishlist{% endblock %} {% block title %}
{% trans "Wishlist" %}
{% endblock %}
{% block content %} {% block content %}
<div class="mb-3"> <div class="mb-3">
<h1>{{ title }} Wishlist</h1> <h1>{{ title }}</h1>
</div> </div>
<div class="mb-5"> <div class="mb-5">
{% if wishes %} {% if wishes %}
@ -25,19 +28,19 @@
{% endfor %} {% endfor %}
</ul> </ul>
{% else %} {% else %}
<div class="alert alert-warning" role="alert">There are currently no wishes!</div> <div class="alert alert-warning" role="alert">{% trans "There are currently no wishes!" %}</div>
{% endif %} {% endif %}
</div> </div>
{% if form %} {% if form %}
<hr class="mb-5"/> <hr class="mb-5"/>
<div class="mb-3"> <div class="mb-3">
<h3> <h3>
<i class="fas fa-star"></i> New wish <i class="fas fa-star"></i> {% trans "New wish" %}
</h3> </h3>
<form method="post" enctype="multipart/form-data"> <form method="post" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
{{ form|crispy }} {{ form|crispy }}
<button type="submit" class="btn btn-pfl">Add</button> <button type="submit" class="btn btn-pfl">{% trans "Add" %}</button>
</form> </form>
</div> </div>
{% endif %} {% endif %}

View file

@ -6,6 +6,8 @@ from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_protect from django.views.decorators.csrf import csrf_protect
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
from django.http import HttpResponseForbidden from django.http import HttpResponseForbidden
from django.utils.translation import gettext_lazy as _
from .forms import CreateOfferForm, RegistrationForm, FilterForm, WishForm from .forms import CreateOfferForm, RegistrationForm, FilterForm, WishForm
@ -38,12 +40,12 @@ def create_offer(request):
offer.user = request.user offer.user = request.user
offer.title = offer.title.title() offer.title = offer.title.title()
offer.save() offer.save()
messages.success(request, "Offer uploaded successfully!") messages.success(request, _("Offer uploaded successfully!"))
return redirect("offer_detail", offer.id) return redirect("offer_detail", offer.id)
else: else:
form = CreateOfferForm() form = CreateOfferForm()
return render(request, "basic_form.html", {"form": form, "button_label": "Create", "title": "Create Offer"}) return render(request, "basic_form.html", {"form": form, "button_label": _("Create"), "title": _("Create offer")})
def offer_detail(request, offer_id): def offer_detail(request, offer_id):
@ -71,7 +73,7 @@ def offer_delete(request, offer_id):
return HttpResponseForbidden() return HttpResponseForbidden()
offer.delete() offer.delete()
messages.success(request, "Offer deleted successfully!") messages.success(request, _("Offer deleted successfully!"))
return redirect("list_offers") return redirect("list_offers")
@ -88,12 +90,12 @@ def offer_edit(request, offer_id):
offer.image.name = generate_unique_filename(form.cleaned_data['image'].name) offer.image.name = generate_unique_filename(form.cleaned_data['image'].name)
offer.user = request.user offer.user = request.user
offer.save() offer.save()
messages.success(request, "Offer updated successfully!") messages.success(request, _("Offer updated successfully!"))
return redirect("offer_detail", offer.id) return redirect("offer_detail", offer.id)
else: else:
form = CreateOfferForm(instance=offer) form = CreateOfferForm(instance=offer)
return render(request, "basic_form.html", {"form": form, "button_label": "Update", "title": "Edit Offer"}) return render(request, "basic_form.html", {"form": form, "button_label": _("Save"), "title": _("Edit Offer")})
@login_required @login_required
@ -101,19 +103,19 @@ def wishlist(request, user_id):
wishes = Wish.objects.filter(user=user_id) wishes = Wish.objects.filter(user=user_id)
if user_id == request.user.id: if user_id == request.user.id:
title = "Your" title = _("Your wishlist")
if request.method == "POST": if request.method == "POST":
form = WishForm(request.POST) form = WishForm(request.POST)
if form.is_valid(): if form.is_valid():
wish = form.save(commit=False) wish = form.save(commit=False)
wish.user = request.user wish.user = request.user
wish.save() wish.save()
messages.success(request, "Wish added successfully!") messages.success(request, _("Wish added successfully!"))
form = WishForm() form = WishForm()
else: else:
form = None form = None
user = get_object_or_404(PflaenzliUser, id=user_id) user = get_object_or_404(PflaenzliUser, id=user_id)
title = f"{user.username}'s" title = f"{user.username}'s {_('wishlist')}"
return render(request, "user/wish.html", {"title": title, "form": form, "wishes": wishes, "own": user_id == request.user.id}) return render(request, "user/wish.html", {"title": title, "form": form, "wishes": wishes, "own": user_id == request.user.id})
@ -124,12 +126,12 @@ def user_edit(request):
form = RegistrationForm(request.POST, instance=request.user) form = RegistrationForm(request.POST, instance=request.user)
if form.is_valid(): if form.is_valid():
form.save() form.save()
messages.success(request, "Account details updated successfully!") messages.success(request, _("Account details updated successfully!"))
return redirect("user_profile") return redirect("user_profile")
else: else:
form = RegistrationForm(instance=request.user) form = RegistrationForm(instance=request.user)
return render(request, "basic_form.html", {"form": form, "button_label": "Save", "title": "Edit Account Details"}) return render(request, "basic_form.html", {"form": form, "button_label": _("Save"), "title": _("Edit Account Details")})
@csrf_protect @csrf_protect
@ -155,9 +157,9 @@ def offer_trade(request, offer_id):
if sender != recipient: if sender != recipient:
send_offer_email(request, offer, sender, recipient) send_offer_email(request, offer, sender, recipient)
messages.success(request, f"{recipient.username} was successfully notified") messages.success(request, f"{recipient.username} {_('was successfully notified')}!")
else: else:
messages.error(request, "You can't trade with yourself!") messages.error(request, _("You can't trade with yourself!"))
return redirect("offer_detail", offer_id) return redirect("offer_detail", offer_id)
@ -180,7 +182,7 @@ def register_user(request):
else: else:
form = RegistrationForm() form = RegistrationForm()
return render(request, "basic_form.html", {"form": form, "button_label": "Register", "title": "Registeration"}) return render(request, "basic_form.html", {"form": form, "button_label": _("Register"), "title": _("Registeration")})
def filter_offers(offers, form): def filter_offers(offers, form):

View file

@ -129,7 +129,11 @@ LOGOUT_REDIRECT_URL = "/"
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/ # https://docs.djangoproject.com/en/4.1/topics/i18n/
LANGUAGE_CODE = "en-us" LANGUAGE_CODE = 'de'
LANGUAGES = [
('de', 'German'),
('en', 'English'),
]
TIME_ZONE = "Europe/Zurich" TIME_ZONE = "Europe/Zurich"