Ember-i18n precompiled translations from Handlebars Runtime

The ember-i18n readme file says:

If you have not precompiled your translations, you need to include full descriptors, not just handlebars-runtime.js in your application.

The problem is that even with pre-compiled templates, when we use the Em.I18n.t function , as shown below, it still calls the Handlebars compilation function, which requires full handles.

Does anyone know a solution for this? Maybe there is a better experience for precompiling translations even for function calls?

+4
source share
2 answers

, , :

/* Customized version of translation compiler */
Em.I18n.compile = function(template) {
    // Full Handlebars completely disabled
    //if (typeof window.Handlebars.compile === 'function')
    //    return window.Handlebars.compile(template);

    return function(context, options){
        var ret = template;
        if (context !== undefined) {
            $.each(context, function(key, value){
                ret = ret.replace("{{"+key+"}}", value);
            });
        }
        return ret;
    }
}

, 100%, .

+1

ember-i18n (2.2.1 ) :

Ember.I18n Handlebars ; . Ember.ENV.I18N_COMPILE_WITHOUT_HANDLEBARS true .

, Handlebars, . , , , , , .

0

Source: https://habr.com/ru/post/1542627/


All Articles