Skip to content

Commit

Permalink
When sending strings to google, if they contained variables, the stri…
Browse files Browse the repository at this point in the history
…ng would get messed up. So escape it to something google doesn't edit, and reassemble the string when a response comes back from the request.
  • Loading branch information
KieranP committed May 28, 2009
1 parent 6203065 commit 2ceb99e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions views/layouts/translate.rhtml
Expand Up @@ -11,10 +11,14 @@
google.load("language", "1");

function getGoogleTranslation(id, text, from_language, to_language) {
text = text.replace(/\{\{/, '__').replace(/\}\}/, '__')
google.language.translate(text, from_language, to_language, function(result) {
if (!result.error) {
Form.Element.setValue(id, result.translation.unescapeHTML());
}
if (!result.error) {
result_text = result.translation.unescapeHTML().gsub(/__(.+)__/, function(match){
return '{{' + match[1] + '}}';
});
Form.Element.setValue(id, result_text);
}
});

}
Expand Down

0 comments on commit 2ceb99e

Please sign in to comment.