2017-05-23 13 views
0

はi18next

</head> 

<body> 
    <div id="add"> 
     <div data-i18n="key">Hello</div> 
    </div> 
    <script> 
     i18next.t('key', {yes: 'this', no: 'great'}); 
    </script> 
    <script> 
     i18next 
     i18next.use(window.i18nextBrowserLanguageDetector) 
     i18next.use(window.i18nextXHRBackend) 

     .init({ 
      debug: true, 
      tName: 't', 
      handleName: 'localize', 
      selectorAttr: 'data-i18n', 
      targetAttr: 'i18n-target', 
      optionsAttr: 'i18n-options', 
      useOptionsAttr: true, 
      parseDefaultValueFromContent: true, 
      initImmediate: true, 
      fallbackLng: false, 
      interpolation: { 
       "escapeValue": true, 
       "prefix": "{{", 
       "suffix": "}}", 
       "formatSeparator": ",", 
       "unescapePrefix": "-", 
       "nestingPrefix": "$t(", 
       "nestingSuffix": ")" 
      }, 

      detection: { 
       order: ['querystring', 'cookie', 'navigator', 'htmlTag'], 
       lookupCookie: 'i18next', 
       lookupLocalStorage: 'i18nextLng', 
       caches: ['cookie'], 
      }, 

      "backend": { 
       "loadPath": "/locales/{{lng}}/{{ns}}.json" 
      } 

     }, function(err, t) { 
      jqueryI18next.init(i18next, $); 
      $('#add').localize(); 
     }); 

    </script> 

</body> 

JSONファイル

{ "キー" に補間する変数でYES渡す逃した:「{{YES}} {あります{no}} "

}

コンソール結果

i18next ::補間:補間するための変数でYES渡す逃し{{YES}}は{{ない}}

i18next ::補間のための:変数なしに通過させるように逃し補間は{{no}}

このコードでは何も間違っていますか?

ありがとう

答えて

0

初期化が行われる前に、i18next.t('key', {yes: 'this', no: 'great'});を呼び出します。

あなたはする必要があります

`` ` .INIT({ ...

}, function(err, t) { 
     jqueryI18next.init(i18next, $); 
     // add vars here!!! 
     $('#add').localize({yes: 'this', no: 'great'}); 
    }); 

` ``

またはデータI18N - オプションの属性を使用します。https://github.com/i18next/jquery-i18next#using-options-in-translation-function

+0

@jamuhi、あなたの時間をありがとう、私は別のクエリを持っています私はスペイン語や中国語のような2つの異なる言語で翻訳しようとしました私は2つの別々のJsonファイルs。 「スペイン語」、「スペイン語」、「偉大なスペイン語」}、または中国語{はい:「これは中国人」、いいえ:「偉大な中国人」}のように、「はい」または「いいえ」には2つの異なる値があります。しかし、ブラウザ言語をChinesに変更するとCh.jsonファイルが呼び出されますが、 "{{yes}}"や "{{no}}"という名前はchinesのJsonファイルに変更される必要があります。その場合は –

+0

@AdityaTomarに入れてみてください。https://www.i18next.com/nesting.html – jamuhl

+0

@jamuhi、もう一度tnx、このURLをご覧ください:https://stackoverflow.com/questions/44154275翻訳不可能 - 翻訳不可タグ - 内部div-i18next-library –

関連する問題