如何在 angularjs 1.6 上使用 i18n
How to use i18n on angularjs 1.6
我应该如何使用 i18n 以便变量 "title" 从翻译后的 json 中获取值。它应该 return "Mis viajes" 而现在它没有 returning 任何东西。谢谢
行程-header.jade
我这样做了,但屏幕上显示“0”。
.trips-header
.background-image
.header-content
p.title.ng-i18next {{ title | i18next}}
p.sub-title.ng-i18next {{ sub-title | i18next}}
米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!"
}
}
}
您在 angular 中的 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
编辑:在 'hello' 周围添加引号。现在它被视为文本而不是变量。
我应该如何使用 i18n 以便变量 "title" 从翻译后的 json 中获取值。它应该 return "Mis viajes" 而现在它没有 returning 任何东西。谢谢 行程-header.jade
我这样做了,但屏幕上显示“0”。
.trips-header
.background-image
.header-content
p.title.ng-i18next {{ title | i18next}}
p.sub-title.ng-i18next {{ sub-title | i18next}}
米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!"
}
}
}
您在 angular 中的 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
编辑:在 'hello' 周围添加引号。现在它被视为文本而不是变量。