mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-20 06:08:35 +02:00
Simple gender handling in translations (for languages like french which need
this feature). Back to previous 'locale' location because it's not possible to access translations that are defined inside the 'templates' directory while scanning with django-admin.py from the 'admin' directory.
This commit is contained in:
+2
-1
@@ -1,6 +1,7 @@
|
||||
from django import forms
|
||||
from mailng.admin.models import Domain, Mailbox, Alias
|
||||
from django.utils.translation import ugettext as _
|
||||
from mailng.admin.templatetags.admin_extras import gender
|
||||
|
||||
class DomainForm(forms.ModelForm):
|
||||
class Meta:
|
||||
@@ -10,7 +11,7 @@ class MailboxForm(forms.ModelForm):
|
||||
quota = forms.IntegerField(label=_("Quota"), required=False)
|
||||
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
||||
password2 = forms.CharField(label=_("Confirmation"), widget=forms.PasswordInput)
|
||||
enabled = forms.BooleanField(label=_("Enabled"), required=False)
|
||||
enabled = forms.BooleanField(label=gender("Enabled", "f"), required=False)
|
||||
|
||||
class Meta:
|
||||
model = Mailbox
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,36 +1,21 @@
|
||||
from django import template
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
register = template.Library()
|
||||
|
||||
genders = {
|
||||
"Enabled" : (_("enabled_m"), _("enabled_f"))
|
||||
}
|
||||
|
||||
@register.simple_tag
|
||||
def domain_menu(domain_id, selection):
|
||||
return render_to_string('admin/domain_menu.html',
|
||||
{"selection" : selection,
|
||||
"domain_id" : domain_id})
|
||||
|
||||
|
||||
# class MyVar(template.Node):
|
||||
# def __init__(self, value, var_name):
|
||||
# self.var_name = var_name
|
||||
# self.value = value
|
||||
|
||||
# def render(self, context):
|
||||
# context[self.var_name] = self.value
|
||||
# return ""
|
||||
|
||||
# import re
|
||||
|
||||
# @register.tag(name="var")
|
||||
# def do_my_var(parser, token):
|
||||
# try:
|
||||
# tag_name, arg = token.contents.split(None, 1)
|
||||
# except ValueError:
|
||||
# raise template.TemplateSyntaxError, '%r tag requires arguments' \
|
||||
# % token.contents.split()[0]
|
||||
# m = re.search('(.*?) as (\w+)', arg)
|
||||
# if not m:
|
||||
# raise template.TemplateSyntaxError, "%r tag had invalid arguments" \
|
||||
# % tag_name
|
||||
# value, var_name = m.groups()
|
||||
# return MyVar(value, var_name)
|
||||
@register.filter
|
||||
def gender(value, target):
|
||||
if genders.has_key(value):
|
||||
return target == "m" and genders[value][0] or genders[value][1]
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user