可运行代码如下:
{ { 'Hello' | translate }}
注意:使用translate的两种常见方式,
- Create a
pipe
that we can use to translate our words in the HTML view. Like this:
{ { 'hello world' | translate }}
- Create a
service
that we can use to translate our words in JS / Typescript. Like this:
...// should display 'hola mundo' when translated to Spanishthis.translatedText = this.translate.instant('hello world'); // this.translate is our translate service ... 第二种方式方便直接在ts文件中使用!不过翻译的东西依然是在
$translateProvider.translations 里! 参考:https://scotch.io/tutorials/simple-language-translation-in-angular-2-part-1