Commit dfa4a03d by jsa

i18n: externalize strings in discussion forums templates and python code.

JIRA: FOR-398, FOR-399
parent ee1651da
...@@ -5,16 +5,16 @@ from django.contrib.auth.models import User ...@@ -5,16 +5,16 @@ from django.contrib.auth.models import User
from django.dispatch import receiver from django.dispatch import receiver
from django.db.models.signals import post_save from django.db.models.signals import post_save
from django.utils.translation import ugettext_noop
from student.models import CourseEnrollment from student.models import CourseEnrollment
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.course_module import CourseDescriptor from xmodule.course_module import CourseDescriptor
FORUM_ROLE_ADMINISTRATOR = 'Administrator' FORUM_ROLE_ADMINISTRATOR = ugettext_noop('Administrator')
FORUM_ROLE_MODERATOR = 'Moderator' FORUM_ROLE_MODERATOR = ugettext_noop('Moderator')
FORUM_ROLE_COMMUNITY_TA = 'Community TA' FORUM_ROLE_COMMUNITY_TA = ugettext_noop('Community TA')
FORUM_ROLE_STUDENT = 'Student' FORUM_ROLE_STUDENT = ugettext_noop('Student')
@receiver(post_save, sender=CourseEnrollment) @receiver(post_save, sender=CourseEnrollment)
......
...@@ -197,7 +197,7 @@ def create_comment(request, course_id, thread_id): ...@@ -197,7 +197,7 @@ def create_comment(request, course_id, thread_id):
""" """
if cc_settings.MAX_COMMENT_DEPTH is not None: if cc_settings.MAX_COMMENT_DEPTH is not None:
if cc_settings.MAX_COMMENT_DEPTH < 0: if cc_settings.MAX_COMMENT_DEPTH < 0:
return JsonError("Comment level too deep") return JsonError(_("Comment level too deep"))
return _create_comment(request, course_id, thread_id=thread_id) return _create_comment(request, course_id, thread_id=thread_id)
...@@ -273,7 +273,7 @@ def create_sub_comment(request, course_id, comment_id): ...@@ -273,7 +273,7 @@ def create_sub_comment(request, course_id, comment_id):
""" """
if cc_settings.MAX_COMMENT_DEPTH is not None: if cc_settings.MAX_COMMENT_DEPTH is not None:
if cc_settings.MAX_COMMENT_DEPTH <= cc.Comment.find(comment_id).depth: if cc_settings.MAX_COMMENT_DEPTH <= cc.Comment.find(comment_id).depth:
return JsonError("Comment level too deep") return JsonError(_("Comment level too deep"))
return _create_comment(request, course_id, parent_id=comment_id) return _create_comment(request, course_id, parent_id=comment_id)
...@@ -579,7 +579,7 @@ def upload(request, course_id): # ajax upload file to a question or answer ...@@ -579,7 +579,7 @@ def upload(request, course_id): # ajax upload file to a question or answer
error = _('Error uploading file. Please contact the site administrator. Thank you.') error = _('Error uploading file. Please contact the site administrator. Thank you.')
if error == '': if error == '':
result = 'Good' result = _('Good')
file_url = file_storage.url(new_file_name) file_url = file_storage.url(new_file_name)
parsed_url = urlparse.urlparse(file_url) parsed_url = urlparse.urlparse(file_url)
file_url = urlparse.urlunparse( file_url = urlparse.urlunparse(
......
...@@ -131,7 +131,7 @@ def inline_discussion(request, course_id, discussion_id): ...@@ -131,7 +131,7 @@ def inline_discussion(request, course_id, discussion_id):
cohorts_list = list() cohorts_list = list()
if is_cohorted: if is_cohorted:
cohorts_list.append({'name': 'All Groups', 'id': None}) cohorts_list.append({'name': _('All Groups'), 'id': None})
#if you're a mod, send all cohorts and let you pick #if you're a mod, send all cohorts and let you pick
...@@ -309,7 +309,7 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -309,7 +309,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
'cohorted_commentables': cohorted_commentables 'cohorted_commentables': cohorted_commentables
} }
return render_to_response('discussion/single_thread.html', context) return render_to_response('discussion/index.html', context)
@login_required @login_required
......
...@@ -9,18 +9,6 @@ import pystache_custom as pystache ...@@ -9,18 +9,6 @@ import pystache_custom as pystache
import urllib import urllib
import os import os
# This method is used to pluralize the words "discussion" and "comment"
# when referring to how many discussion threads or comments the user
# has contributed to.
def pluralize(singular_term, count):
if int(count) >= 2 or int(count) == 0:
return singular_term + 's'
return singular_term
# TODO there should be a better way to handle this
def include_mustache_templates(): def include_mustache_templates():
mustache_dir = settings.PROJECT_ROOT / 'templates' / 'discussion' / 'mustache' mustache_dir = settings.PROJECT_ROOT / 'templates' / 'discussion' / 'mustache'
...@@ -31,3 +19,4 @@ def include_mustache_templates(): ...@@ -31,3 +19,4 @@ def include_mustache_templates():
file_contents = map(read_file, filter(valid_file_name, os.listdir(mustache_dir))) 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))) return '\n'.join(map(wrap_in_tag, map(strip_file_name, file_contents)))
from django.utils.translation import ugettext as _
import django.core.urlresolvers as urlresolvers import django.core.urlresolvers as urlresolvers
import sys import sys
import inspect import inspect
...@@ -21,9 +22,9 @@ def url_for_user(content, user_id): ...@@ -21,9 +22,9 @@ def url_for_user(content, user_id):
def close_thread_text(content): def close_thread_text(content):
if content.get('closed'): if content.get('closed'):
return 'Re-open thread' return _('Re-open thread')
else: else:
return 'Close thread' return _('Close thread')
current_module = sys.modules[__name__] current_module = sys.modules[__name__]
all_functions = inspect.getmembers(current_module, inspect.isfunction) all_functions = inspect.getmembers(current_module, inspect.isfunction)
......
from django.test import TestCase
from django_comment_client.helpers import pluralize
class PluralizeTestCase(TestCase):
def testPluralize(self):
self.term = "cat"
self.assertEqual(pluralize(self.term, 0), "cats")
self.assertEqual(pluralize(self.term, 1), "cat")
self.assertEqual(pluralize(self.term, 2), "cats")
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
<%include file="_underscore_templates.html" /> <%include file="_underscore_templates.html" />
<div class="discussion-module" data-discussion-id="${discussion_id | h}"> <div class="discussion-module" data-discussion-id="${discussion_id | h}">
<a class="discussion-show control-button" href="javascript:void(0)" data-discussion-id="${discussion_id | h}" role="button"><span class="show-hide-discussion-icon"></span><span class="button-text">Show Discussion</span></a> <a class="discussion-show control-button" href="javascript:void(0)" data-discussion-id="${discussion_id | h}" role="button"><span class="show-hide-discussion-icon"></span><span class="button-text">${_("Show Discussion")}</span></a>
<a href="#" class="new-post-btn"><span class="icon icon-edit new-post-icon"></span>${_("New Post")}</a> <a href="#" class="new-post-btn"><span class="icon icon-edit new-post-icon"></span>${_("New Post")}</a>
</div> </div>
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<div class="browse-topic-drop-menu-wrapper"> <div class="browse-topic-drop-menu-wrapper">
<div class="browse-topic-drop-search"> <div class="browse-topic-drop-search">
<label class="sr" for="browse-topic">${_("Filter Topics")}</label> <label class="sr" for="browse-topic">${_("Filter Topics")}</label>
<input type="text" id="browse-topic" class="browse-topic-drop-search-input" placeholder="filter topics"> <input type="text" id="browse-topic" class="browse-topic-drop-search-input" placeholder="${_('filter topics')}">
</div> </div>
<ul class="browse-topic-drop-menu"> <ul class="browse-topic-drop-menu">
<li> <li>
......
...@@ -36,10 +36,10 @@ ...@@ -36,10 +36,10 @@
<div class="right-column"> <div class="right-column">
<div class="form-row"> <div class="form-row">
<label class="sr" for="new-inline-post-title">${_("new post title")}</label> <label class="sr" for="new-inline-post-title">${_("new post title")}</label>
<input type="text" id="new-inline-post-title" class="new-post-title" name="title" placeholder="Title"> <input type="text" id="new-inline-post-title" class="new-post-title" name="title" placeholder="${_('Title')}">
</div> </div>
<div class="form-row"> <div class="form-row">
<div class="new-post-body" name="body" placeholder="Enter your question or comment&hellip;"></div> <div class="new-post-body" name="body" placeholder="${_(u'Enter your question or comment…')}"></div>
<!---<div class="new-post-preview"><span class="new-post-preview-label">Preview</span></div>--> <!---<div class="new-post-preview"><span class="new-post-preview-label">Preview</span></div>-->
</div> </div>
<input type="submit" id="new-inline-post-submit" class="submit" value="${_("Add post")}"> <input type="submit" id="new-inline-post-submit" class="submit" value="${_("Add post")}">
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<div class="topic_menu_wrapper"> <div class="topic_menu_wrapper">
<div class="topic_menu_search" role="menu"> <div class="topic_menu_search" role="menu">
<label class="sr" for="browse-topic-newpost">${_("Filter List")}</label> <label class="sr" for="browse-topic-newpost">${_("Filter List")}</label>
<input type="text" id="browse-topic-newpost" class="form-topic-drop-search-input" placeholder="Filter discussion areas"> <input type="text" id="browse-topic-newpost" class="form-topic-drop-search-input" placeholder="${_("Filter discussion areas")}">
</div> </div>
<ul class="topic_menu" role="menu"> <ul class="topic_menu" role="menu">
${render_form_filter_dropdown(category_map)} ${render_form_filter_dropdown(category_map)}
...@@ -67,10 +67,10 @@ ...@@ -67,10 +67,10 @@
<ul class="new-post-form-errors"></ul> <ul class="new-post-form-errors"></ul>
<div class="form-row"> <div class="form-row">
<label class="sr" for="new-post-title">${_("new post title")}</label> <label class="sr" for="new-post-title">${_("new post title")}</label>
<input type="text" id="new-post-title" class="new-post-title" name="title" placeholder="Title"> <input type="text" id="new-post-title" class="new-post-title" name="title" placeholder="${_("Title")}">
</div> </div>
<div class="form-row"> <div class="form-row">
<div class="new-post-body" name="body" placeholder="Enter your question or comment…"></div> <div class="new-post-body" name="body" placeholder="${_(u"Enter your question or comment…")}"></div>
<!---<div class="new-post-preview"><span class="new-post-preview-label">Preview</span></div>--> <!---<div class="new-post-preview"><span class="new-post-preview-label">Preview</span></div>-->
</div> </div>
<input type="submit" id="new-post-submit" class="submit" value="${_("Add post")}"> <input type="submit" id="new-post-submit" class="submit" value="${_("Add post")}">
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
<%include file="_filter_dropdown.html" /> <%include file="_filter_dropdown.html" />
<div class="search"> <div class="search">
<form class="post-search"> <form class="post-search">
<label class="sr" for="search-discussions">Search</label> <label class="sr" for="search-discussions">${_("Search")}</label>
<input type="text" id="search-discussions" placeholder="Search all discussions" class="post-search-field"> <input type="text" id="search-discussions" placeholder="${_("Search all discussions")}" class="post-search-field">
</form> </form>
</div> </div>
</div> </div>
......
<%! from django.utils.translation import ugettext as _ %> <%! from django.utils.translation import ugettext as _, ungettext %>
<%! from django_comment_client.helpers import pluralize %> <%def name="span(num)"><span>${num}</span></%def>
<%! from django_comment_client.permissions import has_permission, check_permissions_by_view %>
<%! from operator import attrgetter %>
<div class="user-profile"> <div class="user-profile">
<%
role_names = sorted(set(map(attrgetter('name'), django_user.roles.all())))
%>
<div class="sidebar-username">${django_user.username | h}</div> <div class="sidebar-username">${django_user.username | h}</div>
<div class="sidebar-user-roles"> <div class="sidebar-user-roles">
${", ".join(role_names)} ${_(', ').join(sorted(set(map(_, [role.name for role in django_user.roles.all()]))))}
</div> </div>
<div class="sidebar-threads-count"><span>${profiled_user['threads_count'] | h}</span> ${pluralize('discussion', profiled_user['threads_count']) | h} started</div> <div class="sidebar-threads-count">${ungettext('%s discussion started', '%s discussions started', profiled_user['threads_count']) % span(profiled_user['threads_count']) | h}</div>
<div class="sidebar-comments-count"><span>${profiled_user['comments_count'] | h}</span> ${pluralize('comment', profiled_user['comments_count']) | h}</div> <div class="sidebar-comments-count">${ungettext('%s comment', '%s comments', profiled_user['comments_count']) % span(profiled_user['comments_count']) | h}</div>
</div> </div>
<%! from django.utils.translation import ugettext as _ %>
<%! import django_comment_client.helpers as helpers %>
<%! from django.template.defaultfilters import escapejs %>
<%! from django.core.urlresolvers import reverse %>
<%! from courseware.access import has_access %>
<%inherit file="../main.html" />
<%namespace name='static' file='../static_content.html'/>
<%block name="bodyclass">discussion</%block>
<%block name="title"><title>${_("Discussion - {course_number}").format(course_number=course.display_number_with_default) | h}</title></%block>
<%block name="headextra">
<%static:css group='style-course-vendor'/>
<%static:css group='style-course'/>
<%include file="_js_head_dependencies.html" />
</%block>
<%block name="js_extra">
<%include file="_js_body_dependencies.html" />
<%static:js group='discussion'/>
</%block>
<%include file="_discussion_course_navigation.html" args="active_page='discussion'"/>
<%include file="_new_post.html" />
<section class="discussion container" id="discussion-container" data-roles="${roles}" data-course-id="${course_id}" data-user-info="${user_info}" data-threads="${threads}" data-content-info="${annotated_content_info}" data-thread-pages="${thread_pages}" data-flag-moderator="${flag_moderator}">
<div class="discussion-body">
<div class="sidebar"></div>
<div class="discussion-column"></div>
</div>
</section>
<%include file="_underscore_templates.html" />
<%include file="_thread_list_template.html" />
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment