Commit 3dd2fce4 by Braden MacDonald Committed by GitHub

Merge pull request #38 from open-craft/studio-edit-i18n

Fix translation of field names and help text in studio_view
parents c79f6836 60af41a8
......@@ -3,4 +3,4 @@
# XBlock
# This is not in/from PyPi, since it moves fast
-e git+https://github.com/edx/XBlock.git@tag-master-2015-05-22#egg=XBlock
-e git+https://github.com/edx/XBlock.git@xblock-0.4.10#egg=XBlock==0.4.10
......@@ -35,7 +35,7 @@ def package_data(pkg, root_list):
setup(
name='xblock-utils',
version='1.0.2',
version='1.0.3',
description='Various utilities for XBlocks',
packages=[
'xblockutils',
......
......@@ -106,6 +106,16 @@ class TestEditableXBlock_StudioView(StudioEditableBaseTest):
self.assert_unchanged(block, orig_values, explicitly_set=True)
@XBlock.register_temp_plugin(EditableXBlock, "editable")
def test_no_i18n(self):
"""
Test that the studio_view doesn't call block.ugettext since the block hasn't indicated
@XBlock.wants("i18n") or @XBlock.needs("i18n")
"""
with mock.patch.object(EditableXBlock, "ugettext") as mock_ugettext:
self.set_up_root_block()
mock_ugettext.assert_not_called()
@XBlock.register_temp_plugin(EditableXBlock, "editable")
def test_explicit_overrides(self):
"""
Test that we can override the defaults with the same value as the default, and that the
......@@ -211,6 +221,7 @@ def fancy_list_values_provider_b(block):
return [{"display_name": "Robert", "value": "bob"}, {"display_name": "Alexandra", "value": "alex"}]
@XBlock.wants("i18n")
class FancyXBlock(StudioEditableXBlockMixin, XBlock):
"""
A Studio-editable XBlock with lots of fields and fancy features
......@@ -304,6 +315,19 @@ class TestFancyXBlock_StudioView(StudioEditableBaseTest):
return self.load_root_xblock()
@XBlock.register_temp_plugin(FancyXBlock, "fancy")
def test_i18n(self):
"""
Test that field names and help text get translated using the XBlock runtime's ugettext
method.
"""
with mock.patch.object(FancyXBlock, "ugettext", side_effect=lambda text: text[::-1]):
self.set_up_root_block()
bool_field = self.browser.find_element_by_css_selector('li[data-field-name=bool_normal]')
self.assertIn("Normal Boolean Field"[::-1], bool_field.text)
string_with_help_field = self.browser.find_element_by_css_selector('li[data-field-name=string_with_help]')
self.assertIn("Learn more about"[::-1], string_with_help_field.text)
@XBlock.register_temp_plugin(FancyXBlock, "fancy")
def test_no_changes_with_defaults(self):
"""
If we load the edit form and then save right away, there should be no changes.
......
......@@ -13,7 +13,6 @@ StudioEditableXBlockMixin to your XBlock.
import json
import logging
from django.utils.translation import ugettext
from xblock.core import XBlock
from xblock.fields import Scope, JSONField, List, Integer, Float, Boolean, String, DateTime
from xblock.exceptions import JsonHandlerError, NoSuchViewError
......@@ -107,6 +106,14 @@ class StudioEditableXBlockMixin(object):
(DateTime, 'datepicker'),
(JSONField, 'generic'), # This is last so as a last resort we display a text field w/ the JSON string
)
if self.service_declaration("i18n"):
ugettext = self.ugettext
else:
def ugettext(text):
""" Dummy ugettext method that doesn't do anything """
return text
info = {
'name': field_name,
'display_name': ugettext(field.display_name) if field.display_name else "",
......
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