How is internationalization configured for Hogan.js?

后端 未结 2 1753
名媛妹妹
名媛妹妹 2021-01-20 15:31

I\'m looking to use hogan.js to create html form a template in the browser. I\'ve read that hogan supports i18n, but I can\'t find an example of how this works. How do you

2条回答
  •  甜味超标
    2021-01-20 15:54

    It is actually easy to combine this with other internationalisation approaches. We are using jquery-i18n-properties, which is a jQuery plugin that supports the use of .properties files, which are compatible to Java.

    The framework tries to download a file called Messages.properties and depending on the browsers language fo example Messages_en.properties and Messages_en_US.properties. This allows to build a hierarchy of translations very quickly.

    So slightly changing the example of slashnick and using hogan/mustache, I write:

    var template = "{{#i18n}}Name{{/i18n}}: {{username}}",
        context = {
           username: "Jean Luc",
           i18n: function (i18nKey) {return jQuery.i18n.prop(key);}
        };
    
     // Init i18n
    jQuery.i18n.properties(
    {
    name:'Messages', 
    path:'some/path',
    mode : 'map'
    });
    
    Hogan.compile(template).render(context);
    

    Messages.properties File:

    Name = Name
    

    Messages_fr.properties File:

    Name = nom
    

    I do not really see the advantage of using the special mustache version with looks up a global function (performance maybe?).

提交回复
热议问题