]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/i18n/create-custom-files.ts
72136614c43da47e19f3008f69d5e6a368f2623d
[github/Chocobozzz/PeerTube.git] / scripts / i18n / create-custom-files.ts
1 import { writeJSON } from 'fs-extra'
2 import { join } from 'path'
3 import { root, USER_ROLE_LABELS } from '@shared/core-utils'
4 import {
5 ABUSE_STATES,
6 buildLanguages,
7 RUNNER_JOB_STATES,
8 USER_REGISTRATION_STATES,
9 VIDEO_CATEGORIES,
10 VIDEO_CHANNEL_SYNC_STATE,
11 VIDEO_IMPORT_STATES,
12 VIDEO_LICENCES,
13 VIDEO_PLAYLIST_PRIVACIES,
14 VIDEO_PLAYLIST_TYPES,
15 VIDEO_PRIVACIES,
16 VIDEO_STATES
17 } from '../../server/initializers/constants'
18 import { I18N_LOCALES } from '../../shared/core-utils/i18n'
19
20 const videojs = require(join(root(), 'client', 'src', 'locale', 'videojs.en-US.json'))
21 const playerKeys = {
22 'Quality': 'Quality',
23 'Auto': 'Auto',
24 'Speed': 'Speed',
25 'Subtitles/CC': 'Subtitles/CC',
26 'peers': 'peers',
27 'peer': 'peer',
28 'Go to the video page': 'Go to the video page',
29 'Settings': 'Settings',
30 'Watching this video may reveal your IP address to others.': 'Watching this video may reveal your IP address to others.',
31 'Copy the video URL': 'Copy the video URL',
32 'Copy the video URL at the current time': 'Copy the video URL at the current time',
33 'Copy embed code': 'Copy embed code',
34 'Copy magnet URI': 'Copy magnet URI',
35 'Total downloaded: ': 'Total downloaded: ',
36 'Total uploaded: ': 'Total uploaded: ',
37 'From servers: ': 'From servers: ',
38 'From peers: ': 'From peers: ',
39 'Normal mode': 'Normal mode',
40 'Stats for nerds': 'Stats for nerds',
41 'Theater mode': 'Theater mode',
42 'Video UUID': 'Video UUID',
43 'Viewport / Frames': 'Viewport / Frames',
44 'Resolution': 'Resolution',
45 'Volume': 'Volume',
46 'Codecs': 'Codecs',
47 'Color': 'Color',
48 'Go back to the live': 'Go back to the live',
49 'Connection Speed': 'Connection Speed',
50 'Network Activity': 'Network Activity',
51 'Total Transfered': 'Total Transfered',
52 'Download Breakdown': 'Download Breakdown',
53 'Buffer Progress': 'Buffer Progress',
54 'Buffer State': 'Buffer State',
55 'Live Latency': 'Live Latency',
56 'P2P': 'P2P',
57 '{1} seconds': '{1} seconds',
58 'enabled': 'enabled',
59 'Playlist: {1}': 'Playlist: {1}',
60 'disabled': 'disabled',
61 ' off': ' off',
62 'Player mode': 'Player mode',
63 'Play in loop': 'Play in loop',
64 'This live has not started yet.': 'This live has not started yet.',
65 'This live has ended.': 'This live has ended.',
66 'The video failed to play, will try to fast forward.': 'The video failed to play, will try to fast forward.',
67 '{1} / {2} dropped of {3}': '{1} / {2} dropped of {3}',
68 ' (muted)': ' (muted)',
69 '{1} from servers · {2} from peers': '{1} from servers · {2} from peers',
70 'Previous video': 'Previous video',
71 'Video page (new window)': 'Video page (new window)',
72 'Next video': 'Next video'
73 }
74 Object.assign(playerKeys, videojs)
75
76 // Server keys
77 const serverKeys: any = {}
78 Object.values(VIDEO_CATEGORIES)
79 .concat(Object.values(VIDEO_LICENCES))
80 .concat(Object.values(VIDEO_PRIVACIES))
81 .concat(Object.values(VIDEO_STATES))
82 .concat(Object.values(VIDEO_IMPORT_STATES))
83 .concat(Object.values(VIDEO_PLAYLIST_PRIVACIES))
84 .concat(Object.values(VIDEO_PLAYLIST_TYPES))
85 .concat(Object.values(USER_ROLE_LABELS))
86 .concat(Object.values(VIDEO_CHANNEL_SYNC_STATE))
87 .concat(Object.values(ABUSE_STATES))
88 .concat(Object.values(USER_REGISTRATION_STATES))
89 .concat(Object.values(RUNNER_JOB_STATES))
90 .concat([
91 'This video does not exist.',
92 'We cannot fetch the video. Please try again later.',
93 'Sorry',
94 'This video is not available because the remote instance is not responding.',
95 'This playlist does not exist',
96 'We cannot fetch the playlist. Please try again later.',
97 'Playlist: {1}',
98 'By {1}',
99 'Unavailable video'
100 ])
101 .forEach(v => { serverKeys[v] = v })
102
103 // More keys
104 Object.assign(serverKeys, {
105 Unknown: 'Unknown'
106 })
107
108 // ISO 639 keys
109 const languageKeys: any = {}
110 const languages = buildLanguages()
111 Object.keys(languages).forEach(k => { languageKeys[languages[k]] = languages[k] })
112
113 Object.assign(serverKeys, languageKeys)
114
115 writeAll().catch(err => {
116 console.error(err)
117 process.exit(-1)
118 })
119
120 async function writeAll () {
121 const localePath = join(root(), 'client', 'src', 'locale')
122
123 await writeJSON(join(localePath, 'player.en-US.json'), playerKeys, { spaces: 4 })
124 await writeJSON(join(localePath, 'server.en-US.json'), serverKeys, { spaces: 4 })
125
126 for (const key of Object.keys(I18N_LOCALES)) {
127 const playerJsonPath = join(localePath, `player.${key}.json`)
128 const translatedPlayer = require(playerJsonPath)
129
130 const newTranslatedPlayer = Object.assign({}, playerKeys, translatedPlayer)
131 await writeJSON(playerJsonPath, newTranslatedPlayer, { spaces: 4 })
132
133 const serverJsonPath = join(localePath, `server.${key}.json`)
134 const translatedServer = require(serverJsonPath)
135
136 const newTranslatedServer = Object.assign({}, serverKeys, translatedServer)
137 await writeJSON(serverJsonPath, newTranslatedServer, { spaces: 4 })
138 }
139 }