i118next初始化问题

时间:2013-11-11 19:10:37

标签: javascript jquery cordova i18next

我在Cordova / PhoneGap应用程序的jQuery Mobile页面中使用了i18next脚本。

我在HTML页面底部包含以下脚本。

<script src="js/jquery-1.8.3.min.js"></script>               
<script src="js/jquery.mobile-1.3.2.min.js"></script>   
<script src="js/i18next-1.7.1.min.js"></script>         
<script src="js/main.js"></script>  

main.js文件有一些逻辑,它将包含在我的应用程序的所有页面中。

main.js 文件:

function doBootstrap() {
    i18n.init({lng: "en", fallbackLng: 'en'});

    var header = "some tags";
    header += '<h1>' + i18n.t("app.title") + '</h1>';

    // other functions
}

我将使用脚本在不同的部分中跨页面获取翻译的值

上面的函数在Cordova devideready函数中调用,该函数放在上面提到的包括。

document.addEventListener("deviceready", onDeviceReady, true);

function onDeviceReady() {
    doBootstrap();
}

通过以上所有设置,我在i18next-1.7.1.min.js文件中收到以下错误。

Uncaught TypeError: Cannot read property 'defaultValue' of undefined 

.json文件存在于\ locales \ en \ translation.json中,其内容如下。控制台中不显示错误或警告。

{
   "app": {
     "title": "Title"
   }
}

插件设置我缺少什么?

1 个答案:

答案 0 :(得分:2)

最后,我让它发挥作用。这是代码中的一个错误,开发人员在报告它的几分钟内修复了它。太棒了..

以下是该问题的链接。

https://github.com/jamuhl/i18next/issues/166

同样根据插件的开发者,我做了以下更改。

function doBootstrap() {
    var opts = {
       getAsync: true, lng: "en", fallbackLng: 'en'
    };

    i18n.init(opts).done(doBootstrapMain);
}

function doBootstrapMain() {
   // my regular functions
}