diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-06 14:23:40 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-06 16:48:40 +0200 |
commit | e945b184a0f29b47c33bbd05578f3493ca9c8e6c (patch) | |
tree | 46c821006d170e6e28658d978e313761adfaf55a /client/src/assets/player/peertube-player.ts | |
parent | 550a562ceca45ea78d6f7054024c8d3a6b89c30c (diff) | |
download | PeerTube-e945b184a0f29b47c33bbd05578f3493ca9c8e6c.tar.gz PeerTube-e945b184a0f29b47c33bbd05578f3493ca9c8e6c.tar.zst PeerTube-e945b184a0f29b47c33bbd05578f3493ca9c8e6c.zip |
Localize player
Diffstat (limited to 'client/src/assets/player/peertube-player.ts')
-rw-r--r-- | client/src/assets/player/peertube-player.ts | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/client/src/assets/player/peertube-player.ts b/client/src/assets/player/peertube-player.ts index d204b9703..b604097fa 100644 --- a/client/src/assets/player/peertube-player.ts +++ b/client/src/assets/player/peertube-player.ts | |||
@@ -12,6 +12,7 @@ import './peertube-videojs-plugin' | |||
12 | import './peertube-load-progress-bar' | 12 | import './peertube-load-progress-bar' |
13 | import { videojsUntyped } from './peertube-videojs-typings' | 13 | import { videojsUntyped } from './peertube-videojs-typings' |
14 | import { buildVideoEmbed, buildVideoLink, copyToClipboard } from './utils' | 14 | import { buildVideoEmbed, buildVideoLink, copyToClipboard } from './utils' |
15 | import { is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n' | ||
15 | 16 | ||
16 | // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) | 17 | // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) |
17 | videojsUntyped.getComponent('PlaybackRateMenuButton').prototype.controlText_ = 'Speed' | 18 | videojsUntyped.getComponent('PlaybackRateMenuButton').prototype.controlText_ = 'Speed' |
@@ -20,7 +21,6 @@ function getVideojsOptions (options: { | |||
20 | autoplay: boolean, | 21 | autoplay: boolean, |
21 | playerElement: HTMLVideoElement, | 22 | playerElement: HTMLVideoElement, |
22 | videoViewUrl: string, | 23 | videoViewUrl: string, |
23 | videoEmbedUrl: string, | ||
24 | videoDuration: number, | 24 | videoDuration: number, |
25 | videoFiles: VideoFile[], | 25 | videoFiles: VideoFile[], |
26 | enableHotkeys: boolean, | 26 | enableHotkeys: boolean, |
@@ -43,29 +43,6 @@ function getVideojsOptions (options: { | |||
43 | videoViewUrl: options.videoViewUrl, | 43 | videoViewUrl: options.videoViewUrl, |
44 | videoDuration: options.videoDuration, | 44 | videoDuration: options.videoDuration, |
45 | startTime: options.startTime | 45 | startTime: options.startTime |
46 | }, | ||
47 | contextmenuUI: { | ||
48 | content: [ | ||
49 | { | ||
50 | label: 'Copy the video URL', | ||
51 | listener: function () { | ||
52 | copyToClipboard(buildVideoLink()) | ||
53 | } | ||
54 | }, | ||
55 | { | ||
56 | label: 'Copy the video URL at the current time', | ||
57 | listener: function () { | ||
58 | const player = this | ||
59 | copyToClipboard(buildVideoLink(player.currentTime())) | ||
60 | } | ||
61 | }, | ||
62 | { | ||
63 | label: 'Copy embed code', | ||
64 | listener: () => { | ||
65 | copyToClipboard(buildVideoEmbed(options.videoEmbedUrl)) | ||
66 | } | ||
67 | } | ||
68 | ] | ||
69 | } | 46 | } |
70 | }, | 47 | }, |
71 | controlBar: { | 48 | controlBar: { |
@@ -135,4 +112,44 @@ function getControlBarChildren (options: { | |||
135 | return children | 112 | return children |
136 | } | 113 | } |
137 | 114 | ||
138 | export { getVideojsOptions } | 115 | function addContextMenu (player: any, videoEmbedUrl: string) { |
116 | console.log(videoEmbedUrl) | ||
117 | |||
118 | player.contextmenuUI({ | ||
119 | content: [ | ||
120 | { | ||
121 | label: player.localize('Copy the video URL'), | ||
122 | listener: function () { | ||
123 | copyToClipboard(buildVideoLink()) | ||
124 | } | ||
125 | }, | ||
126 | { | ||
127 | label: player.localize('Copy the video URL at the current time'), | ||
128 | listener: function () { | ||
129 | const player = this | ||
130 | copyToClipboard(buildVideoLink(player.currentTime())) | ||
131 | } | ||
132 | }, | ||
133 | { | ||
134 | label: player.localize('Copy embed code'), | ||
135 | listener: () => { | ||
136 | copyToClipboard(buildVideoEmbed(videoEmbedUrl)) | ||
137 | } | ||
138 | } | ||
139 | ] | ||
140 | }) | ||
141 | } | ||
142 | |||
143 | function loadLocale (serverUrl: string, videojs: any, locale: string) { | ||
144 | if (!is18nLocale(locale) || isDefaultLocale(locale)) return undefined | ||
145 | |||
146 | return fetch(serverUrl + '/client/locales/' + locale + '/player.json') | ||
147 | .then(res => res.json()) | ||
148 | .then(json => videojs.addLanguage(locale, json)) | ||
149 | } | ||
150 | |||
151 | export { | ||
152 | loadLocale, | ||
153 | getVideojsOptions, | ||
154 | addContextMenu | ||
155 | } | ||