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