javascript - 怎么使用i18next的angular插件
天蓬老师
天蓬老师 2017-04-10 16:52:56
0
1
342

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

json部分:

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

html部分

<p 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

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!