【发布时间】:2016-07-15 00:24:14
【问题描述】:
大家好,
从 i18next jquery 1.11.1 迁移到 3.0.0 版我需要一点帮助 目前这是我的设置
<!-- Core JS files -->
<script type="text/javascript" src="../js/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="../js/i18next.min.js"></script> (v1.11.1)
$(function(){
// i18next Configuration
// -------------------------
var namespaces = ["nav" ,"common" ];
var options = {
ns: {
namespaces: namespaces,
defaultNs: namespaces[0]
},
resGetPath: '../assets/locales/__ns__/__lng__.json',
debug: false,
load: 'unspecific',
detectLngQS: 'lang',
fallbackLng : 'en',
cookieName: 'applang',
//cookieExpirationTime : ,
useLocalStorage: false,
cookieDomain: '*.mydomain.com',
useCookie: true,
lngWhitelist: ['en','es', 'de', 'fr']
};
i18n.init(options ,function (err,t) {
$('body').i18n(); // Init 18n
});
})
当我想加载额外的命名空间时,我会这样做
var namespaces = ["newFile"];
i18n.loadNamespaces(namespaces, function (err, t) {
// init i18n
$('body').i18n();
.............. other stuff in here
})
但是当我尝试使用最新的 i18next v3 和 jquery-i18next (https://github.com/i18next/jquery-i18next) 保持相同的逻辑时,我在 loadNamespaces 函数上遇到错误(未捕获的 TypeError:namespaces.forEach 不是函数),下面是新设置
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next/3.0.0/i18next.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-i18next/0.0.2/i18next-jquery.min.js" ></script>
i18next
.use(i18nextXHRBackend)
.init({
lng: 'de',
backend: {
loadPath: '../assets/locales/{{lng}}/{{ns}}.json'
}
}, function(err, t) {
jqueryI18next.init(i18next, $);
$('.body').localize();
});
var namespaces = ["newFile"];
i18n.loadNamespaces(namespaces, function (err, t) {
// init i18n
$('body').localize();
.............. other stuff in here
})
【问题讨论】:
标签: javascript jquery i18next