Module: JavascriptLocalize::Methods
- Defined in:
- lib/javascript_localize.rb
Instance Method Summary collapse
-
#include_localized_javascript ⇒ Object
_ = function(str,opt){ var localeString = __LocaleString; localeString = (localeString && localeString != ”) ? localeString : str;.
Instance Method Details
#include_localized_javascript ⇒ Object
_ = function(str,opt)
var localeString = __LocaleString[str];
localeString = (localeString && localeString != '') ? localeString : str;
if(opt){
fn = new Function("obj",
"var p=[],print=function(){p.push.apply(p,arguments);;" +
"with(obj)+
localeString
.replace(/[\t]/g, " ")
.replace(/\"/g, '\\"')
.split("{{").join("\t")
.replace(/\t(.*?)}/g, "\",function(){ try { return $1 }catch(err){ return '$1 undefined'} }.apply(this),\"")
+ "\");};return p.join('');");
return fn.call(this,opt)
}else{
return localeString
}
}
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/javascript_localize.rb', line 26 def include_localized_javascript return %Q{ <script src='/javascripts/locales/#{I18n.locale}.js' type='text/javascript' charset='utf-8'></script> <script type='text/javascript'> _ = function(str,opt){ var localeString = __LocaleString[str]; localeString = (localeString && localeString != '') ? localeString : str; if(opt){ fn = new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" + "with(obj){p.push(\\"" + localeString .replace(/[\\t]/g, " ") .replace(/\\"/g, '\\\\"') .split("{{").join("\\t") .replace(/\\t(.*?)}}/g, "\\",function(){ try { return $1 }catch(err){ return '$1 undefined'} }.apply(this),\\"") + "\\");};return p.join('');"); return fn.call(this,opt) }else{ return localeString } } </script> } end |