diff options
Diffstat (limited to 'client/src/assets/player/peertube-player.ts')
-rw-r--r-- | client/src/assets/player/peertube-player.ts | 34 |
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 | ||
177 | function loadLocale (serverUrl: string, videojs: any, locale: string) { | 177 | function 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 | ||
189 | function 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 | |||
187 | export { | 200 | export { |
188 | loadLocale, | 201 | getServerTranslations, |
202 | loadLocaleInVideoJS, | ||
189 | getVideojsOptions, | 203 | getVideojsOptions, |
190 | addContextMenu | 204 | addContextMenu |
191 | } | 205 | } |
206 | |||
207 | // ############################################################################ | ||
208 | |||
209 | function 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 | } | ||