簡體   English   中英

如何在angularjs 1.6上使用i18n

[英]How to use i18n on angularjs 1.6

我應該如何使用i18n,以便變量“ title”從traslatated json中獲取值。 它應該返回“ Mis viajes”,現在它不返回任何東西。 謝謝trips-header.jade

我這樣做了,屏幕上顯示“ 0”。

.trips-header
    .background-image
    .header-content
        p.title.ng-i18next {{   title | i18next}} 
        p.sub-title.ng-i18next {{   sub-title | i18next}} 

Mi json

 {
  "es-AR": {
      "translation": {
         "title":"Mis Viajes!",
         "sub-title": " te ayuda a planificar y organizar tus viajes."
      }
  }
}

這是一個示例方法。 您希望html看起來像這樣:

<h1>{{'hello' | i18next}}</h1>

你的玉是這樣的:

- var foo = "{{hello | i18next}}"
h1= foo

您的翻譯是這樣的:

{
  "es-AR": {
      "translation": {
          "hello":"hi!"
       }
    }
}

您的i18n角度應正確配置:

yourApp.config( ['$i18nextProvider',function( $i18nextProvider ) {
    $i18nextProvider.options = {
        lng: 'es-AR', //select or detect from browser
        useCookie: false,
        useLocalStorage: false,
        fallbackLng: 'en',
        resGetPath:  l_prefix + 'locales/__lng__/__ns__.json',
        defaultLoadingValue: ''
    }
// file is expected to be locales/es-AR/translation.json
..... remaining of the config

編輯:在“你好”周圍添加了引號。 現在將其視為文本而不是變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM