Skip to content

Commit 082c82c

Browse files
author
Luca Guidi
committed
Strip I18n markers when get translations with AJAX
1 parent 2ca7b5c commit 082c82c

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

Diff for: assets/javascripts/click_to_globalize.js

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ var ClickToGlobalize = Class.create({
6767
new Ajax.Request(this.options.translationsUrl, {
6868
onSuccess: function(transport) {
6969
this.translations = $H(transport.responseText.evalJSON());
70+
this.translations = this.translations.inject($H({}), function(result,pair){
71+
result.set(pair.key, pair.value.stripTags());
72+
return result;
73+
});
7074
}.bind(this),
7175
method: 'get',
7276
// Set on false, cause we have to wait until the end of the request

Diff for: test/javascript/fixtures/translations.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{'hello_world': 'Hello World'}
1+
{"hello_world": "Hello World", "hello_moon": "<span class=\"translation_missing\">en, hello_moon</span>"}

Diff for: test/javascript/lib/jstest.rb

+1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ def set_default_content_type(res, path)
271271
when /\.js$/ then 'text/javascript'
272272
when /\.html$/ then 'text/html'
273273
when /\.css$/ then 'text/css'
274+
when /\.json$/ then 'application/json'
274275
else 'text/plain'
275276
end
276277
end

Diff for: test/javascript/unit/click_to_globalize_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ new Test.Unit.Runner({
4747
this.assertEqual(TestUtil.DefaultOptions, clickToGlobalize.options);
4848
},
4949
testGetTranslations: function() {
50-
expected = $H({ hello_world: 'Hello World' });
50+
expected = $H({ hello_world: "Hello World", hello_moon: "en, hello_moon" });
5151
this.assertEqual(expected.size(), clickToGlobalize.translations.size());
5252
expected.each(function(pair){
5353
this.assertEqual(pair.value, clickToGlobalize.translations.get(pair.key));

0 commit comments

Comments
 (0)