e61346dac9addbbccb0d45f2b662ef1aa99ecdcf
[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 import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'
6 import 'focus-visible'
7
8 import { AppRoutingModule } from './app-routing.module'
9 import { AppComponent } from './app.component'
10 import { CoreModule } from './core'
11 import { HeaderComponent, SearchTypeaheadComponent, SuggestionsComponent, SuggestionComponent } from './header'
12 import { LoginModule } from './login'
13 import { AvatarNotificationComponent, LanguageChooserComponent, MenuComponent } from './menu'
14 import { SharedModule } from './shared'
15 import { VideosModule } from './videos'
16 import { SearchModule } from '@app/search'
17 import { WelcomeModalComponent } from '@app/modal/welcome-modal.component'
18 import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component'
19 import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '@shared/models'
20 import { APP_BASE_HREF, registerLocaleData } from '@angular/common'
21 import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component'
22 import { CustomModalComponent } from '@app/modal/custom-modal.component'
23 import localeOc from '@app/shared/locale/oc'
24
25 registerLocaleData(localeOc, 'oc')
26
27 @NgModule({
28   bootstrap: [ AppComponent ],
29   declarations: [
30     AppComponent,
31
32     MenuComponent,
33     LanguageChooserComponent,
34     QuickSettingsModalComponent,
35     AvatarNotificationComponent,
36     HeaderComponent,
37     SearchTypeaheadComponent,
38     SuggestionsComponent,
39     SuggestionComponent,
40
41     CustomModalComponent,
42     WelcomeModalComponent,
43     InstanceConfigWarningModalComponent
44   ],
45   imports: [
46     BrowserModule,
47
48     CoreModule,
49     SharedModule,
50
51     CoreModule,
52     LoginModule,
53     ResetPasswordModule,
54     SearchModule,
55     SharedModule,
56     VideosModule,
57
58     MetaModule.forRoot({
59       provide: MetaLoader,
60       useFactory: (serverService: ServerService) => {
61         return new MetaStaticLoader({
62           pageTitlePositioning: PageTitlePositioning.PrependPageTitle,
63           pageTitleSeparator: ' - ',
64           get applicationName () { return serverService.getTmpConfig().instance.name },
65           defaults: {
66             get title () { return serverService.getTmpConfig().instance.name },
67             get description () { return serverService.getTmpConfig().instance.shortDescription }
68           }
69         })
70       },
71       deps: [ ServerService ]
72     }),
73
74     AppRoutingModule // Put it after all the module because it has the 404 route
75   ],
76
77   providers: [
78     {
79       provide: APP_BASE_HREF,
80       useValue: '/'
81     },
82
83     {
84       provide: TRANSLATIONS,
85       useFactory: (locale: string) => {
86         // Default locale, nothing to translate
87         const completeLocale = getCompleteLocale(locale)
88         if (isDefaultLocale(completeLocale)) return ''
89
90         const fileLocale = buildFileLocale(locale)
91         return require(`raw-loader!../locale/angular.${fileLocale}.xlf`).default
92       },
93       deps: [ LOCALE_ID ]
94     },
95     { provide: TRANSLATIONS_FORMAT, useValue: 'xlf' }
96   ]
97 })
98 export class AppModule {}