angular-i18n work-around for translations in code?

前端 未结 5 1319
不知归路
不知归路 2020-11-28 12:26

We have to wait until Angular 6 for angular-i18n to support translations in code for error messages and such.

For those that are using angular-i18n (instead of ngx-t

5条回答
  •  鱼传尺愫
    2020-11-28 13:10

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

    In a nutshell:

    There is $localize which can be used to do this.

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

    Unfortunately the feature is not realy complete yet:

    You can then translate the message the same way you would for a template. But, right now (v9.0.0), the CLI does not extract these messages with the xi18n command as it does for templates.

提交回复
热议问题