From 082c82c82dcaa292d6d51aee0ca6637a48e73a44 Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Thu, 9 Apr 2009 12:18:09 +0200 Subject: [PATCH] Strip I18n markers when get translations with AJAX --- assets/javascripts/click_to_globalize.js | 4 ++++ test/javascript/fixtures/translations.json | 2 +- test/javascript/lib/jstest.rb | 1 + test/javascript/unit/click_to_globalize_test.js | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/click_to_globalize.js b/assets/javascripts/click_to_globalize.js index 33a30da..1b401f0 100644 --- a/assets/javascripts/click_to_globalize.js +++ b/assets/javascripts/click_to_globalize.js @@ -67,6 +67,10 @@ var ClickToGlobalize = Class.create({ new Ajax.Request(this.options.translationsUrl, { onSuccess: function(transport) { this.translations = $H(transport.responseText.evalJSON()); + this.translations = this.translations.inject($H({}), function(result,pair){ + result.set(pair.key, pair.value.stripTags()); + return result; + }); }.bind(this), method: 'get', // Set on false, cause we have to wait until the end of the request diff --git a/test/javascript/fixtures/translations.json b/test/javascript/fixtures/translations.json index ef0e8c7..6345c72 100644 --- a/test/javascript/fixtures/translations.json +++ b/test/javascript/fixtures/translations.json @@ -1 +1 @@ -{'hello_world': 'Hello World'} \ No newline at end of file +{"hello_world": "Hello World", "hello_moon": "en, hello_moon"} diff --git a/test/javascript/lib/jstest.rb b/test/javascript/lib/jstest.rb index 4e29868..67701aa 100644 --- a/test/javascript/lib/jstest.rb +++ b/test/javascript/lib/jstest.rb @@ -271,6 +271,7 @@ def set_default_content_type(res, path) when /\.js$/ then 'text/javascript' when /\.html$/ then 'text/html' when /\.css$/ then 'text/css' + when /\.json$/ then 'application/json' else 'text/plain' end end diff --git a/test/javascript/unit/click_to_globalize_test.js b/test/javascript/unit/click_to_globalize_test.js index 515370f..c7f5fc0 100644 --- a/test/javascript/unit/click_to_globalize_test.js +++ b/test/javascript/unit/click_to_globalize_test.js @@ -47,7 +47,7 @@ new Test.Unit.Runner({ this.assertEqual(TestUtil.DefaultOptions, clickToGlobalize.options); }, testGetTranslations: function() { - expected = $H({ hello_world: 'Hello World' }); + expected = $H({ hello_world: "Hello World", hello_moon: "en, hello_moon" }); this.assertEqual(expected.size(), clickToGlobalize.translations.size()); expected.each(function(pair){ this.assertEqual(pair.value, clickToGlobalize.translations.get(pair.key));