]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/i18n/create-custom-files.ts
Merge branch 'release/beta-10' into develop
[github/Chocobozzz/PeerTube.git] / scripts / i18n / create-custom-files.ts
1 import * as jsToXliff12 from 'xliff/jsToXliff12'
2 import { writeFile } from 'fs'
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 'Go to the video page': 'Go to the video page',
27 'Settings': 'Settings',
28 'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.',
29 'Copy the video URL': 'Copy the video URL',
30 'Copy the video URL at the current time': 'Copy the video URL at the current time',
31 'Copy embed code': 'Copy embed code'
32 }
33 const playerTranslations = {
34 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
35 data: Object.assign({}, videojs, playerKeys)
36 }
37
38 // Server keys
39 const serverKeys: any = {}
40 values(VIDEO_CATEGORIES)
41 .concat(values(VIDEO_LICENCES))
42 .concat(values(VIDEO_PRIVACIES))
43 .concat(values(VIDEO_STATES))
44 .concat(values(VIDEO_IMPORT_STATES))
45 .forEach(v => serverKeys[v] = v)
46
47 // More keys
48 Object.assign(serverKeys, {
49 'Misc': 'Misc',
50 'Unknown': 'Unknown'
51 })
52
53 const serverTranslations = {
54 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
55 data: serverKeys
56 }
57
58 // ISO 639 keys
59 const languageKeys: any = {}
60 const languages = buildLanguages()
61 Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
62
63 const iso639Translations = {
64 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
65 data: languageKeys
66 }
67
68 saveToXliffFile(playerTranslations, err => {
69 if (err) return handleError(err)
70
71 saveToXliffFile(serverTranslations, err => {
72 if (err) return handleError(err)
73
74 saveToXliffFile(iso639Translations, err => {
75 if (err) return handleError(err)
76
77 process.exit(0)
78 })
79 })
80 })
81
82 // Then, the server strings
83
84 function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
85 const obj = {
86 resources: {
87 namespace1: {}
88 }
89 }
90 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
91
92 jsToXliff12(obj, (err, res) => {
93 if (err) return cb(err)
94
95 writeFile(jsonTranslations.target, res, err => {
96 if (err) return cb(err)
97
98 return cb(null)
99 })
100 })
101 }
102
103 function handleError (err: any) {
104 console.error(err)
105 process.exit(-1)
106 }