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