diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-16 10:48:35 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-16 10:48:35 +0200 |
commit | 3dfa84940273619ae00f11a5f419a5e4876b2f53 (patch) | |
tree | bd31beeb985a9696af90e15ff6b767c4a0da03d9 /client/src/app/shared/video-caption | |
parent | 4f1f6f038389ce9cdf0c77dfccdc63efc6948101 (diff) | |
download | PeerTube-3dfa84940273619ae00f11a5f419a5e4876b2f53.tar.gz PeerTube-3dfa84940273619ae00f11a5f419a5e4876b2f53.tar.zst PeerTube-3dfa84940273619ae00f11a5f419a5e4876b2f53.zip |
Translate subtitle langs in player
Diffstat (limited to 'client/src/app/shared/video-caption')
-rw-r--r-- | client/src/app/shared/video-caption/video-caption.service.ts | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/client/src/app/shared/video-caption/video-caption.service.ts b/client/src/app/shared/video-caption/video-caption.service.ts index 9c29bc052..994882451 100644 --- a/client/src/app/shared/video-caption/video-caption.service.ts +++ b/client/src/app/shared/video-caption/video-caption.service.ts | |||
@@ -1,29 +1,44 @@ | |||
1 | import { catchError, map } from 'rxjs/operators' | 1 | import { catchError, map, switchMap } from 'rxjs/operators' |
2 | import { HttpClient } from '@angular/common/http' | 2 | import { HttpClient } from '@angular/common/http' |
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { forkJoin, Observable, of } from 'rxjs' | 4 | import { forkJoin, Observable, of } from 'rxjs' |
5 | import { ResultList } from '../../../../../shared' | 5 | import { peertubeTranslate, ResultList } from '../../../../../shared' |
6 | import { RestExtractor, RestService } from '../rest' | 6 | import { RestExtractor, RestService } from '../rest' |
7 | import { VideoService } from '@app/shared/video/video.service' | 7 | import { VideoService } from '@app/shared/video/video.service' |
8 | import { objectToFormData, sortBy } from '@app/shared/misc/utils' | 8 | import { objectToFormData, sortBy } from '@app/shared/misc/utils' |
9 | import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' | 9 | import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' |
10 | import { VideoCaption } from '../../../../../shared/models/videos/caption/video-caption.model' | 10 | import { VideoCaption } from '../../../../../shared/models/videos/caption/video-caption.model' |
11 | import { ServerService } from '@app/core' | ||
11 | 12 | ||
12 | @Injectable() | 13 | @Injectable() |
13 | export class VideoCaptionService { | 14 | export class VideoCaptionService { |
14 | constructor ( | 15 | constructor ( |
15 | private authHttp: HttpClient, | 16 | private authHttp: HttpClient, |
17 | private serverService: ServerService, | ||
16 | private restService: RestService, | 18 | private restService: RestService, |
17 | private restExtractor: RestExtractor | 19 | private restExtractor: RestExtractor |
18 | ) {} | 20 | ) {} |
19 | 21 | ||
20 | listCaptions (videoId: number | string): Observable<ResultList<VideoCaption>> { | 22 | listCaptions (videoId: number | string): Observable<ResultList<VideoCaption>> { |
21 | return this.authHttp.get<ResultList<VideoCaption>>(VideoService.BASE_VIDEO_URL + videoId + '/captions') | 23 | return this.authHttp.get<ResultList<VideoCaption>>(VideoService.BASE_VIDEO_URL + videoId + '/captions') |
22 | .pipe(map(res => { | 24 | .pipe( |
23 | sortBy(res.data, 'language', 'label') | 25 | switchMap(captionsResult => { |
26 | return this.serverService.localeObservable | ||
27 | .pipe(map(translations => ({ captionsResult, translations }))) | ||
28 | }), | ||
29 | map(({ captionsResult, translations }) => { | ||
30 | for (const c of captionsResult.data) { | ||
31 | c.language.label = peertubeTranslate(c.language.label, translations) | ||
32 | } | ||
33 | |||
34 | return captionsResult | ||
35 | }), | ||
36 | map(captionsResult => { | ||
37 | sortBy(captionsResult.data, 'language', 'label') | ||
24 | 38 | ||
25 | return res | 39 | return captionsResult |
26 | })) | 40 | }) |
41 | ) | ||
27 | .pipe(catchError(res => this.restExtractor.handleError(res))) | 42 | .pipe(catchError(res => this.restExtractor.handleError(res))) |
28 | } | 43 | } |
29 | 44 | ||