Use $localize in Angular 10 (with ivy) Library

Viewed 392

I've build a local angular library with angular@10 using ivy and i want to use the new $localize string template functionality.

public test = $localize `:@@test:Test`;

Within a normal app i would enable this by adding @import '@angular/loclize/init'; to the polyfill.ts, but within a library there are no polyfills.

When i try to build the library its fails, so i tried to import the @angular/localize/src/localize to the file in which i used the $localize. After doing that the build is running. But if i use the library within a app it says:

Can't resolve '@angular/localize/src/localize'

Has anyone a way to solve that? Maybe i am using the wrong approach.

1 Answers
declare function $localize(messageParts: TemplateStringsArray, ...expressions: readonly any[]): string;

add this line to file next to the src file of the library and you can use it in the same way like you use it in app and this is work fine.

Related