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