From 3dfa84940273619ae00f11a5f419a5e4876b2f53 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Aug 2018 10:48:35 +0200 Subject: Translate subtitle langs in player --- .../shared/video-caption/video-caption.service.ts | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'client/src/app/shared/video-caption') 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 @@ -import { catchError, map } from 'rxjs/operators' +import { catchError, map, switchMap } from 'rxjs/operators' import { HttpClient } from '@angular/common/http' import { Injectable } from '@angular/core' import { forkJoin, Observable, of } from 'rxjs' -import { ResultList } from '../../../../../shared' +import { peertubeTranslate, ResultList } from '../../../../../shared' import { RestExtractor, RestService } from '../rest' import { VideoService } from '@app/shared/video/video.service' import { objectToFormData, sortBy } from '@app/shared/misc/utils' import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model' import { VideoCaption } from '../../../../../shared/models/videos/caption/video-caption.model' +import { ServerService } from '@app/core' @Injectable() export class VideoCaptionService { constructor ( private authHttp: HttpClient, + private serverService: ServerService, private restService: RestService, private restExtractor: RestExtractor ) {} listCaptions (videoId: number | string): Observable> { return this.authHttp.get>(VideoService.BASE_VIDEO_URL + videoId + '/captions') - .pipe(map(res => { - sortBy(res.data, 'language', 'label') + .pipe( + switchMap(captionsResult => { + return this.serverService.localeObservable + .pipe(map(translations => ({ captionsResult, translations }))) + }), + map(({ captionsResult, translations }) => { + for (const c of captionsResult.data) { + c.language.label = peertubeTranslate(c.language.label, translations) + } + + return captionsResult + }), + map(captionsResult => { + sortBy(captionsResult.data, 'language', 'label') - return res - })) + return captionsResult + }) + ) .pipe(catchError(res => this.restExtractor.handleError(res))) } -- cgit v1.2.3