Romanchuk / angular-i18next

angular v10+ integration with i18next v19.4+
MIT License
131 stars 33 forks source link

reloadResources is not triggering newly added resources with addResourcesBundle #126

Closed sriram275 closed 1 week ago

sriram275 commented 1 month ago

Hi @Romanchuk , I am making API call in constructor to get new Resources for feature module. And adding those resources using addResourceBundle. While API call in progress or addResourceBundle in progress template already initialized and displayed with out translations.

After addResourceBundle how to re trigger to effect all new resources? I tried like below -

constructor(...) {
this.http.get(jsonURL).subscribe(resources => {
                this.i18NextService.addResourceBundle(language, defaultNs, resources, true, false)
                this.i18NextService.events.loaded.subscribe(() => { //I tried added but no event coming
                    console.log('---> All resources loaded')
                    this.i18NextService.reloadResources([language], [defaultNs])
                })
            })
}

But no luck. How to re trigger this? is there any other way?

Thanks in advance.

Romanchuk commented 1 month ago

@sriram275 Hello!

While API call in progress or addResourceBundle in progress template already initialized and displayed with out translations.

I don't understand your case completelly. Why you allow a template to initialize without loaded resource? Do your load in a route resolver or guard.

this.i18NextService.events.loaded.subscribe(() => { //I tried added but no event coming

'loaded' event is for initial load, use 'added' event - https://www.i18next.com/overview/api#onadded

General advice: Always subscribe to event you expect to be fired after call - BEFORE calling method that you expect to trigger this event.

Your questions mostly is irrelevant to my project because it is a wrapper of an original i18next. Explore i18next docs and API to better understand which method trigger which event: https://www.i18next.com/overview/getting-started