I am trying to set up localization with angular l10n library. I successfully implemented a module and initialized it before the UI is loaded for main translation. Now my intention is to have separate translation files/endpoints for every module and lazy load it on top of the default initialization.
This is module I came up, let's call it SomeModule
import { Injectable, NgModule, Inject, APP_INITIALIZER } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LocaleService, TranslationService, TranslationModule, LocalizationModule, L10nLoader, L10N_CONFIG, L10nConfig, L10nConfigRef, ProviderType } from 'angular-l10n';
import { SomeComponent } from './some.component';
@NgModule({
declarations: [
SomeComponent
]
imports: [
CommonModule,
LocalizationModule,
TranslationModule,
],
exports: [
TranslationModule
],
providers: [
],
entryComponents: [SomeComponent]
})
export class SomeModule {
constructor(
@Inject(L10N_CONFIG)
public l10nLoader: L10nLoader,
private configuration: L10nConfigRef,
private translation: TranslationService,
) {
this.load();
}
load() {
this.configuration.translation.providers = [
{ type: ProviderType.Static, prefix: './api/main/' },
{ type: ProviderType.Static, prefix: './api/other/' }
];
this.l10nLoader.load().then(() => {
this.translation.init();
// this.translation.loadTranslation();
})
}
}
By accessing the L10nConfigRef I managed to add there more providers on top of the default init translation. I could see in the browser network that the translation is successfully loaded.
The problem is, it's loaded after all my view/components and it does not refresh the translation.
So how could I reinitialized the translation and manually trigger/emit the translationChanged?
The this.translation.init() does not work neither this.translation.loadTranslation() - the latest is not even a public method in the library so that's neither the right way.
Any other suggestion how to reinit the library and trigger translationChanged?
from Angular l10n localization - load translation in separate modules - does not trigger translationChanged
No comments:
Post a Comment