Add more translation hooks

This commit is contained in:
Jason McBrayer 2018-11-07 13:07:21 -05:00
parent c719b74a8e
commit 722b2d7a3d
4 changed files with 30 additions and 25 deletions

View File

@ -1,24 +1,25 @@
from django import forms
from django.conf import settings
from django.utils.translation import gettext as _
from pytz import common_timezones
from .models import Theme, Preference
PRIVACY_CHOICES = (('public', 'Public'),
('unlisted', 'Unlisted'),
('private', 'Private'),
('direct', 'Direct'))
PRIVACY_CHOICES = (('public', _('Public')),
('unlisted', _('Unlisted')),
('private', _('Private')),
('direct', _('Direct')))
timezones = [ (tz, tz) for tz in common_timezones]
class LoginForm(forms.Form):
instance = forms.CharField(label="Instance",
instance = forms.CharField(label=_("Instance"),
max_length=256)
email = forms.EmailField(label="Email")
email = forms.EmailField(label=_("Email"))
password = forms.CharField(widget=forms.PasswordInput())
class OAuthLoginForm(forms.Form):
instance = forms.CharField(label="Instance",
instance = forms.CharField(label=_("Instance"),
max_length=256)
class PreferencesForm(forms.ModelForm):
@ -31,24 +32,24 @@ class PostForm(forms.Form):
"""def status_post(self, status, in_reply_to_id=None, media_ids=None,
sensitive=False, visibility=None, spoiler_text=None):"""
status = forms.CharField(label="Toot", widget=forms.Textarea)
visibility = forms.ChoiceField(label="Toot visibility", choices=PRIVACY_CHOICES,
visibility = forms.ChoiceField(label=_("Toot visibility"), choices=PRIVACY_CHOICES,
required=False)
spoiler_text = forms.CharField(label="CW or Subject",
spoiler_text = forms.CharField(label=_("CW or Subject"),
required=False)
media_file_1 = forms.FileField(label = "Media 1",
media_file_1 = forms.FileField(label = _("Media 1"),
required=False)
media_text_1 = forms.CharField(label="Describe media 1.",
media_text_1 = forms.CharField(label=_("Describe media 1."),
required=False)
media_file_2 = forms.FileField(label = "Media 2",
media_file_2 = forms.FileField(label = _("Media 2"),
required=False)
media_text_2 = forms.CharField(label="Describe media 2.",
media_text_2 = forms.CharField(label=_("Describe media 2."),
required=False)
media_file_3 = forms.FileField(label = "Media 3",
media_file_3 = forms.FileField(label = _("Media 3"),
required=False)
media_text_3 = forms.CharField(label="Describe media 3.",
media_text_3 = forms.CharField(label=_("Describe media 3."),
required=False)
media_file_4 = forms.FileField(label = "Media 4",
media_file_4 = forms.FileField(label = _("Media 4"),
required=False)
media_text_4 = forms.CharField(label="Describe media 4.",
media_text_4 = forms.CharField(label=_("Describe media 4."),
required=False)
media_sensitive = forms.BooleanField(label="Sensitive media?", required=False)
media_sensitive = forms.BooleanField(label=_("Sensitive media?", required=False))

View File

@ -1,6 +1,7 @@
from datetime import datetime, timedelta
from django.utils.timezone import get_default_timezone, get_current_timezone, localtime
from django.utils.timezone import now as django_now
from django.utils.translation import gettext as _
from django import template
register = template.Library()
@ -24,6 +25,8 @@ def humane_time(arg):
It is not safe to use on future times.
FIXME: work out how best to make these strings translatable
'''
now = django_now()
arg = localtime(arg)
@ -52,14 +55,14 @@ def time_of_day(hour):
This is very english-centric and probably not translatable.
"""
if hour < 3:
return "wee hours"
return _("wee hours")
elif hour < 6:
return "early morning"
return _("early morning")
elif hour < 12:
return "morning"
return _("morning")
elif hour < 18:
return "afternoon"
return _("afternoon")
elif hour < 22:
return "evening"
return _("evening")
else:
return "night"
return _("night")

View File

@ -2,6 +2,7 @@ from django import template
from bs4 import BeautifulSoup
from urllib import parse
from django.urls import reverse
from django.utils.translation import gettext as _
from pdb import set_trace
register = template.Library()

View File

@ -5,7 +5,7 @@ from django.urls import reverse
from django.views.decorators.cache import never_cache, cache_page
from django.urls import reverse
from django.core.files.uploadhandler import TemporaryFileUploadHandler
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext as _
from brutaldon.forms import LoginForm, OAuthLoginForm, PreferencesForm, PostForm
from brutaldon.models import Client, Account, Preference, Theme
from mastodon import Mastodon, AttribAccessDict, MastodonError, MastodonAPIError