+function addContextMenu (player: any, videoEmbedUrl: string) {
+ player.contextmenuUI({
+ content: [
+ {
+ label: player.localize('Copy the video URL'),
+ listener: function () {
+ copyToClipboard(buildVideoLink())
+ }
+ },
+ {
+ label: player.localize('Copy the video URL at the current time'),
+ listener: function () {
+ const player = this
+ copyToClipboard(buildVideoLink(player.currentTime()))
+ }
+ },
+ {
+ label: player.localize('Copy embed code'),
+ listener: () => {
+ copyToClipboard(buildVideoEmbed(videoEmbedUrl))
+ }
+ },
+ {
+ label: player.localize('Copy magnet URI'),
+ listener: function () {
+ const player = this
+ copyToClipboard(player.peertube().getCurrentVideoFile().magnetUri)
+ }
+ }
+ ]
+ })
+}
+
+function loadLocaleInVideoJS (serverUrl: string, videojs: any, locale: string) {
+ const path = getLocalePath(serverUrl, locale)
+ // It is the default locale, nothing to translate
+ if (!path) return Promise.resolve(undefined)
+
+ let p: Promise<any>
+
+ if (loadLocaleInVideoJS.cache[path]) {
+ p = Promise.resolve(loadLocaleInVideoJS.cache[path])
+ } else {
+ p = fetch(path + '/player.json')
+ .then(res => res.json())
+ .then(json => {
+ loadLocaleInVideoJS.cache[path] = json
+ return json
+ })
+ }
+
+ const completeLocale = getCompleteLocale(locale)
+ return p.then(json => videojs.addLanguage(getShortLocale(completeLocale), json))
+}
+namespace loadLocaleInVideoJS {
+ export const cache: { [ path: string ]: any } = {}
+}
+
+function getServerTranslations (serverUrl: string, locale: string) {
+ const path = getLocalePath(serverUrl, locale)
+ // It is the default locale, nothing to translate
+ if (!path) return Promise.resolve(undefined)
+
+ return fetch(path + '/server.json')
+ .then(res => res.json())
+}
+
+// ############################################################################
+
+export {
+ getServerTranslations,
+ loadLocaleInVideoJS,
+ getVideojsOptions,
+ addContextMenu
+}
+
+// ############################################################################
+
+function getLocalePath (serverUrl: string, locale: string) {
+ const completeLocale = getCompleteLocale(locale)
+
+ if (!is18nLocale(completeLocale) || isDefaultLocale(completeLocale)) return undefined
+
+ return serverUrl + '/client/locales/' + completeLocale
+}