]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/i18n/create-custom-files.ts
Use typescript paths in cli scripts too
[github/Chocobozzz/PeerTube.git] / scripts / i18n / create-custom-files.ts
CommitLineData
2aaa1a3f
C
1import { registerTSPaths } from '../../server/helpers/register-ts-paths'
2registerTSPaths()
3
e945b184 4import * as jsToXliff12 from 'xliff/jsToXliff12'
c9d5c64f 5import { writeFile } from 'fs-extra'
e945b184 6import { join } from 'path'
7e5f9f00
C
7import {
8 buildLanguages,
9 VIDEO_CATEGORIES,
10 VIDEO_IMPORT_STATES,
830b4faf 11 VIDEO_LICENCES, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES,
7e5f9f00
C
12 VIDEO_PRIVACIES,
13 VIDEO_STATES
14} from '../../server/initializers/constants'
7ce44a74 15import { values } from 'lodash'
e945b184 16
7ce44a74
C
17type TranslationType = {
18 target: string
19 data: { [id: string]: string }
20}
e945b184 21
7ce44a74 22const videojs = require(join(__dirname, '../../../client/src/locale/source/videojs_en_US.json'))
e945b184
C
23const playerKeys = {
24 'Quality': 'Quality',
25 'Auto': 'Auto',
26 'Speed': 'Speed',
16f7022b 27 'Subtitles/CC': 'Subtitles/CC',
e945b184 28 'peers': 'peers',
09209296 29 'peer': 'peer',
e945b184
C
30 'Go to the video page': 'Go to the video page',
31 'Settings': 'Settings',
32 'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.',
33 'Copy the video URL': 'Copy the video URL',
34 'Copy the video URL at the current time': 'Copy the video URL at the current time',
09209296 35 'Copy embed code': 'Copy embed code',
37c6bb36 36 'Copy magnet URI': 'Copy magnet URI',
09209296
C
37 'Total downloaded: ': 'Total downloaded: ',
38 'Total uploaded: ': 'Total uploaded: '
e945b184 39}
7ce44a74
C
40const playerTranslations = {
41 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
42 data: Object.assign({}, videojs, playerKeys)
e945b184
C
43}
44
7ce44a74
C
45// Server keys
46const serverKeys: any = {}
47values(VIDEO_CATEGORIES)
48 .concat(values(VIDEO_LICENCES))
49 .concat(values(VIDEO_PRIVACIES))
7e5f9f00
C
50 .concat(values(VIDEO_STATES))
51 .concat(values(VIDEO_IMPORT_STATES))
830b4faf
C
52 .concat(values(VIDEO_PLAYLIST_PRIVACIES))
53 .concat(values(VIDEO_PLAYLIST_TYPES))
ad3fa0c5
C
54 .concat([
55 'This video does not exist.',
56 'We cannot fetch the video. Please try again later.',
57 'Sorry',
58 'This video is not available because the remote instance is not responding.'
59 ])
7ce44a74
C
60 .forEach(v => serverKeys[v] = v)
61
7ce44a74
C
62// More keys
63Object.assign(serverKeys, {
64 'Misc': 'Misc',
65 'Unknown': 'Unknown'
66})
67
68const serverTranslations = {
69 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
70 data: serverKeys
e945b184
C
71}
72
850c1bf7
C
73// ISO 639 keys
74const languageKeys: any = {}
75const languages = buildLanguages()
76Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
77
78const iso639Translations = {
79 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
80 data: languageKeys
81}
82
7ce44a74
C
83saveToXliffFile(playerTranslations, err => {
84 if (err) return handleError(err)
85
86 saveToXliffFile(serverTranslations, err => {
87 if (err) return handleError(err)
e945b184 88
850c1bf7
C
89 saveToXliffFile(iso639Translations, err => {
90 if (err) return handleError(err)
91
92 process.exit(0)
93 })
7ce44a74 94 })
e945b184
C
95})
96
97// Then, the server strings
f07d6385 98
7ce44a74
C
99function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
100 const obj = {
101 resources: {
102 namespace1: {}
103 }
104 }
105 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
106
f07d6385
C
107 jsToXliff12(obj, (err, res) => {
108 if (err) return cb(err)
109
7ce44a74 110 writeFile(jsonTranslations.target, res, err => {
f07d6385
C
111 if (err) return cb(err)
112
113 return cb(null)
114 })
115 })
116}
7ce44a74
C
117
118function handleError (err: any) {
119 console.error(err)
120 process.exit(-1)
ad3fa0c5 121}