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