Commit 34d2f051 by louyihua

i18n: Make checklists translatable

Now the description & action_text strings in checklists can be extracted and translated.
parent 72d9a91f
...@@ -16,6 +16,8 @@ from .access import has_course_access ...@@ -16,6 +16,8 @@ from .access import has_course_access
from xmodule.course_module import CourseDescriptor from xmodule.course_module import CourseDescriptor
from xmodule.modulestore.locator import BlockUsageLocator from xmodule.modulestore.locator import BlockUsageLocator
from django.utils.translation import ugettext
__all__ = ['checklists_handler'] __all__ = ['checklists_handler']
...@@ -79,7 +81,7 @@ def checklists_handler(request, tag=None, package_id=None, branch=None, version_ ...@@ -79,7 +81,7 @@ def checklists_handler(request, tag=None, package_id=None, branch=None, version_
course_module.save() course_module.save()
modulestore.update_item(course_module, request.user.id) modulestore.update_item(course_module, request.user.id)
expanded_checklist = expand_checklist_action_url(course_module, persisted_checklist) expanded_checklist = expand_checklist_action_url(course_module, persisted_checklist)
return JsonResponse(expanded_checklist) return JsonResponse(localize_checklist_text(expanded_checklist))
else: else:
return HttpResponseBadRequest( return HttpResponseBadRequest(
("Could not save checklist state because the checklist index " ("Could not save checklist state because the checklist index "
...@@ -99,7 +101,7 @@ def expand_all_action_urls(course_module): ...@@ -99,7 +101,7 @@ def expand_all_action_urls(course_module):
""" """
expanded_checklists = [] expanded_checklists = []
for checklist in course_module.checklists: for checklist in course_module.checklists:
expanded_checklists.append(expand_checklist_action_url(course_module, checklist)) expanded_checklists.append(localize_checklist_text(expand_checklist_action_url(course_module, checklist)))
return expanded_checklists return expanded_checklists
...@@ -127,3 +129,20 @@ def expand_checklist_action_url(course_module, checklist): ...@@ -127,3 +129,20 @@ def expand_checklist_action_url(course_module, checklist):
item['action_url'] = location.url_reverse(url_prefix, '') item['action_url'] = location.url_reverse(url_prefix, '')
return expanded_checklist return expanded_checklist
def localize_checklist_text(checklist):
"""
Localize texts for a given checklist and returns the modified version.
The method does an in-place operation so the input checklist is modified directly.
"""
# Localize checklist name
checklist['short_description'] = ugettext(checklist['short_description'])
# Localize checklist items
for item in checklist.get('items'):
item['short_description'] = ugettext(item['short_description'])
item['long_description'] = ugettext(item['long_description'])
item['action_text'] = ugettext(item['action_text']) if item['action_text'] != "" else u""
return checklist
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
%> %>
<%block name="title">Course Checklists</%block> <%block name="title">${_("Course Checklists")}</%block>
<%block name="bodyclass">is-signedin course view-checklists</%block> <%block name="bodyclass">is-signedin course view-checklists</%block>
<%namespace name='static' file='static_content.html'/> <%namespace name='static' file='static_content.html'/>
...@@ -64,7 +64,7 @@ require(["domReady!", "jquery", "js/collections/checklist", "js/views/checklist" ...@@ -64,7 +64,7 @@ require(["domReady!", "jquery", "js/collections/checklist", "js/views/checklist"
</div> </div>
<div class="bit"> <div class="bit">
<h3 class="title title-3">Studio checklists</h3> <h3 class="title title-3">${_("Studio checklists")}</h3>
<nav class="nav-page checklists-current"> <nav class="nav-page checklists-current">
<ol> <ol>
% for checklist in checklists: % for checklist in checklists:
......
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