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:
@@ -9,6 +9,7 @@ from django.core.files.base import ContentFile
|
|||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
@@ -152,11 +153,11 @@ class Post(models.Model):
|
|||||||
# Make sure there is at least some content
|
# Make sure there is at least some content
|
||||||
self.text = self.text.strip()
|
self.text = self.text.strip()
|
||||||
if not (self.text or self.image):
|
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
|
# Image upload size check
|
||||||
if self.image and self.image.size > settings.MAX_UPLOAD_SIZE:
|
if self.image and self.image.size > settings.MAX_UPLOAD_SIZE:
|
||||||
raise ValidationError(
|
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},
|
params={"max": settings.MAX_UPLOAD_SIZE},
|
||||||
)
|
)
|
||||||
# Rate limiting for posts
|
# Rate limiting for posts
|
||||||
@@ -169,7 +170,8 @@ class Post(models.Model):
|
|||||||
if delta < self.board.post_cooldown:
|
if delta < self.board.post_cooldown:
|
||||||
cooldown = self.board.post_cooldown - delta
|
cooldown = self.board.post_cooldown - delta
|
||||||
raise ValidationError(
|
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())},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{% extends "board/base.html" %}
|
{% extends "board/base.html" %}
|
||||||
{% load post_body %}
|
{% load post_body %}
|
||||||
|
{% load l10n %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% with title=board.url %}
|
{% with title=board.url %}
|
||||||
@@ -22,15 +23,21 @@
|
|||||||
<div class="column"> </div>
|
<div class="column"> </div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h2>Create a new thread</h2>
|
<h2>{% localize on %}Create a new thread{% endlocalize %}</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<form method="post" action="{% url 'board:board_detail' url=board.url %}" enctype="multipart/form-data">
|
<form method="post" action="{% url 'board:board_detail' url=board.url %}" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<table>
|
<table>
|
||||||
{{ form.as_table }}
|
{{ form.as_table }}
|
||||||
<tr><td> </td><td>Max image size: {{ max_upload_size|measure_bytes }}</td></tr>
|
<tr>
|
||||||
<tr><td> </td><td><input type="submit" value="Submit" /></td></tr>
|
<th> </th>
|
||||||
|
<td>
|
||||||
|
{% localize on %}Max image size{% endlocalize %}:
|
||||||
|
{{ max_upload_size|measure_bytes }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr><th> </th><td><input type="submit" value="Submit" /></td></tr>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{% extends "board/base.html" %}
|
{% extends "board/base.html" %}
|
||||||
{% load post_body %}
|
{% load post_body %}
|
||||||
|
{% load l10n %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% with title=board.url %}
|
{% with title=board.url %}
|
||||||
@@ -25,7 +26,13 @@
|
|||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<table>
|
<table>
|
||||||
{{ form.as_table }}
|
{{ form.as_table }}
|
||||||
<tr><td> </td><td><span class="post_form_image_specs">Max image size: {{ max_upload_size|measure_bytes }}</span></td></tr>
|
<tr>
|
||||||
|
<th> </th>
|
||||||
|
<td>
|
||||||
|
{% localize on %}Max image size{% endlocalize %}:
|
||||||
|
{{ max_upload_size|measure_bytes }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr><td> </td><td><input type="submit" value="Submit" /></td></tr>
|
<tr><td> </td><td><input type="submit" value="Submit" /></td></tr>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
{% load post_body %}
|
{% load post_body %}
|
||||||
|
{% load l10n %}
|
||||||
<div id="p{{post.id}}">
|
<div id="p{{post.id}}">
|
||||||
{# Image #}
|
{# Image #}
|
||||||
{% if post.thumbnail %}
|
{% if post.thumbnail %}
|
||||||
{# Image info #}
|
{# Image info #}
|
||||||
<div class="post_image_info">
|
<div class="post_image_info">
|
||||||
File: <a href="{{post.image.url}}" target="_blank">{{post.original_image_name}}</a>
|
{% localize on %}File{% endlocalize %}:
|
||||||
|
<a href="{{post.image.url}}" target="_blank">{{post.original_image_name}}</a>
|
||||||
({{post.image.size|measure_bytes}}, {{post.image_width}}x{{post.image_height}})
|
({{post.image.size|measure_bytes}}, {{post.image_width}}x{{post.image_height}})
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -23,17 +25,19 @@
|
|||||||
{% if post.subject %}
|
{% if post.subject %}
|
||||||
<span class="post_subject">{{post.subject}}</span>
|
<span class="post_subject">{{post.subject}}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
by <span class="post_name">{{post.name|default:"Anonymous"}}</span>
|
{% localize on %}by{% endlocalize %}
|
||||||
at {{post.created}}
|
<span class="post_name">{{post.name|default:"Anonymous"}}</span>
|
||||||
|
{% localize on %}at{% endlocalize %}
|
||||||
|
{{post.created}}
|
||||||
{% if reply_link %}
|
{% if reply_link %}
|
||||||
[<a href="{{post.get_absolute_url}}">Reply</a>]
|
[<a href="{{post.get_absolute_url}}">{% localize on %}Reply{% endlocalize %}</a>]
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# "X replies elided" dialog for OPs on the board #}
|
{# "X replies elided" dialog for OPs on the board #}
|
||||||
{% if replies_elided > 0 %}
|
{% if replies_elided > 0 %}
|
||||||
<br/>
|
<br/>
|
||||||
<span class="replies_elided">
|
<span class="replies_elided">
|
||||||
({{replies_elided}} replies elided, click reply to view)
|
({% localize on %}{{replies_elided}} replies elided, click reply to view{% endlocalize %})
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
|
|
||||||
LANGUAGE_CODE = "en-us"
|
LANGUAGE_CODE = "en-us"
|
||||||
|
|
||||||
TIME_ZONE = "UTC"
|
TIME_ZONE = "US/Pacific"
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user