关于此主题的其他一些链接:
您可能可以从您选择的模板语言中自己构建一些东西。例如:
<script>
define("myProps", {
"record_created": "A record for {{name}} has been created at {{date}}"
});
define("myI18N", ["handlebars"], function(Handlebars) {
function format(template, context) {
var compiled = Handlebars.compile(template);
return compiled(context);
}
function Wrapper(props) {
var ob = {};
for (var i in props) {
ob[i] = format.bind(null, props[i]);
}
return ob;
}
return Wrapper;
});
require(["myProps", "myI18N"], function(props, i18n) {
var ob = i18n(props);
console.log(ob.record_created({
name: "Meli",
date: new Date()
}));
});
</script>
印刷:
A record for Meli has been created at Mon Sep 23 2013 20:32:39 GMT+0100 (GMT Daylight Time)
设置:
<script>
require = {
paths: {
"handlebars": "https://rawgithub.com/wycats/handlebars.js/v1.0.12/dist/handlebars"
},
shim: {
'handlebars': {
exports: 'Handlebars'
}
}
};
</script>
<script src="http://requirejs.org/docs/release/2.1.8/comments/require.js"></script>