Skip to content

Commit

Permalink
Strip I18n markers when get translations with AJAX
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Guidi committed Apr 9, 2009
1 parent 2ca7b5c commit 082c82c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions assets/javascripts/click_to_globalize.js
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/javascript/fixtures/translations.json
@@ -1 +1 @@
{'hello_world': 'Hello World'}
{"hello_world": "Hello World", "hello_moon": "<span class=\"translation_missing\">en, hello_moon</span>"}
1 change: 1 addition & 0 deletions test/javascript/lib/jstest.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/javascript/unit/click_to_globalize_test.js
Expand Up @@ -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));
Expand Down

0 comments on commit 082c82c

Please sign in to comment.