]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/i18n/create-custom-files.ts
Sort on videoQuotaUsed in backend
[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, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES,
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(values(VIDEO_PLAYLIST_PRIVACIES))
50 .concat(values(VIDEO_PLAYLIST_TYPES))
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 ])
57 .forEach(v => serverKeys[v] = v)
58
59 // More keys
60 Object.assign(serverKeys, {
61 'Misc': 'Misc',
62 'Unknown': 'Unknown'
63 })
64
65 const serverTranslations = {
66 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
67 data: serverKeys
68 }
69
70 // ISO 639 keys
71 const languageKeys: any = {}
72 const languages = buildLanguages()
73 Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
74
75 const iso639Translations = {
76 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
77 data: languageKeys
78 }
79
80 saveToXliffFile(playerTranslations, err => {
81 if (err) return handleError(err)
82
83 saveToXliffFile(serverTranslations, err => {
84 if (err) return handleError(err)
85
86 saveToXliffFile(iso639Translations, err => {
87 if (err) return handleError(err)
88
89 process.exit(0)
90 })
91 })
92 })
93
94 // Then, the server strings
95
96 function 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
104 jsToXliff12(obj, (err, res) => {
105 if (err) return cb(err)
106
107 writeFile(jsonTranslations.target, res, err => {
108 if (err) return cb(err)
109
110 return cb(null)
111 })
112 })
113 }
114
115 function handleError (err: any) {
116 console.error(err)
117 process.exit(-1)
118 }