backbone.js - Localizing templates with backbone, underscore on mobile -


i want localize templates in phonegap/backbone mobile app. want somehow override underscore render function in way append attribute languages. let me show on example:

lets required (require.js) homeview template wich looks like:

<div>    <p><%= language.get('sometext') %></p> </div>  

in homeview.js have:

var template = _.template(hometemplate); this.$el.html( template({language: languagemodel})); 

this works, don't want append language attribute underscore template. somehow overwrite render function include language model?

you can put javascript expression inside <%= ... %>. in particular, can access globals. so, if have global application namespace:

// i'll call `app` lack of better placeholder. window.app = { ... }; 

then can put language in there:

app.language = your_language_model; 

and access in template without supplying _.template call or compiled template function:

var t = _.template('<%= app.language.get('pancakes') %>'); var h = t(); 

demo: http://jsfiddle.net/ambiguous/jkmg7/1/


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -