简体   繁体   English

如何在angularjs 1.6上使用i18n

[英]How to use i18n on angularjs 1.6

How I should use i18n so the variable "title" takes the value from the traslatated json. 我应该如何使用i18n,以便变量“ title”从traslatated json中获取值。 It should return "Mis viajes" and right now it is not returning anything. 它应该返回“ Mis viajes”,现在它不返回任何东西。 Thanks trips-header.jade 谢谢trips-header.jade

I did this and I get "0" on the screen. 我这样做了,屏幕上显示“ 0”。

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

Mi json Mi json

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

Here is a sample approach. 这是一个示例方法。 You want html to look like this: 您希望html看起来像这样:

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

Your jade is this: 你的玉是这样的:

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

Your translation is this: 您的翻译是这样的:

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

Your i18n in angular should be properly configured: 您的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

EDIT: added quotes around the 'hello'. 编辑:在“你好”周围添加了引号。 Now it is treated as a text and not a variable. 现在将其视为文本而不是变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM