How to add localization in Angular Library using localize?

375 Views Asked by At

I want to add localization in my custom angular library. It must be done using localize(not ngx-translate). I tried localize documentation nut it is not creating translation files. When I run 'ng i18n --output-path src/locale' it gives an error. Ivy extraction requires the '@angular/localize' package. Please let me know if someone know about it

1

There are 1 best solutions below

2
On

I don't think it's possible to add the localization file inside the library . I create a few angular libraries but the localization file is inside the app that installed the libraries, and all the translation unit go to this file...

be aware if you want to implement localize in the ts file for example:

$localize`my word`;

sometimes it will not work when you try to build it because the library doesn't see this function. the solution for it is to declare the method in your library: create file next to package.json file and this inside:

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

I hope it was helpful :)