aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/app.module.ts18
-rw-r--r--client/src/app/core/server/server.service.ts20
-rw-r--r--client/src/app/shared/i18n/i18n-utils.ts12
-rw-r--r--client/src/app/shared/video/video.service.ts4
-rw-r--r--client/src/app/videos/+video-watch/video-watch.component.ts3
5 files changed, 36 insertions, 21 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'
16import { SharedModule } from './shared' 16import { SharedModule } from './shared'
17import { SignupModule } from './signup' 17import { SignupModule } from './signup'
18import { VideosModule } from './videos' 18import { VideosModule } from './videos'
19import { buildFileLocale, getDefaultLocale } from '../../../shared/models/i18n' 19import { buildFileLocale, getCompleteLocale, getDefaultLocale, isDefaultLocale } from '../../../shared/models/i18n'
20import { environment } from '../environments/environment' 20import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils'
21 21
22export function metaFactory (serverService: ServerService): MetaLoader { 22export 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'
2import { HttpClient } from '@angular/common/http' 2import { HttpClient } from '@angular/common/http'
3import { Inject, Injectable, LOCALE_ID } from '@angular/core' 3import { Inject, Injectable, LOCALE_ID } from '@angular/core'
4import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' 4import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
5import { Observable, ReplaySubject } from 'rxjs' 5import { Observable, ReplaySubject, of } from 'rxjs'
6import { ServerConfig } from '../../../../../shared' 6import { getCompleteLocale, ServerConfig } from '../../../../../shared'
7import { About } from '../../../../../shared/models/server/about.model' 7import { About } from '../../../../../shared/models/server/about.model'
8import { environment } from '../../../environments/environment' 8import { environment } from '../../../environments/environment'
9import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos' 9import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos'
10import { buildFileLocale, getDefaultLocale } from '../../../../../shared/models/i18n' 10import { isDefaultLocale } from '../../../../../shared/models/i18n'
11import { peertubeTranslate } from '@app/shared/i18n/i18n-utils' 11import { getDevLocale, isOnDevLocale, peertubeTranslate } from '@app/shared/i18n/i18n-utils'
12 12
13@Injectable() 13@Injectable()
14export class ServerService { 14export 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 @@
1import { environment } from '../../../environments/environment'
2
1function peertubeTranslate (str: string, translations: { [ id: string ]: string }) { 3function 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
7function isOnDevLocale () {
8 return environment.production === false && window.location.search === '?lang=fr'
9}
10
11function getDevLocale () {
12 return 'fr'
13}
14
5export { 15export {
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
25import { ServerService } from '@app/core' 25import { ServerService } from '@app/core'
26import { I18n } from '@ngx-translate/i18n-polyfill' 26import { I18n } from '@ngx-translate/i18n-polyfill'
27import { environment } from '../../../environments/environment' 27import { environment } from '../../../environments/environment'
28import { 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