]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/i18n/create-custom-files.ts
Fix "Off" player string localization
[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 embed code': 'Copy 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 'Stats for nerds': 'Stats for nerds',
40 'Theater mode': 'Theater mode',
41 'Video UUID': 'Video UUID',
42 'Viewport / Frames': 'Viewport / Frames',
43 'Resolution': 'Resolution',
44 'Volume': 'Volume',
45 'Codecs': 'Codecs',
46 'Color': 'Color',
47 'Connection Speed': 'Connection Speed',
48 'Network Activity': 'Network Activity',
49 'Total Transfered': 'Total Transfered',
50 'Download Breakdown': 'Download Breakdown',
51 'Buffer Progress': 'Buffer Progress',
52 'Buffer State': 'Buffer State',
53 'Live Latency': 'Live Latency',
54 ' off': ' off',
55 'Player mode': 'Player mode'
56 }
57 Object.assign(playerKeys, videojs)
58
59 // Server keys
60 const serverKeys: any = {}
61 values(VIDEO_CATEGORIES)
62 .concat(values(VIDEO_LICENCES))
63 .concat(values(VIDEO_PRIVACIES))
64 .concat(values(VIDEO_STATES))
65 .concat(values(VIDEO_IMPORT_STATES))
66 .concat(values(VIDEO_PLAYLIST_PRIVACIES))
67 .concat(values(VIDEO_PLAYLIST_TYPES))
68 .concat([
69 'This video does not exist.',
70 'We cannot fetch the video. Please try again later.',
71 'Sorry',
72 'This video is not available because the remote instance is not responding.',
73 'This playlist does not exist',
74 'We cannot fetch the playlist. Please try again later.',
75 'Playlist: {1}',
76 'By {1}',
77 'Unavailable video'
78 ])
79 .forEach(v => { serverKeys[v] = v })
80
81 // More keys
82 Object.assign(serverKeys, {
83 Misc: 'Misc',
84 Unknown: 'Unknown'
85 })
86
87 // ISO 639 keys
88 const languageKeys: any = {}
89 const languages = buildLanguages()
90 Object.keys(languages).forEach(k => { languageKeys[languages[k]] = languages[k] })
91
92 Object.assign(serverKeys, languageKeys)
93
94 writeAll().catch(err => {
95 console.error(err)
96 process.exit(-1)
97 })
98
99 async function writeAll () {
100 const localePath = join(__dirname, '../../../client/src/locale')
101
102 await writeJSON(join(localePath, 'player.en-US.json'), playerKeys, { spaces: 4 })
103 await writeJSON(join(localePath, 'server.en-US.json'), serverKeys, { spaces: 4 })
104
105 for (const key of Object.keys(I18N_LOCALES)) {
106 const playerJsonPath = join(localePath, `player.${key}.json`)
107 const translatedPlayer = require(playerJsonPath)
108
109 const newTranslatedPlayer = Object.assign({}, playerKeys, translatedPlayer)
110 await writeJSON(playerJsonPath, newTranslatedPlayer, { spaces: 4 })
111
112 const serverJsonPath = join(localePath, `server.${key}.json`)
113 const translatedServer = require(serverJsonPath)
114
115 const newTranslatedServer = Object.assign({}, serverKeys, translatedServer)
116 await writeJSON(serverJsonPath, newTranslatedServer, { spaces: 4 })
117 }
118 }