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