Backbone.js how to i18n value before passing to te

2019-03-31 04:44发布

问题:

Using Backbone.js, Handlebars and Require.js with i18n. I have my en_us.js file with all the string translations, but how do I deal with the case of dynamic values being sent to the template?

I know all these strings ahead of time, but hard coding them into the template seems messy, can I pass in a pre-translated string some how? I am using the hbs module for the i18n and templates with require.js.

回答1:

I see this problem not related to i18n but to any case where you need render data that still need to be calculated.

You should cook your data before you send it to the template to be rendered, so your template just has to take a key and show the value.

If your Model.attributes are not ready for your template you shouldn't send them directly but prepare them and when they are ready send them to the template.

Check the answers in this question to see if any of the answers match with your needs.