aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/i18n/create-custom-files.ts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/i18n/create-custom-files.ts')
-rwxr-xr-xscripts/i18n/create-custom-files.ts70
1 files changed, 51 insertions, 19 deletions
diff --git a/scripts/i18n/create-custom-files.ts b/scripts/i18n/create-custom-files.ts
index d8a87f291..3519afd47 100755
--- a/scripts/i18n/create-custom-files.ts
+++ b/scripts/i18n/create-custom-files.ts
@@ -1,12 +1,15 @@
1import * as jsToXliff12 from 'xliff/jsToXliff12' 1import * as jsToXliff12 from 'xliff/jsToXliff12'
2import { writeFile } from 'fs' 2import { writeFile } from 'fs'
3import { join } from 'path' 3import { join } from 'path'
4import { buildLanguages, VIDEO_CATEGORIES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../server/initializers/constants'
5import { values } from 'lodash'
4 6
5// First, the player 7type TranslationType = {
6const playerSource = join(__dirname, '../../../client/src/locale/source/videojs_en_US.json') 8 target: string
7const playerTarget = join(__dirname, '../../../client/src/locale/source/player_en_US.xml') 9 data: { [id: string]: string }
10}
8 11
9const videojs = require(playerSource) 12const videojs = require(join(__dirname, '../../../client/src/locale/source/videojs_en_US.json'))
10const playerKeys = { 13const playerKeys = {
11 'Quality': 'Quality', 14 'Quality': 'Quality',
12 'Auto': 'Auto', 15 'Auto': 'Auto',
@@ -19,36 +22,65 @@ const playerKeys = {
19 'Copy the video URL at the current time': 'Copy the video URL at the current time', 22 'Copy the video URL at the current time': 'Copy the video URL at the current time',
20 'Copy embed code': 'Copy embed code' 23 'Copy embed code': 'Copy embed code'
21} 24}
22 25const playerTranslations = {
23const obj = { 26 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
24 resources: { 27 data: Object.assign({}, videojs, playerKeys)
25 namespace1: {}
26 }
27} 28}
28 29
29for (const sourceObject of [ videojs, playerKeys ]) { 30// Server keys
30 Object.keys(sourceObject).forEach(k => obj.resources.namespace1[ k ] = { source: sourceObject[ k ] }) 31const serverKeys: any = {}
32values(VIDEO_CATEGORIES)
33 .concat(values(VIDEO_LICENCES))
34 .concat(values(VIDEO_PRIVACIES))
35 .forEach(v => serverKeys[v] = v)
36
37// ISO 639 keys
38const languages = buildLanguages()
39Object.keys(languages).forEach(k => serverKeys[languages[k]] = languages[k])
40
41// More keys
42Object.assign(serverKeys, {
43 'Misc': 'Misc',
44 'Unknown': 'Unknown'
45})
46
47const serverTranslations = {
48 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
49 data: serverKeys
31} 50}
32 51
33saveToXliffFile(playerTarget, obj, err => { 52saveToXliffFile(playerTranslations, err => {
34 if (err) { 53 if (err) return handleError(err)
35 console.error(err) 54
36 process.exit(-1) 55 saveToXliffFile(serverTranslations, err => {
37 } 56 if (err) return handleError(err)
38 57
39 process.exit(0) 58 process.exit(0)
59 })
40}) 60})
41 61
42// Then, the server strings 62// Then, the server strings
43 63
44function saveToXliffFile (targetPath: string, obj: any, cb: Function) { 64function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
65 const obj = {
66 resources: {
67 namespace1: {}
68 }
69 }
70 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
71
45 jsToXliff12(obj, (err, res) => { 72 jsToXliff12(obj, (err, res) => {
46 if (err) return cb(err) 73 if (err) return cb(err)
47 74
48 writeFile(playerTarget, res, err => { 75 writeFile(jsonTranslations.target, res, err => {
49 if (err) return cb(err) 76 if (err) return cb(err)
50 77
51 return cb(null) 78 return cb(null)
52 }) 79 })
53 }) 80 })
54} 81}
82
83function handleError (err: any) {
84 console.error(err)
85 process.exit(-1)
86} \ No newline at end of file