Angular 9: i18n in TypeScript

后端 未结 3 779
悲&欢浪女
悲&欢浪女 2021-01-02 01:53

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

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

3条回答
  •  臣服心动
    2021-01-02 02:13

    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

    
      You have 10 users
      Vous avez 10 utilisateurs
    
    

    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

提交回复
热议问题