]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/i18n/create-custom-files.ts
Implement captions/subtitles
[github/Chocobozzz/PeerTube.git] / scripts / i18n / create-custom-files.ts
CommitLineData
e945b184
C
1import * as jsToXliff12 from 'xliff/jsToXliff12'
2import { writeFile } from 'fs'
3import { join } from 'path'
7ce44a74
C
4import { buildLanguages, VIDEO_CATEGORIES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../server/initializers/constants'
5import { values } from 'lodash'
e945b184 6
7ce44a74
C
7type TranslationType = {
8 target: string
9 data: { [id: string]: string }
10}
e945b184 11
7ce44a74 12const videojs = require(join(__dirname, '../../../client/src/locale/source/videojs_en_US.json'))
e945b184
C
13const playerKeys = {
14 'Quality': 'Quality',
15 'Auto': 'Auto',
16 'Speed': 'Speed',
17 'peers': 'peers',
18 'Go to the video page': 'Go to the video page',
19 'Settings': 'Settings',
20 'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.',
21 'Copy the video URL': 'Copy the video URL',
22 'Copy the video URL at the current time': 'Copy the video URL at the current time',
23 'Copy embed code': 'Copy embed code'
24}
7ce44a74
C
25const playerTranslations = {
26 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
27 data: Object.assign({}, videojs, playerKeys)
e945b184
C
28}
29
7ce44a74
C
30// Server keys
31const serverKeys: any = {}
32values(VIDEO_CATEGORIES)
33 .concat(values(VIDEO_LICENCES))
34 .concat(values(VIDEO_PRIVACIES))
35 .forEach(v => serverKeys[v] = v)
36
7ce44a74
C
37// More keys
38Object.assign(serverKeys, {
39 'Misc': 'Misc',
40 'Unknown': 'Unknown'
41})
42
43const serverTranslations = {
44 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
45 data: serverKeys
e945b184
C
46}
47
850c1bf7
C
48// ISO 639 keys
49const languageKeys: any = {}
50const languages = buildLanguages()
51Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
52
53const iso639Translations = {
54 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
55 data: languageKeys
56}
57
7ce44a74
C
58saveToXliffFile(playerTranslations, err => {
59 if (err) return handleError(err)
60
61 saveToXliffFile(serverTranslations, err => {
62 if (err) return handleError(err)
e945b184 63
850c1bf7
C
64 saveToXliffFile(iso639Translations, err => {
65 if (err) return handleError(err)
66
67 process.exit(0)
68 })
7ce44a74 69 })
e945b184
C
70})
71
72// Then, the server strings
f07d6385 73
7ce44a74
C
74function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
75 const obj = {
76 resources: {
77 namespace1: {}
78 }
79 }
80 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
81
f07d6385
C
82 jsToXliff12(obj, (err, res) => {
83 if (err) return cb(err)
84
7ce44a74 85 writeFile(jsonTranslations.target, res, err => {
f07d6385
C
86 if (err) return cb(err)
87
88 return cb(null)
89 })
90 })
91}
7ce44a74
C
92
93function handleError (err: any) {
94 console.error(err)
95 process.exit(-1)
96}