diff options
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/app/app.module.ts | 18 | ||||
-rw-r--r-- | client/src/app/core/server/server.service.ts | 20 | ||||
-rw-r--r-- | client/src/app/shared/i18n/i18n-utils.ts | 12 | ||||
-rw-r--r-- | client/src/app/shared/video/video.service.ts | 4 | ||||
-rw-r--r-- | client/src/app/videos/+video-watch/video-watch.component.ts | 3 | ||||
-rw-r--r-- | client/src/assets/player/peertube-player.ts | 10 | ||||
-rw-r--r-- | client/src/main.ts | 7 |
7 files changed, 47 insertions, 27 deletions
diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index e60a74cc0..51e354378 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts | |||
@@ -16,8 +16,8 @@ import { MenuComponent } from './menu' | |||
16 | import { SharedModule } from './shared' | 16 | import { SharedModule } from './shared' |
17 | import { SignupModule } from './signup' | 17 | import { SignupModule } from './signup' |
18 | import { VideosModule } from './videos' | 18 | import { VideosModule } from './videos' |
19 | import { buildFileLocale, getDefaultLocale } from '../../../shared/models/i18n' | 19 | import { buildFileLocale, getCompleteLocale, getDefaultLocale, isDefaultLocale } from '../../../shared/models/i18n' |
20 | import { environment } from '../environments/environment' | 20 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' |
21 | 21 | ||
22 | export function metaFactory (serverService: ServerService): MetaLoader { | 22 | export function metaFactory (serverService: ServerService): MetaLoader { |
23 | return new MetaStaticLoader({ | 23 | return new MetaStaticLoader({ |
@@ -67,17 +67,17 @@ export function metaFactory (serverService: ServerService): MetaLoader { | |||
67 | { | 67 | { |
68 | provide: TRANSLATIONS, | 68 | provide: TRANSLATIONS, |
69 | useFactory: (locale) => { | 69 | useFactory: (locale) => { |
70 | // On dev mode, test locales | 70 | // On dev mode, test localization |
71 | if (environment.production === false && window.location.search === '?lang=fr') { | 71 | if (isOnDevLocale()) { |
72 | return require(`raw-loader!../locale/target/angular_fr.xml`) | 72 | locale = getDevLocale() |
73 | return require(`raw-loader!../locale/target/angular_${locale}.xml`) | ||
73 | } | 74 | } |
74 | 75 | ||
75 | const fileLocale = buildFileLocale(locale) | ||
76 | |||
77 | // Default locale, nothing to translate | 76 | // Default locale, nothing to translate |
78 | const defaultFileLocale = buildFileLocale(getDefaultLocale()) | 77 | const completeLocale = getCompleteLocale(locale) |
79 | if (fileLocale === defaultFileLocale) return '' | 78 | if (isDefaultLocale(completeLocale)) return '' |
80 | 79 | ||
80 | const fileLocale = buildFileLocale(locale) | ||
81 | return require(`raw-loader!../locale/target/angular_${fileLocale}.xml`) | 81 | return require(`raw-loader!../locale/target/angular_${fileLocale}.xml`) |
82 | }, | 82 | }, |
83 | deps: [ LOCALE_ID ] | 83 | deps: [ LOCALE_ID ] |
diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index 56d33339e..74363e6a1 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts | |||
@@ -2,13 +2,13 @@ import { map, share, switchMap, tap } from 'rxjs/operators' | |||
2 | import { HttpClient } from '@angular/common/http' | 2 | import { HttpClient } from '@angular/common/http' |
3 | import { Inject, Injectable, LOCALE_ID } from '@angular/core' | 3 | import { Inject, Injectable, LOCALE_ID } from '@angular/core' |
4 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' | 4 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' |
5 | import { Observable, ReplaySubject } from 'rxjs' | 5 | import { Observable, ReplaySubject, of } from 'rxjs' |
6 | import { ServerConfig } from '../../../../../shared' | 6 | import { getCompleteLocale, ServerConfig } from '../../../../../shared' |
7 | import { About } from '../../../../../shared/models/server/about.model' | 7 | import { About } from '../../../../../shared/models/server/about.model' |
8 | import { environment } from '../../../environments/environment' | 8 | import { environment } from '../../../environments/environment' |
9 | import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos' | 9 | import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos' |
10 | import { buildFileLocale, getDefaultLocale } from '../../../../../shared/models/i18n' | 10 | import { isDefaultLocale } from '../../../../../shared/models/i18n' |
11 | import { peertubeTranslate } from '@app/shared/i18n/i18n-utils' | 11 | import { getDevLocale, isOnDevLocale, peertubeTranslate } from '@app/shared/i18n/i18n-utils' |
12 | 12 | ||
13 | @Injectable() | 13 | @Injectable() |
14 | export class ServerService { | 14 | export class ServerService { |
@@ -72,8 +72,8 @@ export class ServerService { | |||
72 | private http: HttpClient, | 72 | private http: HttpClient, |
73 | @Inject(LOCALE_ID) private localeId: string | 73 | @Inject(LOCALE_ID) private localeId: string |
74 | ) { | 74 | ) { |
75 | this.loadConfigLocally() | ||
76 | this.loadServerLocale() | 75 | this.loadServerLocale() |
76 | this.loadConfigLocally() | ||
77 | } | 77 | } |
78 | 78 | ||
79 | loadConfig () { | 79 | loadConfig () { |
@@ -163,14 +163,16 @@ export class ServerService { | |||
163 | } | 163 | } |
164 | 164 | ||
165 | private loadServerLocale () { | 165 | private loadServerLocale () { |
166 | const fileLocale = buildFileLocale(environment.production === true ? this.localeId : 'fr') | 166 | const completeLocale = isOnDevLocale() ? getDevLocale() : getCompleteLocale(this.localeId) |
167 | 167 | ||
168 | // Default locale, nothing to translate | 168 | // Default locale, nothing to translate |
169 | const defaultFileLocale = buildFileLocale(getDefaultLocale()) | 169 | if (isDefaultLocale(completeLocale)) { |
170 | if (fileLocale === defaultFileLocale) return {} | 170 | this.localeObservable = of({}).pipe(share()) |
171 | return | ||
172 | } | ||
171 | 173 | ||
172 | this.localeObservable = this.http | 174 | this.localeObservable = this.http |
173 | .get(ServerService.BASE_LOCALE_URL + fileLocale + '/server.json') | 175 | .get(ServerService.BASE_LOCALE_URL + completeLocale + '/server.json') |
174 | .pipe(share()) | 176 | .pipe(share()) |
175 | } | 177 | } |
176 | 178 | ||
diff --git a/client/src/app/shared/i18n/i18n-utils.ts b/client/src/app/shared/i18n/i18n-utils.ts index c1de51b7b..37180b930 100644 --- a/client/src/app/shared/i18n/i18n-utils.ts +++ b/client/src/app/shared/i18n/i18n-utils.ts | |||
@@ -1,7 +1,19 @@ | |||
1 | import { environment } from '../../../environments/environment' | ||
2 | |||
1 | function peertubeTranslate (str: string, translations: { [ id: string ]: string }) { | 3 | function peertubeTranslate (str: string, translations: { [ id: string ]: string }) { |
2 | return translations[str] ? translations[str] : str | 4 | return translations[str] ? translations[str] : str |
3 | } | 5 | } |
4 | 6 | ||
7 | function isOnDevLocale () { | ||
8 | return environment.production === false && window.location.search === '?lang=fr' | ||
9 | } | ||
10 | |||
11 | function getDevLocale () { | ||
12 | return 'fr' | ||
13 | } | ||
14 | |||
5 | export { | 15 | export { |
16 | getDevLocale, | ||
17 | isOnDevLocale, | ||
6 | peertubeTranslate | 18 | peertubeTranslate |
7 | } | 19 | } |
diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index c607b7d6a..58cb52efc 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts | |||
@@ -46,8 +46,8 @@ export class VideoService { | |||
46 | return this.serverService.localeObservable | 46 | return this.serverService.localeObservable |
47 | .pipe( | 47 | .pipe( |
48 | switchMap(translations => { | 48 | switchMap(translations => { |
49 | return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + uuid) | 49 | return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + uuid) |
50 | .pipe(map(videoHash => ({ videoHash, translations }))) | 50 | .pipe(map(videoHash => ({ videoHash, translations }))) |
51 | }), | 51 | }), |
52 | map(({ videoHash, translations }) => new VideoDetails(videoHash, translations)), | 52 | map(({ videoHash, translations }) => new VideoDetails(videoHash, translations)), |
53 | catchError(res => this.restExtractor.handleError(res)) | 53 | catchError(res => this.restExtractor.handleError(res)) |
diff --git a/client/src/app/videos/+video-watch/video-watch.component.ts b/client/src/app/videos/+video-watch/video-watch.component.ts index d3e16c4cf..4a67d456e 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts | |||
@@ -25,6 +25,7 @@ import { getVideojsOptions, loadLocale, addContextMenu } from '../../../assets/p | |||
25 | import { ServerService } from '@app/core' | 25 | import { ServerService } from '@app/core' |
26 | import { I18n } from '@ngx-translate/i18n-polyfill' | 26 | import { I18n } from '@ngx-translate/i18n-polyfill' |
27 | import { environment } from '../../../environments/environment' | 27 | import { environment } from '../../../environments/environment' |
28 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' | ||
28 | 29 | ||
29 | @Component({ | 30 | @Component({ |
30 | selector: 'my-video-watch', | 31 | selector: 'my-video-watch', |
@@ -377,7 +378,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
377 | }) | 378 | }) |
378 | 379 | ||
379 | if (this.videojsLocaleLoaded === false) { | 380 | if (this.videojsLocaleLoaded === false) { |
380 | await loadLocale(environment.apiUrl, videojs, environment.production === true ? this.localeId : 'fr') | 381 | await loadLocale(environment.apiUrl, videojs, isOnDevLocale() ? getDevLocale() : this.localeId) |
381 | this.videojsLocaleLoaded = true | 382 | this.videojsLocaleLoaded = true |
382 | } | 383 | } |
383 | 384 | ||
diff --git a/client/src/assets/player/peertube-player.ts b/client/src/assets/player/peertube-player.ts index b604097fa..9e37b75d2 100644 --- a/client/src/assets/player/peertube-player.ts +++ b/client/src/assets/player/peertube-player.ts | |||
@@ -12,7 +12,7 @@ import './peertube-videojs-plugin' | |||
12 | import './peertube-load-progress-bar' | 12 | import './peertube-load-progress-bar' |
13 | import { videojsUntyped } from './peertube-videojs-typings' | 13 | import { videojsUntyped } from './peertube-videojs-typings' |
14 | import { buildVideoEmbed, buildVideoLink, copyToClipboard } from './utils' | 14 | import { buildVideoEmbed, buildVideoLink, copyToClipboard } from './utils' |
15 | import { is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n' | 15 | import { getCompleteLocale, is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n' |
16 | 16 | ||
17 | // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) | 17 | // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) |
18 | videojsUntyped.getComponent('PlaybackRateMenuButton').prototype.controlText_ = 'Speed' | 18 | videojsUntyped.getComponent('PlaybackRateMenuButton').prototype.controlText_ = 'Speed' |
@@ -141,11 +141,13 @@ function addContextMenu (player: any, videoEmbedUrl: string) { | |||
141 | } | 141 | } |
142 | 142 | ||
143 | function loadLocale (serverUrl: string, videojs: any, locale: string) { | 143 | function loadLocale (serverUrl: string, videojs: any, locale: string) { |
144 | if (!is18nLocale(locale) || isDefaultLocale(locale)) return undefined | 144 | const completeLocale = getCompleteLocale(locale) |
145 | 145 | ||
146 | return fetch(serverUrl + '/client/locales/' + locale + '/player.json') | 146 | if (!is18nLocale(completeLocale) || isDefaultLocale(completeLocale)) return Promise.resolve(undefined) |
147 | |||
148 | return fetch(serverUrl + '/client/locales/' + completeLocale + '/player.json') | ||
147 | .then(res => res.json()) | 149 | .then(res => res.json()) |
148 | .then(json => videojs.addLanguage(locale, json)) | 150 | .then(json => videojs.addLanguage(completeLocale, json)) |
149 | } | 151 | } |
150 | 152 | ||
151 | export { | 153 | export { |
diff --git a/client/src/main.ts b/client/src/main.ts index 19f45a3e3..061be17de 100644 --- a/client/src/main.ts +++ b/client/src/main.ts | |||
@@ -5,14 +5,17 @@ import { AppModule } from './app/app.module' | |||
5 | import { environment } from './environments/environment' | 5 | import { environment } from './environments/environment' |
6 | 6 | ||
7 | import { hmrBootstrap } from './hmr' | 7 | import { hmrBootstrap } from './hmr' |
8 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' | ||
8 | 9 | ||
9 | let providers = [] | 10 | let providers = [] |
10 | if (environment.production) { | 11 | if (environment.production) { |
11 | enableProdMode() | 12 | enableProdMode() |
12 | } | 13 | } |
13 | 14 | ||
14 | if (environment.production === false && window.location.search === '?lang=fr') { | 15 | // Template translation, should be in the bootstrap step |
15 | const translations = require(`raw-loader!./locale/target/angular_fr.xml`) | 16 | if (isOnDevLocale()) { |
17 | const locale = getDevLocale() | ||
18 | const translations = require(`raw-loader!./locale/target/angular_${locale}.xml`) | ||
16 | 19 | ||
17 | providers = [ | 20 | providers = [ |
18 | { provide: TRANSLATIONS, useValue: translations }, | 21 | { provide: TRANSLATIONS, useValue: translations }, |