aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-06 16:46:42 +0200
committerChocobozzz <me@florianbigard.com>2018-06-06 16:48:41 +0200
commit7ce44a74a3b052190cfacd4bd5ee6b92cfc620ac (patch)
tree6f178426c165f9136eb08354efa4a06c24725f87 /client/src/app/shared/video
parentf07d6385b4b46c3254898292a8a53ed415b8d49b (diff)
downloadPeerTube-7ce44a74a3b052190cfacd4bd5ee6b92cfc620ac.tar.gz
PeerTube-7ce44a74a3b052190cfacd4bd5ee6b92cfc620ac.tar.zst
PeerTube-7ce44a74a3b052190cfacd4bd5ee6b92cfc620ac.zip
Add server localization
Diffstat (limited to 'client/src/app/shared/video')
-rw-r--r--client/src/app/shared/video/video-details.model.ts4
-rw-r--r--client/src/app/shared/video/video.model.ts8
-rw-r--r--client/src/app/shared/video/video.service.ts56
3 files changed, 43 insertions, 25 deletions
diff --git a/client/src/app/shared/video/video-details.model.ts b/client/src/app/shared/video/video-details.model.ts
index 5fc55fca6..19c350ab3 100644
--- a/client/src/app/shared/video/video-details.model.ts
+++ b/client/src/app/shared/video/video-details.model.ts
@@ -15,8 +15,8 @@ export class VideoDetails extends Video implements VideoDetailsServerModel {
15 likesPercent: number 15 likesPercent: number
16 dislikesPercent: number 16 dislikesPercent: number
17 17
18 constructor (hash: VideoDetailsServerModel) { 18 constructor (hash: VideoDetailsServerModel, translations = {}) {
19 super(hash) 19 super(hash, translations)
20 20
21 this.descriptionPath = hash.descriptionPath 21 this.descriptionPath = hash.descriptionPath
22 this.files = hash.files 22 this.files = hash.files
diff --git a/client/src/app/shared/video/video.model.ts b/client/src/app/shared/video/video.model.ts
index 48d562f9c..d37dc2c3e 100644
--- a/client/src/app/shared/video/video.model.ts
+++ b/client/src/app/shared/video/video.model.ts
@@ -5,6 +5,7 @@ import { VideoConstant } from '../../../../../shared/models/videos/video.model'
5import { getAbsoluteAPIUrl } from '../misc/utils' 5import { getAbsoluteAPIUrl } from '../misc/utils'
6import { ServerConfig } from '../../../../../shared/models' 6import { ServerConfig } from '../../../../../shared/models'
7import { Actor } from '@app/shared/actor/actor.model' 7import { Actor } from '@app/shared/actor/actor.model'
8import { peertubeTranslate } from '@app/shared/i18n/i18n-utils'
8 9
9export class Video implements VideoServerModel { 10export class Video implements VideoServerModel {
10 by: string 11 by: string
@@ -68,7 +69,7 @@ export class Video implements VideoServerModel {
68 minutes.toString() + ':' + secondsPadding + seconds.toString() 69 minutes.toString() + ':' + secondsPadding + seconds.toString()
69 } 70 }
70 71
71 constructor (hash: VideoServerModel) { 72 constructor (hash: VideoServerModel, translations = {}) {
72 const absoluteAPIUrl = getAbsoluteAPIUrl() 73 const absoluteAPIUrl = getAbsoluteAPIUrl()
73 74
74 this.createdAt = new Date(hash.createdAt.toString()) 75 this.createdAt = new Date(hash.createdAt.toString())
@@ -98,6 +99,11 @@ export class Video implements VideoServerModel {
98 99
99 this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host) 100 this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
100 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) 101 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
102
103 this.category.label = peertubeTranslate(this.category.label, translations)
104 this.licence.label = peertubeTranslate(this.licence.label, translations)
105 this.language.label = peertubeTranslate(this.language.label, translations)
106 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
101 } 107 }
102 108
103 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) { 109 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts
index d1e32faeb..c607b7d6a 100644
--- a/client/src/app/shared/video/video.service.ts
+++ b/client/src/app/shared/video/video.service.ts
@@ -1,4 +1,4 @@
1import { catchError, map } from 'rxjs/operators' 1import { catchError, map, switchMap } from 'rxjs/operators'
2import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' 2import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http'
3import { Injectable } from '@angular/core' 3import { Injectable } from '@angular/core'
4import { Observable } from 'rxjs' 4import { Observable } from 'rxjs'
@@ -24,6 +24,7 @@ import { Account } from '@app/shared/account/account.model'
24import { AccountService } from '@app/shared/account/account.service' 24import { AccountService } from '@app/shared/account/account.service'
25import { VideoChannel } from '../../../../../shared/models/videos' 25import { VideoChannel } from '../../../../../shared/models/videos'
26import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' 26import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
27import { ServerService } from '@app/core'
27 28
28@Injectable() 29@Injectable()
29export class VideoService { 30export class VideoService {
@@ -33,7 +34,8 @@ export class VideoService {
33 constructor ( 34 constructor (
34 private authHttp: HttpClient, 35 private authHttp: HttpClient,
35 private restExtractor: RestExtractor, 36 private restExtractor: RestExtractor,
36 private restService: RestService 37 private restService: RestService,
38 private serverService: ServerService
37 ) {} 39 ) {}
38 40
39 getVideoViewUrl (uuid: string) { 41 getVideoViewUrl (uuid: string) {
@@ -41,9 +43,13 @@ export class VideoService {
41 } 43 }
42 44
43 getVideo (uuid: string): Observable<VideoDetails> { 45 getVideo (uuid: string): Observable<VideoDetails> {
44 return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + uuid) 46 return this.serverService.localeObservable
45 .pipe( 47 .pipe(
46 map(videoHash => new VideoDetails(videoHash)), 48 switchMap(translations => {
49 return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + uuid)
50 .pipe(map(videoHash => ({ videoHash, translations })))
51 }),
52 map(({ videoHash, translations }) => new VideoDetails(videoHash, translations)),
47 catchError(res => this.restExtractor.handleError(res)) 53 catchError(res => this.restExtractor.handleError(res))
48 ) 54 )
49 } 55 }
@@ -102,9 +108,10 @@ export class VideoService {
102 let params = new HttpParams() 108 let params = new HttpParams()
103 params = this.restService.addRestGetParams(params, pagination, sort) 109 params = this.restService.addRestGetParams(params, pagination, sort)
104 110
105 return this.authHttp.get(UserService.BASE_USERS_URL + '/me/videos', { params }) 111 return this.authHttp
112 .get<ResultList<Video>>(UserService.BASE_USERS_URL + '/me/videos', { params })
106 .pipe( 113 .pipe(
107 map(this.extractVideos), 114 switchMap(res => this.extractVideos(res)),
108 catchError(res => this.restExtractor.handleError(res)) 115 catchError(res => this.restExtractor.handleError(res))
109 ) 116 )
110 } 117 }
@@ -120,9 +127,9 @@ export class VideoService {
120 params = this.restService.addRestGetParams(params, pagination, sort) 127 params = this.restService.addRestGetParams(params, pagination, sort)
121 128
122 return this.authHttp 129 return this.authHttp
123 .get(AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/videos', { params }) 130 .get<ResultList<Video>>(AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/videos', { params })
124 .pipe( 131 .pipe(
125 map(this.extractVideos), 132 switchMap(res => this.extractVideos(res)),
126 catchError(res => this.restExtractor.handleError(res)) 133 catchError(res => this.restExtractor.handleError(res))
127 ) 134 )
128 } 135 }
@@ -138,9 +145,9 @@ export class VideoService {
138 params = this.restService.addRestGetParams(params, pagination, sort) 145 params = this.restService.addRestGetParams(params, pagination, sort)
139 146
140 return this.authHttp 147 return this.authHttp
141 .get(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.uuid + '/videos', { params }) 148 .get<ResultList<Video>>(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.uuid + '/videos', { params })
142 .pipe( 149 .pipe(
143 map(this.extractVideos), 150 switchMap(res => this.extractVideos(res)),
144 catchError(res => this.restExtractor.handleError(res)) 151 catchError(res => this.restExtractor.handleError(res))
145 ) 152 )
146 } 153 }
@@ -160,9 +167,9 @@ export class VideoService {
160 } 167 }
161 168
162 return this.authHttp 169 return this.authHttp
163 .get(VideoService.BASE_VIDEO_URL, { params }) 170 .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
164 .pipe( 171 .pipe(
165 map(this.extractVideos), 172 switchMap(res => this.extractVideos(res)),
166 catchError(res => this.restExtractor.handleError(res)) 173 catchError(res => this.restExtractor.handleError(res))
167 ) 174 )
168 } 175 }
@@ -230,7 +237,7 @@ export class VideoService {
230 return this.authHttp 237 return this.authHttp
231 .get<ResultList<VideoServerModel>>(url, { params }) 238 .get<ResultList<VideoServerModel>>(url, { params })
232 .pipe( 239 .pipe(
233 map(this.extractVideos), 240 switchMap(res => this.extractVideos(res)),
234 catchError(res => this.restExtractor.handleError(res)) 241 catchError(res => this.restExtractor.handleError(res))
235 ) 242 )
236 } 243 }
@@ -287,14 +294,19 @@ export class VideoService {
287 } 294 }
288 295
289 private extractVideos (result: ResultList<VideoServerModel>) { 296 private extractVideos (result: ResultList<VideoServerModel>) {
290 const videosJson = result.data 297 return this.serverService.localeObservable
291 const totalVideos = result.total 298 .pipe(
292 const videos = [] 299 map(translations => {
293 300 const videosJson = result.data
294 for (const videoJson of videosJson) { 301 const totalVideos = result.total
295 videos.push(new Video(videoJson)) 302 const videos: Video[] = []
296 } 303
297 304 for (const videoJson of videosJson) {
298 return { videos, totalVideos } 305 videos.push(new Video(videoJson, translations))
306 }
307
308 return { videos, totalVideos }
309 })
310 )
299 } 311 }
300} 312}