【发布时间】:2017-03-29 10:43:33
【问题描述】:
我有以下问题。如何在ng2-translate 中从angular2 翻译@Input()?将非常感谢任何帮助。如果您对我的代码有任何其他问题,请询问。
我来了
您的电话号码:123 {{ 电话 }}
我的代码
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'child',
template: `
<span> {{ 'Contact.Text' | translate:telNumber:telephone }}</span>
<input type="text" placeholder="{{ 'Contact.Input' | translate }}">
`
})
export class ChildComponent implements OnInit {
@Input() telephone: number; // <- this one
telNumber = { value: 123 };
constructor() { }
ngOnInit() { }
}
en.json
{
"Navigation": {
"First": "Main Page",
"Second": "Menu",
"Third": "Contact",
"ChangeLanguage": "Change language"
},
"Mainpage": {
"Title": "Welcome to the home page",
"Content": "This home page is the most beautiful homepage you have ever seen"
},
"Menu": {
"Title": "Animals",
"FirstAnimal": "Dog",
"SecondAnimal": "Cat",
"ThirdAnimal": "Cow",
"FourthAnimal": "Pig",
"FifthAnimal": "Bird"
},
"Contact": {
"Title": "Contact to us",
"Text": "Your phone number: {{ value }} {{ telephone }}",
"Input": "Deutschland Name"
}
}
【问题讨论】:
-
我认为您不能像这样翻译动态输入,除非您已经对给定输入进行了翻译。如果我错了,请纠正我。
-
但这只是一个数字。我不想做 {{ 'Contact.Text' |翻译:电话号码 }} {{ 电话 }}。我想把这个电话发给 en.json
-
不好意思问,为什么要把电话号码发给
en.json?任何语言的数字都不一样吗?我想你有你的理由,我只是好奇。 -
有时我想使用“您的电话号码:12334。谢谢”。你知道,文本中的数字(中心)不是最后:)
标签: angular input ng2-translate