aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-02-07 15:51:19 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-02-10 16:39:28 +0100
commit361dcebc75dea74947b6c3aafd9d7d720c054b01 (patch)
tree5edf2a0d871097ba7da2b974b8ccdef9c6b73261 /client/src
parentf77eb73b5e02bed9e223dafc1c203ceb7c05b6e5 (diff)
downloadPeerTube-361dcebc75dea74947b6c3aafd9d7d720c054b01.tar.gz
PeerTube-361dcebc75dea74947b6c3aafd9d7d720c054b01.tar.zst
PeerTube-361dcebc75dea74947b6c3aafd9d7d720c054b01.zip
Support i18n build
Diffstat (limited to 'client/src')
-rw-r--r--client/src/app/app.module.ts13
-rw-r--r--client/src/environments/environment.ts3
-rw-r--r--client/src/main.ts28
3 files changed, 11 insertions, 33 deletions
diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts
index 62915ec54..14fdb7588 100644
--- a/client/src/app/app.module.ts
+++ b/client/src/app/app.module.ts
@@ -4,7 +4,6 @@ import { ServerService } from '@app/core'
4import { ResetPasswordModule } from '@app/reset-password' 4import { ResetPasswordModule } from '@app/reset-password'
5 5
6import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core' 6import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'
7import { ClipboardModule } from 'ngx-clipboard'
8import 'focus-visible' 7import 'focus-visible'
9 8
10import { AppRoutingModule } from './app-routing.module' 9import { AppRoutingModule } from './app-routing.module'
@@ -15,11 +14,10 @@ import { LoginModule } from './login'
15import { AvatarNotificationComponent, LanguageChooserComponent, MenuComponent } from './menu' 14import { AvatarNotificationComponent, LanguageChooserComponent, MenuComponent } from './menu'
16import { SharedModule } from './shared' 15import { SharedModule } from './shared'
17import { VideosModule } from './videos' 16import { VideosModule } from './videos'
18import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '../../../shared/models/i18n'
19import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils'
20import { SearchModule } from '@app/search' 17import { SearchModule } from '@app/search'
21import { WelcomeModalComponent } from '@app/modal/welcome-modal.component' 18import { WelcomeModalComponent } from '@app/modal/welcome-modal.component'
22import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component' 19import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-warning-modal.component'
20import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '@shared/models'
23 21
24export function metaFactory (serverService: ServerService): MetaLoader { 22export function metaFactory (serverService: ServerService): MetaLoader {
25 return new MetaStaticLoader({ 23 return new MetaStaticLoader({
@@ -67,17 +65,12 @@ export function metaFactory (serverService: ServerService): MetaLoader {
67 65
68 AppRoutingModule // Put it after all the module because it has the 404 route 66 AppRoutingModule // Put it after all the module because it has the 404 route
69 ], 67 ],
68
70 providers: [ 69 providers: [
71 { 70 {
72 provide: TRANSLATIONS, 71 provide: TRANSLATIONS,
73 useFactory: (locale: string) => { 72 useFactory: (locale: string) => {
74 // On dev mode, test localization 73 // Default locale, nothing to translate
75 if (isOnDevLocale()) {
76 locale = buildFileLocale(getDevLocale())
77 return require(`raw-loader!../locale/angular.${locale}.xlf`)
78 }
79
80 // Default locale, nothing to translate
81 const completeLocale = getCompleteLocale(locale) 74 const completeLocale = getCompleteLocale(locale)
82 if (isDefaultLocale(completeLocale)) return '' 75 if (isDefaultLocale(completeLocale)) return ''
83 76
diff --git a/client/src/environments/environment.ts b/client/src/environments/environment.ts
index 1ea483554..b6bc784b5 100644
--- a/client/src/environments/environment.ts
+++ b/client/src/environments/environment.ts
@@ -6,8 +6,7 @@
6// 6//
7// In order to load these polyfills early enough (before app code), polyfill.ts imports this file to 7// In order to load these polyfills early enough (before app code), polyfill.ts imports this file to
8// to change the order in the final bundle. 8// to change the order in the final bundle.
9import 'core-js/es6/reflect' 9import 'core-js/features/reflect'
10import 'core-js/es7/reflect'
11 10
12export const environment = { 11export const environment = {
13 production: false, 12 production: false,
diff --git a/client/src/main.ts b/client/src/main.ts
index 2b65072ad..3fb9b346e 100644
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -1,31 +1,17 @@
1import { enableProdMode, TRANSLATIONS, TRANSLATIONS_FORMAT } from '@angular/core' 1import { enableProdMode } from '@angular/core'
2import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' 2import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
3 3
4import { AppModule } from './app/app.module' 4import { AppModule } from './app/app.module'
5import { environment } from './environments/environment' 5import { environment } from './environments/environment'
6 6
7import { hmrBootstrap } from './hmr' 7import { hmrBootstrap } from './hmr'
8import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils'
9import { buildFileLocale } from '../../shared'
10 8
11let providers: any[] = []
12if (environment.production) { 9if (environment.production) {
13 enableProdMode() 10 enableProdMode()
14} 11}
15 12
16// Template translation, should be in the bootstrap step
17if (isOnDevLocale()) {
18 const locale = buildFileLocale(getDevLocale())
19 const translations = require(`raw-loader!./locale/angular.${locale}.xlf`)
20
21 providers = [
22 { provide: TRANSLATIONS, useValue: translations },
23 { provide: TRANSLATIONS_FORMAT, useValue: 'xlf' }
24 ]
25}
26
27const bootstrap = () => platformBrowserDynamic() 13const bootstrap = () => platformBrowserDynamic()
28 .bootstrapModule(AppModule, { providers }) 14 .bootstrapModule(AppModule)
29 .then(bootstrapModule => { 15 .then(bootstrapModule => {
30 // TODO: Uncomment and remove unregistration when https://github.com/angular/angular/issues/21191 is fixed 16 // TODO: Uncomment and remove unregistration when https://github.com/angular/angular/issues/21191 is fixed
31 // TODO: Remove when https://github.com/angular/angular-cli/issues/8779 is fixed? 17 // TODO: Remove when https://github.com/angular/angular-cli/issues/8779 is fixed?
@@ -36,11 +22,11 @@ const bootstrap = () => platformBrowserDynamic()
36 22
37 if (navigator.serviceWorker && typeof navigator.serviceWorker.getRegistrations === 'function') { 23 if (navigator.serviceWorker && typeof navigator.serviceWorker.getRegistrations === 'function') {
38 navigator.serviceWorker.getRegistrations() 24 navigator.serviceWorker.getRegistrations()
39 .then(registrations => { 25 .then(registrations => {
40 for (const registration of registrations) { 26 for (const registration of registrations) {
41 registration.unregister() 27 registration.unregister()
42 } 28 }
43 }) 29 })
44 } 30 }
45 31
46 return bootstrapModule 32 return bootstrapModule