From 354c2d49af8ddc3e97af048716ab2ad4aa46a59d Mon Sep 17 00:00:00 2001 From: Aron Fyodor Asor Date: Wed, 1 Apr 2015 11:20:40 -0700 Subject: [PATCH 1/6] translate the updated title. This is where the actual title is set, not on the exercise view render method. So we put the gettext method here! --- kalite/distributed/static/js/distributed/exercises/views.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kalite/distributed/static/js/distributed/exercises/views.js b/kalite/distributed/static/js/distributed/exercises/views.js index 4178240286..67ce49a30f 100755 --- a/kalite/distributed/static/js/distributed/exercises/views.js +++ b/kalite/distributed/static/js/distributed/exercises/views.js @@ -397,7 +397,7 @@ window.ExerciseView = Backbone.View.extend({ }, update_title: function() { - this.$(".exercise-title").text(this.data_model.get("title")); + this.$(".exercise-title").text(gettext(this.data_model.get("title"))); }, hint_used: function() { From 6b009a69666276c24e069231bb3a68500d2f45c5 Mon Sep 17 00:00:00 2001 From: Aron Fyodor Asor Date: Wed, 1 Apr 2015 14:00:25 -0700 Subject: [PATCH 2/6] SOMEONE MESSED WITH THE KHAN DESCRIPTION STRING Revert back to the string found in the po file. --- data/khan/channel_data.json | 2 +- .../distributed/partials/khan_dummy_channel_translation.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/khan/channel_data.json b/data/khan/channel_data.json index cd2c466d50..a6eb028daa 100644 --- a/data/khan/channel_data.json +++ b/data/khan/channel_data.json @@ -1,7 +1,7 @@ { "channel_name": "KA Lite", "head_line": "A free world-class education for anyone anywhere.", - "tag_line": "KA Lite is a lightweight web server for viewing and interacting with core Khan Academy content (videos and exercises) without needing an Internet connection.", + "tag_line": "KA Lite is a light-weight web server for viewing and interacting with core Khan Academy content (videos and exercises) without needing an Internet connection.", "channel_license": "CC-BY-NC-SA", "footer_text": "Videos © 2015 Khan Academy (Creative Commons) // Exercises © 2015 Khan Academy" } diff --git a/kalite/distributed/templates/distributed/partials/khan_dummy_channel_translation.html b/kalite/distributed/templates/distributed/partials/khan_dummy_channel_translation.html index 2dc9f41602..0bb8e55766 100644 --- a/kalite/distributed/templates/distributed/partials/khan_dummy_channel_translation.html +++ b/kalite/distributed/templates/distributed/partials/khan_dummy_channel_translation.html @@ -2,5 +2,5 @@ {% trans "KA Lite" %} {% trans "A free world-class education for anyone anywhere." %} -{% trans "KA Lite is a lightweight web server for viewing and interacting with core Khan Academy content (videos and exercises) without needing an Internet connection." %} -{% trans "Videos and Exercises © 2014 Khan Academy" %} \ No newline at end of file +{% trans "KA Lite is a light-weight web server for viewing and interacting with core Khan Academy content (videos and exercises) without needing an Internet connection." %} +{% trans "Videos and Exercises © 2014 Khan Academy" %} From 69c8c3c062afff8ebfad4fda2c74247581200b00 Mon Sep 17 00:00:00 2001 From: Aron Fyodor Asor Date: Thu, 2 Apr 2015 09:24:52 -0700 Subject: [PATCH 3/6] when assessment item is a dict, always return something. --- kalite/topic_tools/__init__.py | 3 +-- kalite/topic_tools/tests/utils_tests.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/kalite/topic_tools/__init__.py b/kalite/topic_tools/__init__.py index 2e197c29bc..3546fff12d 100644 --- a/kalite/topic_tools/__init__.py +++ b/kalite/topic_tools/__init__.py @@ -534,8 +534,7 @@ def smart_translate_item_data(item_data): elif isinstance(field_data, list): item_data[field] = map(smart_translate_item_data, field_data) - - return item_data + return item_data diff --git a/kalite/topic_tools/tests/utils_tests.py b/kalite/topic_tools/tests/utils_tests.py index 4f7da3817b..4cab27c48f 100644 --- a/kalite/topic_tools/tests/utils_tests.py +++ b/kalite/topic_tools/tests/utils_tests.py @@ -17,6 +17,18 @@ class SmartTranslateItemDataTests(KALiteTestCase): def tearDown(self): ugettext_dummy.reset_mock() + def test_list_of_dicts(self): + # test_data = {"hints": [{"content": TRANS_STRING, "images": {}, "widgets": {}}]} + # expected_data = {"hints": [{"content": DUMMY_STRING, "images": {}, "widgets": {}}]} + self.maxDiff = None + test_data = {'question': {'content': TRANS_STRING, 'images': {'/content/khan/f24b1c8daf0d1b16bf2dc391393b655e72190290.png': {'width': 450, 'height': 81}}, 'widgets': {'radio 1': {'version': {'major': 0, 'minor': 0}, 'type': 'radio', 'graded': True, 'options': {'onePerLine': True, 'noneOfTheAbove': False, 'choices': [], 'displayCount': None, 'multipleSelect': False, 'randomize': True}}}}, 'answerArea': {'calculator': False, 'type': 'multiple', 'options': {'content': '', 'images': {}, 'widgets': {}}}, 'itemDataVersion': {'major': 0, 'minor': 1}, 'hints': [{'content': TRANS_STRING, 'images': {}, 'widgets': {}}]} + expected_data = {'question': {'content': DUMMY_STRING, 'images': {'/content/khan/f24b1c8daf0d1b16bf2dc391393b655e72190290.png': {'width': 450, 'height': 81}}, 'widgets': {'radio 1': {'version': {'major': 0, 'minor': 0}, 'type': 'radio', 'graded': True, 'options': {'onePerLine': True, 'noneOfTheAbove': False, 'choices': [], 'displayCount': None, 'multipleSelect': False, 'randomize': True}}}}, 'answerArea': {'calculator': False, 'type': 'multiple', 'options': {'content': '', 'images': {}, 'widgets': {}}}, 'itemDataVersion': {'major': 0, 'minor': 1}, 'hints': [{'content': DUMMY_STRING, 'images': {}, 'widgets': {}}]} + + result = mod.smart_translate_item_data(test_data) + # ugettext_dummy.assert_called_once_with(TRANS_STRING) + + self.assertEqual(result, expected_data) + def test_list_of_lists(self): test_data = [[TRANS_STRING]] expected_data = [[DUMMY_STRING]] From 8ced9bbb5c50e967fa9cfacee5508014fc278dc7 Mon Sep 17 00:00:00 2001 From: Aron Fyodor Asor Date: Thu, 2 Apr 2015 09:25:31 -0700 Subject: [PATCH 4/6] actually translate things we pass to $._. Ugh. Looks like $._ was a noop, as it just interpolated strings? This time, we actually translate them by passing it into our own gettext method. --- kalite/distributed/static/perseus/ke/local-only/i18n.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kalite/distributed/static/perseus/ke/local-only/i18n.js b/kalite/distributed/static/perseus/ke/local-only/i18n.js index 961125ed8e..3c73160e90 100644 --- a/kalite/distributed/static/perseus/ke/local-only/i18n.js +++ b/kalite/distributed/static/perseus/ke/local-only/i18n.js @@ -104,7 +104,7 @@ str = str.messages[0]; } - return interpolateStringToArray(str, options).join(""); + return interpolateStringToArray(gettext(str), options).join(""); }; /** From e9c25174e7e88ffeb32ba69c3dfe2077539d843c Mon Sep 17 00:00:00 2001 From: Aron Fyodor Asor Date: Thu, 2 Apr 2015 11:50:20 -0700 Subject: [PATCH 5/6] translate exercise data with whatever language was requested. Before, we translated based on exercise_lang, whose value is whatever get_best_available_language returns for a given set of languages. However, those set of language choices we pass in are those we have translated exercise templates for. When translating for perseus, this is not the case. So what we do here instead is just localize for whatever language we originally requested for get_exercise_cache in the first place. If it's not there, gettext automatically falls back to English. --- kalite/topic_tools/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kalite/topic_tools/__init__.py b/kalite/topic_tools/__init__.py index 3546fff12d..608ba543a7 100644 --- a/kalite/topic_tools/__init__.py +++ b/kalite/topic_tools/__init__.py @@ -165,7 +165,7 @@ def get_exercise_cache(force=False, language=settings.LANGUAGE_CODE): exercise_template = os.path.join(exercise_lang, exercise_file) - with i18n.translate_block(exercise_lang): + with i18n.translate_block(language): exercise["available"] = available exercise["lang"] = exercise_lang exercise["template"] = exercise_template From 029830efa01202e4b0a3630d90997204badee7ce Mon Sep 17 00:00:00 2001 From: Aron Fyodor Asor Date: Thu, 2 Apr 2015 11:56:16 -0700 Subject: [PATCH 6/6] Revert "translate the updated title." This reverts commit 354c2d49af8ddc3e97af048716ab2ad4aa46a59d. --- kalite/distributed/static/js/distributed/exercises/views.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kalite/distributed/static/js/distributed/exercises/views.js b/kalite/distributed/static/js/distributed/exercises/views.js index 67ce49a30f..4178240286 100755 --- a/kalite/distributed/static/js/distributed/exercises/views.js +++ b/kalite/distributed/static/js/distributed/exercises/views.js @@ -397,7 +397,7 @@ window.ExerciseView = Backbone.View.extend({ }, update_title: function() { - this.$(".exercise-title").text(gettext(this.data_model.get("title"))); + this.$(".exercise-title").text(this.data_model.get("title")); }, hint_used: function() {