1
0
Fork 0
peertube/client/src/app/app.module.ts

93 lines
3.0 KiB
TypeScript
Raw Normal View History

2018-05-31 16:12:15 +00:00
import { LOCALE_ID, NgModule, TRANSLATIONS, TRANSLATIONS_FORMAT } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
2018-03-22 13:13:30 +00:00
import { ServerService } from '@app/core'
2018-01-30 12:27:07 +00:00
import { ResetPasswordModule } from '@app/reset-password'
2016-09-06 20:40:57 +00:00
2018-01-30 12:27:07 +00:00
import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'
2018-05-29 09:40:46 +00:00
import { ClipboardModule } from 'ngx-clipboard'
import 'focus-visible'
2018-01-30 12:27:07 +00:00
import { AppRoutingModule } from './app-routing.module'
import { AppComponent } from './app.component'
import { CoreModule } from './core'
2018-01-30 12:27:07 +00:00
import { HeaderComponent } from './header'
import { LoginModule } from './login'
2019-01-08 10:26:41 +00:00
import { AvatarNotificationComponent, LanguageChooserComponent, MenuComponent } from './menu'
import { SharedModule } from './shared'
import { VideosModule } from './videos'
import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '../../../shared/models/i18n'
2018-06-06 15:37:13 +00:00
import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils'
2018-07-19 14:17:54 +00:00
import { SearchModule } from '@app/search'
2019-08-28 12:40:06 +00:00
import { WelcomeModalComponent } from '@app/modal/welcome-modal.component'
import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component'
2016-11-20 16:18:15 +00:00
2018-03-22 13:13:30 +00:00
export function metaFactory (serverService: ServerService): MetaLoader {
2017-03-10 09:33:36 +00:00
return new MetaStaticLoader({
pageTitlePositioning: PageTitlePositioning.PrependPageTitle,
pageTitleSeparator: ' - ',
2019-12-18 14:31:54 +00:00
get applicationName () { return serverService.getTmpConfig().instance.name },
2017-03-10 09:33:36 +00:00
defaults: {
2019-12-18 14:31:54 +00:00
get title () { return serverService.getTmpConfig().instance.name },
get description () { return serverService.getTmpConfig().instance.shortDescription }
2017-03-10 09:33:36 +00:00
}
})
2017-03-10 09:33:36 +00:00
}
2016-11-04 16:25:26 +00:00
2016-09-06 20:40:57 +00:00
@NgModule({
bootstrap: [ AppComponent ],
declarations: [
2017-12-01 08:20:19 +00:00
AppComponent,
MenuComponent,
2018-06-28 11:59:48 +00:00
LanguageChooserComponent,
2019-01-08 10:26:41 +00:00
AvatarNotificationComponent,
2019-08-28 12:40:06 +00:00
HeaderComponent,
WelcomeModalComponent,
InstanceConfigWarningModalComponent
2016-09-06 20:40:57 +00:00
],
2016-11-20 16:18:15 +00:00
imports: [
2016-09-06 20:40:57 +00:00
BrowserModule,
2016-09-09 20:23:41 +00:00
2016-11-20 16:18:15 +00:00
CoreModule,
SharedModule,
CoreModule,
LoginModule,
2018-01-30 12:27:07 +00:00
ResetPasswordModule,
2018-07-19 14:17:54 +00:00
SearchModule,
2016-11-20 16:18:15 +00:00
SharedModule,
2017-03-12 17:40:05 +00:00
VideosModule,
MetaModule.forRoot({
provide: MetaLoader,
2018-03-22 13:13:30 +00:00
useFactory: (metaFactory),
deps: [ ServerService ]
2018-05-31 09:35:01 +00:00
}),
2018-05-31 12:43:48 +00:00
AppRoutingModule // Put it after all the module because it has the 404 route
2016-09-06 20:40:57 +00:00
],
2018-05-31 16:12:15 +00:00
providers: [
{
provide: TRANSLATIONS,
useFactory: (locale: string) => {
2018-06-06 15:37:13 +00:00
// On dev mode, test localization
if (isOnDevLocale()) {
2018-08-16 09:48:48 +00:00
locale = buildFileLocale(getDevLocale())
2019-11-07 14:33:23 +00:00
return require(`raw-loader!../locale/angular.${locale}.xlf`)
2018-06-05 13:01:45 +00:00
}
2018-05-31 16:12:15 +00:00
// Default locale, nothing to translate
2018-06-06 15:37:13 +00:00
const completeLocale = getCompleteLocale(locale)
if (isDefaultLocale(completeLocale)) return ''
2018-05-31 16:12:15 +00:00
2018-06-06 15:37:13 +00:00
const fileLocale = buildFileLocale(locale)
2019-11-07 14:33:23 +00:00
return require(`raw-loader!../locale/angular.${fileLocale}.xlf`)
2018-05-31 16:12:15 +00:00
},
deps: [ LOCALE_ID ]
},
{ provide: TRANSLATIONS_FORMAT, useValue: 'xlf' }
]
2016-09-06 20:40:57 +00:00
})
2017-12-11 16:36:46 +00:00
export class AppModule {}