-
Notifications
You must be signed in to change notification settings - Fork 445
/
multilingual.module.ts
67 lines (60 loc) · 1.81 KB
/
multilingual.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// angular
import { NgModule, ModuleWithProviders, Optional, SkipSelf, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpModule, Http } from '@angular/http';
// libs
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
// module
import { Config } from '../core/index';
import { MULTILANG_COMPONENTS } from './components/index';
import { MULTILANG_PROVIDERS } from './services/index';
// for AoT compilation
export function translateLoaderFactory(http: Http) {
return new TranslateHttpLoader(http, `${Config.IS_MOBILE_NATIVE() ? '/' : ''}assets/i18n/`, '.json');
}
/**
* Do not specify providers for modules that might be imported by a lazy loaded module.
*/
@NgModule({
imports: [
CommonModule,
HttpModule,
FormsModule,
TranslateModule.forRoot([{
provide: TranslateLoader,
deps: [Http],
useFactory: (translateLoaderFactory)
}]),
],
declarations: [
...MULTILANG_COMPONENTS
],
providers: [
...MULTILANG_PROVIDERS,
],
exports: [
...MULTILANG_COMPONENTS,
TranslateModule
],
schemas: [
NO_ERRORS_SCHEMA,
CUSTOM_ELEMENTS_SCHEMA
]
})
export class MultilingualModule {
// optional usage
// ideally we could use this to override TranslateModule, but it requires the static above at moment
static forRoot(configuredProviders: Array<any>): ModuleWithProviders {
return {
ngModule: MultilingualModule,
providers: configuredProviders
};
}
constructor(@Optional() @SkipSelf() parentModule: MultilingualModule) {
if (parentModule) {
throw new Error('MultilingualModule already loaded; Import in root module only.');
}
}
}