我有以下问题。如何在ng2-translate
中翻译@Input()
from angular2?将非常感谢任何帮助。如果您对我的代码有任何其他问题,请询问。ng2 translate和@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"
}
}
我不认为你可以像这样翻译动态输入,除非你已经有了给定输入的翻译。纠正我,如果我错了。 – John
但它只是一个数字。我不想做{{'Contact.Text'| translate:telNumber}} {{telephone}}。我想将此电话发送至en.json – qwerty1234567
对不起,请问,但您为什么要将电话号码发送到'en.json'?任何语言的数字都不一样?我想你有你的理由,我只是好奇。 – John