怎么使用i18next的angular插件

正在用i18next的angular插件https://github.com/i18next/ng-i18next,可以正确读取json文件,如果使用JS DOM的话可以正确显示出内容。但是不知道怎么使用插件的angular指令翻译内容。以下是我的测试代码

json部分:

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

html部分

<div ng-app="myApp" ng-controller="myCtrl" class="home">
<h1 ng-i18next="home.title"></h1>
<p ng-i18next="home.content"></p>

js部分

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){
}])

以上代码是想在页面上显示翻译出来的内容"test"和"this is a test", 但是显示的是“home.title"和”home.content".

以下是console的记录,最后一个报错不知道什么引起的:
i18next::backendConnector: loaded namespace translation for language en Object {home: Object}
i18next.min.js:2 i18next: languageChanged en
i18next.min.js:2 i18next: initialized Object {debug: true, ns: Array[1], defaultNS: Array[1], fallbackLng: Array[1], fallbackNS: false…}
ng-i18next.min.js:1 Uncaught TypeError: i.lng is not a function

阅读 5.3k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题