Add support for i18n and l10n

The majority of the words on the site are user-generated, but I've tried
to surround everything else with localization calls. I don't know
another language so this will have to do until someone decides to
translate it lol

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-05-07 14:19:06 -07:00
parent bce5e6cdf6
commit fe8ea04d18
5 changed files with 33 additions and 13 deletions

View File

@@ -9,6 +9,7 @@ from django.core.files.base import ContentFile
from django.dispatch import receiver
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext as _
from PIL import Image
from io import BytesIO
@@ -152,11 +153,11 @@ class Post(models.Model):
# Make sure there is at least some content
self.text = self.text.strip()
if not (self.text or self.image):
raise ValidationError("Please either write a message or upload an image")
raise ValidationError(_("Please either write a message or upload an image"))
# Image upload size check
if self.image and self.image.size > settings.MAX_UPLOAD_SIZE:
raise ValidationError(
"Image supplied is too large. Maximum image size is %(max)s",
_("Image supplied is too large. Maximum image size is %(max)s"),
params={"max": settings.MAX_UPLOAD_SIZE},
)
# Rate limiting for posts
@@ -169,7 +170,8 @@ class Post(models.Model):
if delta < self.board.post_cooldown:
cooldown = self.board.post_cooldown - delta
raise ValidationError(
f"Please wait {int(cooldown.total_seconds())} seconds before posting again"
_(f"Please wait %(cooldown)s seconds before posting again"),
params={"cooldown": int(cooldown.total_seconds())},
)