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