Permalink
Browse files

When sending strings to google, if they contained variables, the stri…

…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...
1 parent 6203065 commit 2ceb99e29f8b149e0cf9c2c4bf0d6dc6585b3a5a KieranP committed May 28, 2009
Showing with 7 additions and 3 deletions.
  1. +7 −3 views/layouts/translate.rhtml
@@ -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);
+ }
});
}

0 comments on commit 2ceb99e

Please sign in to comment.