Romanchuk/angular-i18next

reloadResources is not triggering newly added resources with addResourcesBundle

Opened this issue · 1 comments

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.

@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