Can I use Angular i18n to translate string literals in typescript code

I can confirm what @JB Nizet is referring to in his answer is now working in Angular 9, so this works:

  foo() {
    const appTitle = $localize`:@@siteTitle:Example Title`;
    // appTitle is now translated based on locale

    titleService.setTitle(appTitle); 
  }

You can read more about it here https://github.com/angular/angular/blob/master/packages/localize/init/index.ts

Leave a Comment