* Issue #24: Add ability to localise queues so that the templates used

by those queues are in languages that differ from the installation 
  langugage. 

  To utilise this, call your templates 'zz:templatename' where 'zz' is the 
  language code and 'templatename' is the name used by the Helpdesk when 
  sending e-mails.

  Thanks to Paul Boehm for the submission.
This commit is contained in:
Ross Poulton 2008-11-18 01:43:50 +00:00
parent d5d692db45
commit 065e7e9eb0
6 changed files with 46 additions and 4 deletions

27
lib.py
View File

@ -49,20 +49,39 @@ def send_templated_mail(template_name, email_context, recipients, sender=None, b
from django.template import loader, Context
from helpdesk.models import EmailTemplate
import os
t = EmailTemplate.objects.get(template_name__iexact=template_name)
context = Context(email_context)
locale = getattr(context['queue'], 'locale', 'en')
if locale != 'en':
template_localized = template_name + ':' + locale
else:
template_localized = None
got_template = True
if template_localized:
try:
t = EmailTemplate.objects.get(templaet_name__iexact=template_localized)
except EmailTemplate.DoesNotExist:
got_template = False
if not got_template:
t = EmailTemplate.objects.get(template_name__iexact=template_name)
if not sender:
sender = settings.DEFAULT_FROM_EMAIL
context = Context(email_context)
footer_file = os.path.join('helpdesk', locale, 'email_text_footer.txt')
text_part = loader.get_template_from_string(
"%s{%% include 'helpdesk/email_text_footer.txt' %%}" % t.plain_text
"%s{%% include '%s' %%}" % (t.plain_text, footer_file)
).render(context)
email_html_base_file = os.path.join('helpdesk', locale, 'email_html_base.html')
html_part = loader.get_template_from_string(
"{%% extends 'helpdesk/email_html_base.html' %%}{%% block title %%}%s{%% endblock %%}{%% block content %%}%s{%% endblock %%}" % (t.heading, t.html)
"{%% extends '%s' %%}{%% block title %%}%s{%% endblock %%}{%% block content %%}%s{%% endblock %%}" % (email_html_base_file, t.heading, t.html)
).render(context)
subject_part = loader.get_template_from_string(

View File

@ -45,6 +45,14 @@ class Queue(models.Model):
'address for that mailbox.'),
)
locale = models.CharField(
_('Locale'),
max_length=10,
blank=True,
null=True,
help_text=_('Locale of this queue. All correspondence in this queue will be in this language.'),
)
allow_public_submission = models.BooleanField(
_('Allow Public Submission?'),
blank=True,

View File

@ -0,0 +1,9 @@
<h1 style='font-family: "Trebuchet MS", Arial, sans-serif; font-size: 14pt; color: #6593C0'>{% block header %}Helpdesk{% endblock %}</h1>
{% block content %}{% endblock %}
<p style='font-family: "Trebuchet MS", Arial, sans-serif; font-size: 11pt;'>Beste Gr&uuml;&szlig;e,</p>
<p style='font-family: "Trebuchet MS", Arial, sans-serif; font-size: 11pt;'><b>{{ queue.title }}</b>{% if queue.email_address %}<br><a href='mailto:{{ queue.email_address }}'>{{ queue.email_address }}</a>{% endif %}</p>
<p style='font-family: "Trebuchet MS", Arial, sans-serif; font-size: 9pt; color: #808080;' color='#808080'>Diese E-Mail wurde, im Einklang mit unserer Privacy-Policy an Dich als Benutzer unseres Support-Dienstes gesendet. Bitte teil uns mit falls du denkst, da&szlig; du diese E-Mail nicht bekommen h&auml;ttest sollen.</p>

View File

@ -0,0 +1,6 @@
Beste GrüÃe,
{{ queue.title }}{% if queue.email_address %}
{{ queue.email_address }}{% endif %}
Diese E-Mail wurde, im Einklang mit unserer Privacy-Policy an Dich als Benutzer unseres Support-Dienstes gesendet. Bitte teil uns mit falls du denkst, daà du diese E-Mail nicht bekommen hättest sollen.