Skip to content

Commit

Permalink
fix(core): translation provide TranslateModule with LanguageService
Browse files Browse the repository at this point in the history
  • Loading branch information
alecarn committed Jan 8, 2024
1 parent f6ed93a commit 225f808
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/lib/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ const dbConfig: DBConfig = {
IgoActivityModule.forRoot(),
IgoConfigModule.forRoot(),
IgoErrorModule.forRoot(),
provideRootTranslation(),
IgoMessageModule,
NgxIndexedDBModule.forRoot(dbConfig)
],
providers: [provideRootTranslation()],
declarations: [],
exports: [
IgoActivityModule,
Expand Down
21 changes: 18 additions & 3 deletions packages/core/src/lib/language/shared/language.provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { HttpBackend } from '@angular/common/http';
import { ImportProvidersSource, Provider } from '@angular/core';
import {
APP_INITIALIZER,
EnvironmentProviders,
Provider,
importProvidersFrom,
makeEnvironmentProviders
} from '@angular/core';

import {
MissingTranslationHandler,
Expand All @@ -10,15 +16,24 @@ import {

import { ConfigService } from '../../config';
import { LanguageLoader } from './language.loader';
import { LanguageService } from './language.service';
import { IgoMissingTranslationHandler } from './missing-translation.guard';

/**
* Make sure you only call this method in the root module of your application, most of the time called AppModule.
*/
export function provideRootTranslation(
loader?: Provider
): ImportProvidersSource {
return TranslateModule.forRoot(setTranslationConfig(loader));
): EnvironmentProviders {
return makeEnvironmentProviders([
importProvidersFrom(TranslateModule.forRoot(setTranslationConfig(loader))),
{
provide: APP_INITIALIZER,
useFactory: () => () => {},
deps: [LanguageService],
multi: true
}
]);
}

export const setTranslationConfig = (
Expand Down

0 comments on commit 225f808

Please sign in to comment.