robisim74 / angular-l10n

Angular library to translate texts, dates and numbers
MIT License
380 stars 59 forks source link

angular-l10n used in angular component being imported from react parent application as library doesnot work #344

Closed nishantks15 closed 8 months ago

nishantks15 commented 9 months ago

I have a angular project which uses this L10nTranslationModule from angular-l10n. This angular project compiles and creates library.

This angular project (library) is being used/imported from react client application and the translation does not work. It doesn't give any error.

I cannot import angular-l10n in react as it is unsupported there. Am I missing anything while implementing ?

Simple feature of this.translationService.setLocale('en-US') at one place and getting this locale at other place gives blank value instead of 'en-US'

robisim74 commented 9 months ago

Without any relevant information, it is not possible to determine what is happening in your project, and no help can be provided.

If you are exporting only the components, the library is most likely not initialized. Initialization defines the locale, loads translation files etc. otherwise you get only empty values. Therefore it is necessary to call L10nTranslationModule.forRoot in AppModule orprovideL10nTranslation in a standalone app (from Angular v16).

See also this issues:

Greetings

nishantks15 commented 9 months ago

I have created custom angular library in Angular version 9. angular-l10n library used in this custom angular library is implemented correctly(including L10nTranslationModule.forRoot in AppModule) as when I import this custom library from another angular project with version 15 then it works fine. It does translation to different languages.

But when I use this custom angular library from React project then it doesn't work. What doesnot work ? After setLocale, getLocale does not give value back.

robisim74 commented 9 months ago

I'm sorry, but using an Angular app, transformed into a library, inside a React app is not a common or project-supported scenario.

Again, if you want help you need to enable me to recreate the problem or provide minimal reproduction.

I have some basic information:

And again: does everything in the Angular library work once imported into React? Angular routing, other libraries using forRoot?

And then regarding angular-l10n you should debug it and see if it is initialized: are the translation files loaded? setLocale changes the locale at runtime, but only if it has been initialized, otherwise it does nothing

nishantks15 commented 9 months ago

so this way I am passing language and then custom library uses this language to set to ln10translation service of angular10n and then I use getLocale at some other place e,g. interceptor to send this language as part of each request to backend api.

Bases on this language we load the translation file dynamically. Now since we are not getting any value from getLocale, we are not able to load translations or read from interceptor or any other file.

robisim74 commented 9 months ago

The code of this library is open source: here is the list of versions, and here the v9 branch

And finally here the setLocale method: https://github.com/robisim74/angular-l10n/blob/angular_v9/projects/angular-l10n/src/lib/services/l10n-translation.service.ts#L49-L51

Before you can use a library in an unconventional way, you should understand how it works, or provide the code you are trying to use.

Hope this helps.

Greetings

nishantks15 commented 9 months ago
robisim74 commented 9 months ago

@nishantks15 What happens in your app at the following points I reported above?

https://github.com/robisim74/angular-l10n/blob/angular_v9/projects/angular-l10n/src/lib/services/l10n-translation.service.ts#L163

https://github.com/robisim74/angular-l10n/blob/angular_v9/projects/angular-l10n/src/lib/services/l10n-translation.service.ts#L173

Without a reproduction, you need to provide at least the result of a debug.

robisim74 commented 8 months ago

Closing due to lack of reproduction and feedback.