全球化1.x与DevExtreme库

时间:2016-09-08 09:10:09

标签: javascript knockout.js devextreme javascript-globalize

我对DevExtreme v.16.1与Globalize 1.x的结合有疑问。他们从0.x升级到1.x,自更新以来我无法使其工作。

我将librries加载到外部文件中,并在解析了promise之后加载了其余的应用程序。

这是我的localize.js

的一部分
$(function () {
    MK.localisation.init = $.when(
        // CLDR libraries for NL-nl
        $.getJSON("js/localization/nl/ca-gregorian.json"),
        $.getJSON("js/localization/nl/numbers.json"),
        $.getJSON("js/localization/nl/currencies.json"),

        // CLDR libraries for DE-de
        $.getJSON("js/localization/de/ca-gregorian.json"),
        $.getJSON("js/localization/de/numbers.json"),
        $.getJSON("js/localization/de/currencies.json"),

        // CLDR libraries for EN-uk
        $.getJSON("js/localization/en/ca-gregorian.json"),
        $.getJSON("js/localization/en/numbers.json"),
        $.getJSON("js/localization/en/currencies.json"),

        //additional CLDR libraries
        $.getJSON("js/cldr/supplemental/likelySubtags.json"),
        $.getJSON("js/cldr/supplemental/timeData.json"),
        $.getJSON("js/cldr/supplemental/weekData.json"),
        $.getJSON("js/cldr/supplemental/currencyData.json"),
        $.getJSON("js/cldr/supplemental/numberingSystems.json")
    ).then(function () {
        // Normalize $.get results, we only need the JSON, not the request statuses.
        return [].slice.apply(arguments, [0]).map(function (result) {
            return result[0];
        });
    }).then(
        Globalize.load
    ).then(function () {
        return $.when(
            $.getJSON("js/localization/nl/dx.all.nl.json"),
            $.getJSON("js/localization/nl/localization.nl.json"),
            $.getJSON("js/localization/de/dx.all.de.json"),
            $.getJSON("js/localization/de/localization.de.json"),
            $.getJSON("js/localization/en/dx.all.en.json"),
            $.getJSON("js/localization/en/localization.en.json")
        ).done(function (r1,r2,r3,r4,r5,r6) {
            Globalize.loadMessages(r1[0]);
            Globalize.loadMessages(r2[0]);
            Globalize.loadMessages(r3[0]);
            Globalize.loadMessages(r4[0]);
            Globalize.loadMessages(r5[0]);
            Globalize.loadMessages(r6[0]);
            Globalize.locale("nl");
            $.each(MK.config.navigation, function () {
                if (this.title.indexOf('@') === 0) {
                    this.title = Globalize.formatMessage(this.title.substring(1));
                }
            });           
        });
    });

如果我在Globalize.locale(“nl”)中放置断点,我会看到所有消息都在Globalize对象中加载。

我通过以下方式在index.js的顶部调用此函数:

$(function () {

    //setup localisation
    MK.localisation.init.done(function () {
        Globalize.locale("de");
        //rest of the app decalration follows here
    })

我也可以在JavaScript中使用翻译而不会出现问题

Globalize.formatMessage("someString")

但是,DevExtreme模块未翻译。他们仍然是英语。也可以使用@someString语法直接在视图内转换字符串。这不适用于我声明的字符串。它确实可以使用字符串构建,因此解析确实有效。

我怀疑计时问题,可能在加载字符串之前解析了视图?但是无法解决问题,遵循devextreme的手册,我认为......

http://js.devexpress.com/Documentation/Guide/SPA_Framework/Localization/?version=16_1&approach=Knockout

0 个答案:

没有答案