【发布时间】:2017-05-04 18:49:30
【问题描述】:
我知道 Angular 2 i18n 有两个主要平台:The official way 和 ng2-translate。我更倾向于使用官方文档推荐的内容。对我来说,如何翻译 HTML 字符串非常清楚。但有一件事我还没有得到:如何翻译 Typescript 字符串?
例如,我有以下使用内置 i18n 解决方案的组件:
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'hello',
template: `
<h1 i18n>Hello {{name}}!</h1>
<button (click)="notify()"></button>
`
})
export class HelloComponent {
private name = 'John Doe';
notify() {
/* How do I translate this? */
alert(`Hello ${this.name}!`);
}
}
放置在 HTML 中的字符串将被翻译。但是如何翻译警报中显示的字符串?如果没有本地方法,那么推荐的方法是什么?
【问题讨论】:
-
查看文档,
i18n似乎专门用于组件模板文本。 -
目前还没有正式的方法。 github.com/angular/angular/issues/11405 对此投赞成票,以便他们优先考虑!
-
@SimonBriggs 感谢您指出问题。
标签: angular typescript