]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/i18n/create-custom-files.ts
check email enabled for requiresEmailVer config
[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 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))
ad3fa0c5
C
49 .concat([
50 'This video does not exist.',
51 'We cannot fetch the video. Please try again later.',
52 'Sorry',
53 'This video is not available because the remote instance is not responding.'
54 ])
7ce44a74
C
55 .forEach(v => serverKeys[v] = v)
56
7ce44a74
C
57// More keys
58Object.assign(serverKeys, {
59 'Misc': 'Misc',
60 'Unknown': 'Unknown'
61})
62
63const serverTranslations = {
64 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
65 data: serverKeys
e945b184
C
66}
67
850c1bf7
C
68// ISO 639 keys
69const languageKeys: any = {}
70const languages = buildLanguages()
71Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
72
73const iso639Translations = {
74 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
75 data: languageKeys
76}
77
7ce44a74
C
78saveToXliffFile(playerTranslations, err => {
79 if (err) return handleError(err)
80
81 saveToXliffFile(serverTranslations, err => {
82 if (err) return handleError(err)
e945b184 83
850c1bf7
C
84 saveToXliffFile(iso639Translations, err => {
85 if (err) return handleError(err)
86
87 process.exit(0)
88 })
7ce44a74 89 })
e945b184
C
90})
91
92// Then, the server strings
f07d6385 93
7ce44a74
C
94function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
95 const obj = {
96 resources: {
97 namespace1: {}
98 }
99 }
100 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
101
f07d6385
C
102 jsToXliff12(obj, (err, res) => {
103 if (err) return cb(err)
104
7ce44a74 105 writeFile(jsonTranslations.target, res, err => {
f07d6385
C
106 if (err) return cb(err)
107
108 return cb(null)
109 })
110 })
111}
7ce44a74
C
112
113function handleError (err: any) {
114 console.error(err)
115 process.exit(-1)
ad3fa0c5 116}