Angular 9: i18n in TypeScript

回眸只為那壹抹淺笑 提交于 2020-05-13 05:35:06

问题


I studied the new i18n feature in Angular 9. https://angular.io/guide/i18n

How to translate text in TypeScript, e.g. SnackBar messages?


回答1:


Check this blog https://blog.ninja-squad.com/2019/12/10/angular-localize/

@Component({
  template: '{{ title }}'
})
export class HomeComponent {
  title = $localize`You have 10 users`;
}

And

You have to manually add it to your messages.fr.xlf

<trans-unit id="6480943972743237078">
  <source>You have 10 users</source>
  <target>Vous avez 10 utilisateurs</target>
</trans-unit>

don't forgot re serve your angular application.

UPDATE FOR ID

@Component({
  template: '{{ title }}'
})
export class HomeComponent {
  title = $localize`:@@6480943972743237078:`;
}

https://github.com/angular/angular/blob/252966bcca91ea4deb0e52f1f1d0d3f103f84ccd/packages/localize/init/index.ts#L31



来源:https://stackoverflow.com/questions/60271964/angular-9-i18n-in-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!