From f75a7e08cd54cdcb391fb419a42a7589478fae20 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Thu, 16 Jan 2014 15:52:44 -0500 Subject: [PATCH] Internationalize forums mustache templates --- conf/locale/babel.cfg | 2 ++ .../django_comment_client/helpers.py | 23 ++++++++++++++----- .../discussion/_inline_new_post.html | 1 + lms/templates/discussion/_new_post.html | 1 + .../mustache/_inline_discussion.mustache | 17 +++++++------- .../_inline_discussion_cohorted.mustache | 20 ++++++++-------- .../mustache/_inline_thread.mustache | 12 ++++++---- .../mustache/_inline_thread_cohorted.mustache | 12 ++++++---- .../mustache/_inline_thread_show.mustache | 22 ++++++++++-------- .../discussion/mustache/_pagination.mustache | 10 ++++---- .../mustache/_profile_thread.mustache | 11 +++++---- 11 files changed, 79 insertions(+), 52 deletions(-) diff --git a/conf/locale/babel.cfg b/conf/locale/babel.cfg index 6631586ad4..039ef1aa5f 100644 --- a/conf/locale/babel.cfg +++ b/conf/locale/babel.cfg @@ -15,6 +15,8 @@ input_encoding = utf-8 [mako: lms/templates/**.html] input_encoding = utf-8 +[mako: lms/templates/**.mustache] +input_encoding = utf-8 [mako: common/templates/**.html] input_encoding = utf-8 [mako: cms/templates/emails/**.txt] diff --git a/lms/djangoapps/django_comment_client/helpers.py b/lms/djangoapps/django_comment_client/helpers.py index 2a045d27fd..2d5f87ee19 100644 --- a/lms/djangoapps/django_comment_client/helpers.py +++ b/lms/djangoapps/django_comment_client/helpers.py @@ -1,6 +1,7 @@ from django.conf import settings from .mustache_helpers import mustache_helpers from functools import partial +from mako.template import Template from .utils import extend_content, merge_dict, render_mustache import django_comment_client.settings as cc_settings @@ -12,11 +13,21 @@ import os def include_mustache_templates(): mustache_dir = settings.PROJECT_ROOT / 'templates' / 'discussion' / 'mustache' - valid_file_name = lambda file_name: file_name.endswith('.mustache') - read_file = lambda file_name: (file_name, open(mustache_dir / file_name, "r").read()) - strip_file_name = lambda x: (x[0].rpartition('.')[0], x[1]) - wrap_in_tag = lambda x: "".format(x[0], x[1]) - file_contents = map(read_file, filter(valid_file_name, os.listdir(mustache_dir))) - return '\n'.join(map(wrap_in_tag, map(strip_file_name, file_contents))) + def is_valid_file_name(file_name): + return file_name.endswith('.mustache') + def read_file(file_name): + return open(mustache_dir / file_name, "r").read().decode('utf-8') + def template_id_from_file_name(file_name): + return file_name.rpartition('.')[0] + def process_mako(template_content): + return Template(template_content).render_unicode() + def make_script_tag(id, content): + return u"".format(id, content) + + return u'\n'.join( + make_script_tag(template_id_from_file_name(file_name), process_mako(read_file(file_name))) + for file_name in os.listdir(mustache_dir) + if is_valid_file_name(file_name) + ) diff --git a/lms/templates/discussion/_inline_new_post.html b/lms/templates/discussion/_inline_new_post.html index 370041866c..ae108a4d78 100644 --- a/lms/templates/discussion/_inline_new_post.html +++ b/lms/templates/discussion/_inline_new_post.html @@ -15,6 +15,7 @@ %endif %if is_course_cohorted:
+ ## Translators: This labels the selector for which group of students can view a post ${_("Make visible to:")} diff --git a/lms/templates/discussion/mustache/_inline_discussion.mustache b/lms/templates/discussion/mustache/_inline_discussion.mustache index 58d5f6f6d0..62948bec7a 100644 --- a/lms/templates/discussion/mustache/_inline_discussion.mustache +++ b/lms/templates/discussion/mustache/_inline_discussion.mustache @@ -1,3 +1,5 @@ +<%! from django.utils.translation import ugettext as _ %> +
@@ -6,22 +8,21 @@
- +
-
- +
- - Cancel + + ${_("Cancel")}
- +
{{#allow_anonymous}} - + {{/allow_anonymous}} {{#allow_anonymous_to_peers}} - + {{/allow_anonymous_to_peers}}
diff --git a/lms/templates/discussion/mustache/_inline_discussion_cohorted.mustache b/lms/templates/discussion/mustache/_inline_discussion_cohorted.mustache index 6eab3f10cc..cb75c6f20b 100644 --- a/lms/templates/discussion/mustache/_inline_discussion_cohorted.mustache +++ b/lms/templates/discussion/mustache/_inline_discussion_cohorted.mustache @@ -1,3 +1,5 @@ +<%! from django.utils.translation import ugettext as _ %> +
@@ -6,26 +8,26 @@
- +
-
- +
- - Cancel + + ${_("Cancel")}
- +
{{#allow_anonymous}} - + {{/allow_anonymous}} {{#allow_anonymous_to_peers}} - + {{/allow_anonymous_to_peers}}
- Make visible to: + ## Translators: This labels the selector for which group of students can view a post + ${_("Make visible to:")}