Skip to content

Commit 1daa081

Browse files
committed
Module forRoot update
1 parent 7b19eee commit 1daa081

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

src/I18nextNamespaceResolver.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { ITranslationService } from './ITranslationService';
44

55
// tslint:disable-next-line:variable-name
66
export const I18nextNamespaceResolver: FactoryProvider = {
7-
provide: I18NEXT_NAMESPACE_RESOLVER,
8-
useFactory: (i18next: ITranslationService) =>
9-
(activatedRouteSnapshot, routerStateSnapshot): Promise<void> => {
10-
let namespaces: string[] = [];
11-
namespaces = activatedRouteSnapshot.data && activatedRouteSnapshot.data.i18nextNamespaces || namespaces;
12-
return i18next.loadNamespaces(namespaces.filter(n => n));
13-
},
14-
deps: [I18NEXT_SERVICE]
15-
};
7+
provide: I18NEXT_NAMESPACE_RESOLVER,
8+
useFactory: (i18next: ITranslationService) =>
9+
(activatedRouteSnapshot, routerStateSnapshot): Promise<void> => {
10+
let namespaces: string[] = [];
11+
namespaces = activatedRouteSnapshot.data && activatedRouteSnapshot.data.i18nextNamespaces || namespaces;
12+
return i18next.loadNamespaces(namespaces.filter(n => n));
13+
},
14+
deps: [I18NEXT_SERVICE]
15+
};

src/index.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ import { I18nextNamespaceResolver } from './I18nextNamespaceResolver';
3030
useValue: ''
3131
},
3232
I18NextPipe,
33-
I18NextTitle,
34-
{
35-
provide: Title,
36-
useClass: I18NextTitle
37-
}
33+
I18NextCapPipe,
34+
I18NextTitle
3835
],
3936
declarations: [
4037
I18NextPipe,
@@ -46,19 +43,28 @@ import { I18nextNamespaceResolver } from './I18nextNamespaceResolver';
4643
]
4744
})
4845
export class I18NextModule {
49-
static forRoot(): ModuleWithProviders {
46+
static forRoot(localizeTitle: boolean = false): ModuleWithProviders {
47+
let providers: any = [
48+
{
49+
provide: I18NEXT_SERVICE,
50+
useClass: I18NextService
51+
},
52+
I18NextService,
53+
I18NextPipe,
54+
I18NextCapPipe,
55+
I18nextNamespaceResolver
56+
];
57+
58+
if (localizeTitle){
59+
providers.push({
60+
provide: Title,
61+
useClass: I18NextTitle
62+
});
63+
}
64+
5065
return {
5166
ngModule: I18NextModule,
52-
providers: [
53-
{
54-
provide: I18NEXT_SERVICE,
55-
useClass: I18NextService
56-
},
57-
I18NextService,
58-
I18NextPipe,
59-
I18NextCapPipe,
60-
I18nextNamespaceResolver
61-
]
67+
providers: providers
6268
};
6369
}
6470
}

0 commit comments

Comments
 (0)