aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-16 10:48:35 +0200
committerChocobozzz <me@florianbigard.com>2018-08-16 10:48:35 +0200
commit3dfa84940273619ae00f11a5f419a5e4876b2f53 (patch)
treebd31beeb985a9696af90e15ff6b767c4a0da03d9 /client/src/assets
parent4f1f6f038389ce9cdf0c77dfccdc63efc6948101 (diff)
downloadPeerTube-3dfa84940273619ae00f11a5f419a5e4876b2f53.tar.gz
PeerTube-3dfa84940273619ae00f11a5f419a5e4876b2f53.tar.zst
PeerTube-3dfa84940273619ae00f11a5f419a5e4876b2f53.zip
Translate subtitle langs in player
Diffstat (limited to 'client/src/assets')
-rw-r--r--client/src/assets/player/peertube-player.ts34
1 files changed, 29 insertions, 5 deletions
diff --git a/client/src/assets/player/peertube-player.ts b/client/src/assets/player/peertube-player.ts
index 1fca6a7d2..1b1ec7a68 100644
--- a/client/src/assets/player/peertube-player.ts
+++ b/client/src/assets/player/peertube-player.ts
@@ -174,18 +174,42 @@ function addContextMenu (player: any, videoEmbedUrl: string) {
174 }) 174 })
175} 175}
176 176
177function loadLocale (serverUrl: string, videojs: any, locale: string) { 177function loadLocaleInVideoJS (serverUrl: string, videojs: any, locale: string) {
178 const completeLocale = getCompleteLocale(locale) 178 const path = getLocalePath(serverUrl, locale)
179 // It is the default locale, nothing to translate
180 if (!path) return Promise.resolve(undefined)
179 181
180 if (!is18nLocale(completeLocale) || isDefaultLocale(completeLocale)) return Promise.resolve(undefined) 182 const completeLocale = getCompleteLocale(locale)
181 183
182 return fetch(serverUrl + '/client/locales/' + completeLocale + '/player.json') 184 return fetch(path + '/player.json')
183 .then(res => res.json()) 185 .then(res => res.json())
184 .then(json => videojs.addLanguage(getShortLocale(completeLocale), json)) 186 .then(json => videojs.addLanguage(getShortLocale(completeLocale), json))
185} 187}
186 188
189function getServerTranslations (serverUrl: string, locale: string) {
190 const path = getLocalePath(serverUrl, locale)
191 // It is the default locale, nothing to translate
192 if (!path) return Promise.resolve(undefined)
193
194 return fetch(path + '/server.json')
195 .then(res => res.json())
196}
197
198// ############################################################################
199
187export { 200export {
188 loadLocale, 201 getServerTranslations,
202 loadLocaleInVideoJS,
189 getVideojsOptions, 203 getVideojsOptions,
190 addContextMenu 204 addContextMenu
191} 205}
206
207// ############################################################################
208
209function getLocalePath (serverUrl: string, locale: string) {
210 const completeLocale = getCompleteLocale(locale)
211
212 if (!is18nLocale(completeLocale) || isDefaultLocale(completeLocale)) return undefined
213
214 return serverUrl + '/client/locales/' + completeLocale
215}