Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用i18next与Anuglar插件进行翻译?_Javascript_Angularjs_Localization_Internationalization_I18next - Fatal编程技术网

Javascript 如何使用i18next与Anuglar插件进行翻译?

Javascript 如何使用i18next与Anuglar插件进行翻译?,javascript,angularjs,localization,internationalization,i18next,Javascript,Angularjs,Localization,Internationalization,I18next,我将i18next与插件一起使用。对于angular指令,它应该在页面上显示“test”和“thisatest”。但它显示“home.title”和“home.content”。检查控制台,json文件加载正确,如果我使用javascript DOM,可以显示正确的内容 我的json文件: { "home":{ "title": "test", "content": "this is a test" } } html: 这是控制台的信息,我不知道

我将i18next与插件一起使用。对于angular指令,它应该在页面上显示“test”和“thisatest”。但它显示“home.title”和“home.content”。检查控制台,json文件加载正确,如果我使用javascript DOM,可以显示正确的内容

我的json文件:

{
    "home":{
        "title": "test",
        "content": "this is a test"
    }
}
html:

这是控制台的信息,我不知道最后一个错误是什么:

  • i18next::backendConnector:已加载语言的命名空间转换 en对象{home:Object}
  • i18next.min.js:2 i18next:languageChanged en
  • i18next.min.js:2 i18next:initialized Object{debug:true,ns: 数组[1],defaultNS:Array[1],回退lng:Array[1],回退ns: 假…}
  • ng-i18next.min.js:1未捕获类型错误:i.lng不是函数

刚刚进行了双重检查,看起来像是
i18next
模块已升级到较新版本,因此有以下选项:

{
  compatibilityAPI: 'v1',
  compatibilityJSON: 'v1',
  // ...old options from v1
}
它应该用于
i18next
使
ng-i18next
插件工作


p.S:作为建议,我建议您使用插件而不是这个插件,但这完全取决于您。

我尝试了{{home.title}}和{{home.content},但没有任何内容page@VincentFu是的,误解了,对不起。您可以不用花括号保存它。是的,它正在使用兼容标志,谢谢@OlegMeleshko
angular.module('jm.i18next')
.config(['$i18nextProvider',function($i18nextProvider){
  window.i18next.use(window.i18nextXHRBackend);

  $i18nextProvider.options = {
    debug: true,
    lng: 'en',
    fallbackLng: 'en',
    backend: {
      loadPath: '/locales/{{lng}}/{{ns}}.json'
    }
  };
}]);

angular.module('myApp', ['jm.i18next']).controller('myCtrl',['$scope', '$i18next',function($scope, $i18next){
}])
{
  compatibilityAPI: 'v1',
  compatibilityJSON: 'v1',
  // ...old options from v1
}