]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/i18n/create-custom-files.ts
Add hls support on server
[github/Chocobozzz/PeerTube.git] / scripts / i18n / create-custom-files.ts
CommitLineData
e945b184 1import * as jsToXliff12 from 'xliff/jsToXliff12'
c9d5c64f 2import { writeFile } from 'fs-extra'
e945b184 3import { join } from 'path'
7e5f9f00
C
4import {
5 buildLanguages,
6 VIDEO_CATEGORIES,
7 VIDEO_IMPORT_STATES,
8 VIDEO_LICENCES,
9 VIDEO_PRIVACIES,
10 VIDEO_STATES
11} from '../../server/initializers/constants'
7ce44a74 12import { values } from 'lodash'
e945b184 13
7ce44a74
C
14type TranslationType = {
15 target: string
16 data: { [id: string]: string }
17}
e945b184 18
7ce44a74 19const videojs = require(join(__dirname, '../../../client/src/locale/source/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',
29 'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.',
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
C
32 'Copy embed code': 'Copy embed code',
33 'Total downloaded: ': 'Total downloaded: ',
34 'Total uploaded: ': 'Total uploaded: '
e945b184 35}
7ce44a74
C
36const playerTranslations = {
37 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
38 data: Object.assign({}, videojs, playerKeys)
e945b184
C
39}
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))
ad3fa0c5
C
48 .concat([
49 'This video does not exist.',
50 'We cannot fetch the video. Please try again later.',
51 'Sorry',
52 'This video is not available because the remote instance is not responding.'
53 ])
7ce44a74
C
54 .forEach(v => serverKeys[v] = v)
55
7ce44a74
C
56// More keys
57Object.assign(serverKeys, {
58 'Misc': 'Misc',
59 'Unknown': 'Unknown'
60})
61
62const serverTranslations = {
63 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
64 data: serverKeys
e945b184
C
65}
66
850c1bf7
C
67// ISO 639 keys
68const languageKeys: any = {}
69const languages = buildLanguages()
70Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
71
72const iso639Translations = {
73 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
74 data: languageKeys
75}
76
7ce44a74
C
77saveToXliffFile(playerTranslations, err => {
78 if (err) return handleError(err)
79
80 saveToXliffFile(serverTranslations, err => {
81 if (err) return handleError(err)
e945b184 82
850c1bf7
C
83 saveToXliffFile(iso639Translations, err => {
84 if (err) return handleError(err)
85
86 process.exit(0)
87 })
7ce44a74 88 })
e945b184
C
89})
90
91// Then, the server strings
f07d6385 92
7ce44a74
C
93function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
94 const obj = {
95 resources: {
96 namespace1: {}
97 }
98 }
99 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
100
f07d6385
C
101 jsToXliff12(obj, (err, res) => {
102 if (err) return cb(err)
103
7ce44a74 104 writeFile(jsonTranslations.target, res, err => {
f07d6385
C
105 if (err) return cb(err)
106
107 return cb(null)
108 })
109 })
110}
7ce44a74
C
111
112function handleError (err: any) {
113 console.error(err)
114 process.exit(-1)
ad3fa0c5 115}