2

I have an angular library and in this library I have text that are to be translated.

My library exists in an nx monorepo.

I am not making any applications so I have no application context to perform configuration in.

In other unrelated projects I have achieved translations by defining them like this:

public inspectionOrder(): string { return $localize`:@@InspectionOrder:Inspection order`; } 

and configuring localize in main.ts like this

import "@angular/localize/init"; 

After this the translations that are used in the application are found up and added to the *.xlf file when running nx extract-i18n <application-name>.

However in a library:

  1. I have no main.ts to import "@angular/localize/init"
  2. I have no context (application) to use them so translations are not found and not added to the *.xlf file

And how would it even work if my npm package is shipped with *.xlf files? Would applications need to merge their *.xlf files with mine?

Either I am missing something basic or the concept of translation provided by angular is not designed for standalone libraries.

Can someone provide we with suggestions / guidance on how to perform translations in an angular standalone library with no application context?

Most optimally through the official way of managing translations if possible.

Thanks in advance!

I have tried following the official guide. I expected the guide or the official documentation to contain a description of how to manage translations in a standalone angular library. I might have missed something though as i see this as a fairly basic thing to do.

Seems to me that the way of translating libraries should be done in an application context but this is not an option for me. I have to fully control all translations within the library.

2
  • This answer might help you - Localize angular library with ngx-translate Commented Aug 7, 2024 at 12:41
  • I looked at this but not it's not what angular is shipped with, however still popular. Might end up with something like that if Angular have nothing out of the box. Thanks! :) Commented Aug 7, 2024 at 13:01

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.