]>
Commit | Line | Data |
---|---|---|
1 | import { LOCALE_ID, NgModule, TRANSLATIONS, TRANSLATIONS_FORMAT } from '@angular/core' | |
2 | import { BrowserModule } from '@angular/platform-browser' | |
3 | import { ServerService } from '@app/core' | |
4 | import { ResetPasswordModule } from '@app/reset-password' | |
5 | ||
6 | import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core' | |
7 | import { ClipboardModule } from 'ngx-clipboard' | |
8 | import { HotkeyModule, IHotkeyOptions } from 'angular2-hotkeys' | |
9 | ||
10 | import { AppRoutingModule } from './app-routing.module' | |
11 | import { AppComponent } from './app.component' | |
12 | import { CoreModule } from './core' | |
13 | import { HeaderComponent } from './header' | |
14 | import { LoginModule } from './login' | |
15 | import { MenuComponent } from './menu' | |
16 | import { SharedModule } from './shared' | |
17 | import { SignupModule } from './signup' | |
18 | import { VideosModule } from './videos' | |
19 | import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '../../../shared/models/i18n' | |
20 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' | |
21 | import { LanguageChooserComponent } from '@app/menu/language-chooser.component' | |
22 | import { SearchModule } from '@app/search' | |
23 | ||
24 | export function metaFactory (serverService: ServerService): MetaLoader { | |
25 | return new MetaStaticLoader({ | |
26 | pageTitlePositioning: PageTitlePositioning.PrependPageTitle, | |
27 | pageTitleSeparator: ' - ', | |
28 | get applicationName () { return serverService.getConfig().instance.name }, | |
29 | defaults: { | |
30 | get title () { return serverService.getConfig().instance.name }, | |
31 | get description () { return serverService.getConfig().instance.shortDescription } | |
32 | } | |
33 | }) | |
34 | } | |
35 | ||
36 | @NgModule({ | |
37 | bootstrap: [ AppComponent ], | |
38 | declarations: [ | |
39 | AppComponent, | |
40 | ||
41 | MenuComponent, | |
42 | LanguageChooserComponent, | |
43 | HeaderComponent | |
44 | ], | |
45 | imports: [ | |
46 | BrowserModule, | |
47 | // FIXME: https://github.com/maxisam/ngx-clipboard/issues/133 | |
48 | ClipboardModule, | |
49 | HotkeyModule.forRoot({ | |
50 | cheatSheetCloseEsc: true | |
51 | } as IHotkeyOptions), | |
52 | ||
53 | CoreModule, | |
54 | SharedModule, | |
55 | ||
56 | CoreModule, | |
57 | LoginModule, | |
58 | ResetPasswordModule, | |
59 | SignupModule, | |
60 | SearchModule, | |
61 | SharedModule, | |
62 | VideosModule, | |
63 | ||
64 | MetaModule.forRoot({ | |
65 | provide: MetaLoader, | |
66 | useFactory: (metaFactory), | |
67 | deps: [ ServerService ] | |
68 | }), | |
69 | ||
70 | AppRoutingModule // Put it after all the module because it has the 404 route | |
71 | ], | |
72 | providers: [ | |
73 | { | |
74 | provide: TRANSLATIONS, | |
75 | useFactory: (locale) => { | |
76 | // On dev mode, test localization | |
77 | if (isOnDevLocale()) { | |
78 | locale = buildFileLocale(getDevLocale()) | |
79 | return require(`raw-loader!../locale/target/angular_${locale}.xml`) | |
80 | } | |
81 | ||
82 | // Default locale, nothing to translate | |
83 | const completeLocale = getCompleteLocale(locale) | |
84 | if (isDefaultLocale(completeLocale)) return '' | |
85 | ||
86 | const fileLocale = buildFileLocale(locale) | |
87 | return require(`raw-loader!../locale/target/angular_${fileLocale}.xml`) | |
88 | }, | |
89 | deps: [ LOCALE_ID ] | |
90 | }, | |
91 | { provide: TRANSLATIONS_FORMAT, useValue: 'xlf' } | |
92 | ] | |
93 | }) | |
94 | export class AppModule {} |