]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/i18n/create-custom-files.ts
Fix bug with tsconfig paths
[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,
830b4faf 8 VIDEO_LICENCES, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES,
7e5f9f00
C
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 32 'Copy embed code': 'Copy embed code',
37c6bb36 33 'Copy magnet URI': 'Copy magnet URI',
09209296
C
34 'Total downloaded: ': 'Total downloaded: ',
35 'Total uploaded: ': 'Total uploaded: '
e945b184 36}
7ce44a74
C
37const playerTranslations = {
38 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
39 data: Object.assign({}, videojs, playerKeys)
e945b184
C
40}
41
7ce44a74
C
42// Server keys
43const serverKeys: any = {}
44values(VIDEO_CATEGORIES)
45 .concat(values(VIDEO_LICENCES))
46 .concat(values(VIDEO_PRIVACIES))
7e5f9f00
C
47 .concat(values(VIDEO_STATES))
48 .concat(values(VIDEO_IMPORT_STATES))
830b4faf
C
49 .concat(values(VIDEO_PLAYLIST_PRIVACIES))
50 .concat(values(VIDEO_PLAYLIST_TYPES))
ad3fa0c5
C
51 .concat([
52 'This video does not exist.',
53 'We cannot fetch the video. Please try again later.',
54 'Sorry',
55 'This video is not available because the remote instance is not responding.'
56 ])
7ce44a74
C
57 .forEach(v => serverKeys[v] = v)
58
7ce44a74
C
59// More keys
60Object.assign(serverKeys, {
61 'Misc': 'Misc',
62 'Unknown': 'Unknown'
63})
64
65const serverTranslations = {
66 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
67 data: serverKeys
e945b184
C
68}
69
850c1bf7
C
70// ISO 639 keys
71const languageKeys: any = {}
72const languages = buildLanguages()
73Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
74
75const iso639Translations = {
76 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
77 data: languageKeys
78}
79
7ce44a74
C
80saveToXliffFile(playerTranslations, err => {
81 if (err) return handleError(err)
82
83 saveToXliffFile(serverTranslations, err => {
84 if (err) return handleError(err)
e945b184 85
850c1bf7
C
86 saveToXliffFile(iso639Translations, err => {
87 if (err) return handleError(err)
88
89 process.exit(0)
90 })
7ce44a74 91 })
e945b184
C
92})
93
94// Then, the server strings
f07d6385 95
7ce44a74
C
96function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
97 const obj = {
98 resources: {
99 namespace1: {}
100 }
101 }
102 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
103
f07d6385
C
104 jsToXliff12(obj, (err, res) => {
105 if (err) return cb(err)
106
7ce44a74 107 writeFile(jsonTranslations.target, res, err => {
f07d6385
C
108 if (err) return cb(err)
109
110 return cb(null)
111 })
112 })
113}
7ce44a74
C
114
115function handleError (err: any) {
116 console.error(err)
117 process.exit(-1)
ad3fa0c5 118}