]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/i18n/create-custom-files.ts
Fix context menu when watching a playlist
[github/Chocobozzz/PeerTube.git] / scripts / i18n / create-custom-files.ts
1 import { writeJSON } from 'fs-extra'
2 import { values } from 'lodash'
3 import { join } from 'path'
4 import { registerTSPaths } from '../../server/helpers/register-ts-paths'
5 import {
6 buildLanguages,
7 VIDEO_CATEGORIES,
8 VIDEO_IMPORT_STATES,
9 VIDEO_LICENCES,
10 VIDEO_PLAYLIST_PRIVACIES,
11 VIDEO_PLAYLIST_TYPES,
12 VIDEO_PRIVACIES,
13 VIDEO_STATES
14 } from '../../server/initializers/constants'
15 import { I18N_LOCALES } from '../../shared/core-utils/i18n'
16
17 registerTSPaths()
18
19 const videojs = require(join(__dirname, '../../../client/src/locale/videojs.en-US.json'))
20 const playerKeys = {
21 'Quality': 'Quality',
22 'Auto': 'Auto',
23 'Speed': 'Speed',
24 'Subtitles/CC': 'Subtitles/CC',
25 'peers': 'peers',
26 'peer': 'peer',
27 'Go to the video page': 'Go to the video page',
28 'Settings': 'Settings',
29 'Watching this video may reveal your IP address to others.': 'Watching this video may reveal your IP address to others.',
30 'Copy the video URL': 'Copy the video URL',
31 'Copy the video URL at the current time': 'Copy the video URL at the current time',
32 'Copy video embed code': 'Copy video embed code',
33 'Copy magnet URI': 'Copy magnet URI',
34 'Total downloaded: ': 'Total downloaded: ',
35 'Total uploaded: ': 'Total uploaded: ',
36 'From servers: ': 'From servers: ',
37 'From peers: ': 'From peers: ',
38 'Normal mode': 'Normal mode',
39 'Play in loop': 'Play in loop',
40 'Theater mode': 'Theater mode',
41 'Copy the playlist URL': 'Copy the playlist URL',
42 'Copy the playlist URL at current video position': 'Copy the playlist URL at current video position',
43 'Copy the playlist embed code': 'Copy the playlist embed code'
44 }
45 Object.assign(playerKeys, videojs)
46
47 // Server keys
48 const serverKeys: any = {}
49 values(VIDEO_CATEGORIES)
50 .concat(values(VIDEO_LICENCES))
51 .concat(values(VIDEO_PRIVACIES))
52 .concat(values(VIDEO_STATES))
53 .concat(values(VIDEO_IMPORT_STATES))
54 .concat(values(VIDEO_PLAYLIST_PRIVACIES))
55 .concat(values(VIDEO_PLAYLIST_TYPES))
56 .concat([
57 'This video does not exist.',
58 'We cannot fetch the video. Please try again later.',
59 'Sorry',
60 'This video is not available because the remote instance is not responding.',
61 'This playlist does not exist',
62 'We cannot fetch the playlist. Please try again later.',
63 'Playlist: {1}',
64 'By {1}',
65 'Unavailable video'
66 ])
67 .forEach(v => { serverKeys[v] = v })
68
69 // More keys
70 Object.assign(serverKeys, {
71 Misc: 'Misc',
72 Unknown: 'Unknown'
73 })
74
75 // ISO 639 keys
76 const languageKeys: any = {}
77 const languages = buildLanguages()
78 Object.keys(languages).forEach(k => { languageKeys[languages[k]] = languages[k] })
79
80 Object.assign(serverKeys, languageKeys)
81
82 writeAll().catch(err => {
83 console.error(err)
84 process.exit(-1)
85 })
86
87 async function writeAll () {
88 const localePath = join(__dirname, '../../../client/src/locale')
89
90 await writeJSON(join(localePath, 'player.en-US.json'), playerKeys, { spaces: 4 })
91 await writeJSON(join(localePath, 'server.en-US.json'), serverKeys, { spaces: 4 })
92
93 for (const key of Object.keys(I18N_LOCALES)) {
94 const playerJsonPath = join(localePath, `player.${key}.json`)
95 const translatedPlayer = require(playerJsonPath)
96
97 const newTranslatedPlayer = Object.assign({}, playerKeys, translatedPlayer)
98 await writeJSON(playerJsonPath, newTranslatedPlayer, { spaces: 4 })
99
100 const serverJsonPath = join(localePath, `server.${key}.json`)
101 const translatedServer = require(serverJsonPath)
102
103 const newTranslatedServer = Object.assign({}, serverKeys, translatedServer)
104 await writeJSON(serverJsonPath, newTranslatedServer, { spaces: 4 })
105 }
106 }