]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/i18n/create-custom-files.ts
e946b8fd63f27977eef21657f0253a7bcaf57cda
[github/Chocobozzz/PeerTube.git] / scripts / i18n / create-custom-files.ts
1 import { registerTSPaths } from '../../server/helpers/register-ts-paths'
2 registerTSPaths()
3
4 import * as jsToXliff12 from 'xliff/jsToXliff12'
5 import { writeFile } from 'fs-extra'
6 import { join } from 'path'
7 import {
8 buildLanguages,
9 VIDEO_CATEGORIES,
10 VIDEO_IMPORT_STATES,
11 VIDEO_LICENCES, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES,
12 VIDEO_PRIVACIES,
13 VIDEO_STATES
14 } from '../../server/initializers/constants'
15 import { values } from 'lodash'
16
17 type TranslationType = {
18 target: string
19 data: { [id: string]: string }
20 }
21
22 const videojs = require(join(__dirname, '../../../client/src/locale/source/videojs_en_US.json'))
23 const playerKeys = {
24 'Quality': 'Quality',
25 'Auto': 'Auto',
26 'Speed': 'Speed',
27 'Subtitles/CC': 'Subtitles/CC',
28 'peers': 'peers',
29 'peer': 'peer',
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',
35 'Copy embed code': 'Copy embed code',
36 'Copy magnet URI': 'Copy magnet URI',
37 'Total downloaded: ': 'Total downloaded: ',
38 'Total uploaded: ': 'Total uploaded: '
39 }
40 const playerTranslations = {
41 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
42 data: Object.assign({}, videojs, playerKeys)
43 }
44
45 // Server keys
46 const serverKeys: any = {}
47 values(VIDEO_CATEGORIES)
48 .concat(values(VIDEO_LICENCES))
49 .concat(values(VIDEO_PRIVACIES))
50 .concat(values(VIDEO_STATES))
51 .concat(values(VIDEO_IMPORT_STATES))
52 .concat(values(VIDEO_PLAYLIST_PRIVACIES))
53 .concat(values(VIDEO_PLAYLIST_TYPES))
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 ])
60 .forEach(v => serverKeys[v] = v)
61
62 // More keys
63 Object.assign(serverKeys, {
64 'Misc': 'Misc',
65 'Unknown': 'Unknown'
66 })
67
68 const serverTranslations = {
69 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
70 data: serverKeys
71 }
72
73 // ISO 639 keys
74 const languageKeys: any = {}
75 const languages = buildLanguages()
76 Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
77
78 const iso639Translations = {
79 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
80 data: languageKeys
81 }
82
83 saveToXliffFile(playerTranslations, err => {
84 if (err) return handleError(err)
85
86 saveToXliffFile(serverTranslations, err => {
87 if (err) return handleError(err)
88
89 saveToXliffFile(iso639Translations, err => {
90 if (err) return handleError(err)
91
92 process.exit(0)
93 })
94 })
95 })
96
97 // Then, the server strings
98
99 function 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
107 jsToXliff12(obj, (err, res) => {
108 if (err) return cb(err)
109
110 writeFile(jsonTranslations.target, res, err => {
111 if (err) return cb(err)
112
113 return cb(null)
114 })
115 })
116 }
117
118 function handleError (err: any) {
119 console.error(err)
120 process.exit(-1)
121 }