diff options
Diffstat (limited to 'scripts/i18n/create-custom-files.ts')
-rwxr-xr-x | scripts/i18n/create-custom-files.ts | 70 |
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 @@ | |||
1 | import * as jsToXliff12 from 'xliff/jsToXliff12' | 1 | import * as jsToXliff12 from 'xliff/jsToXliff12' |
2 | import { writeFile } from 'fs' | 2 | import { writeFile } from 'fs' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { buildLanguages, VIDEO_CATEGORIES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../server/initializers/constants' | ||
5 | import { values } from 'lodash' | ||
4 | 6 | ||
5 | // First, the player | 7 | type TranslationType = { |
6 | const playerSource = join(__dirname, '../../../client/src/locale/source/videojs_en_US.json') | 8 | target: string |
7 | const playerTarget = join(__dirname, '../../../client/src/locale/source/player_en_US.xml') | 9 | data: { [id: string]: string } |
10 | } | ||
8 | 11 | ||
9 | const videojs = require(playerSource) | 12 | const videojs = require(join(__dirname, '../../../client/src/locale/source/videojs_en_US.json')) |
10 | const playerKeys = { | 13 | const 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 | 25 | const playerTranslations = { | |
23 | const 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 | ||
29 | for (const sourceObject of [ videojs, playerKeys ]) { | 30 | // Server keys |
30 | Object.keys(sourceObject).forEach(k => obj.resources.namespace1[ k ] = { source: sourceObject[ k ] }) | 31 | const serverKeys: any = {} |
32 | values(VIDEO_CATEGORIES) | ||
33 | .concat(values(VIDEO_LICENCES)) | ||
34 | .concat(values(VIDEO_PRIVACIES)) | ||
35 | .forEach(v => serverKeys[v] = v) | ||
36 | |||
37 | // ISO 639 keys | ||
38 | const languages = buildLanguages() | ||
39 | Object.keys(languages).forEach(k => serverKeys[languages[k]] = languages[k]) | ||
40 | |||
41 | // More keys | ||
42 | Object.assign(serverKeys, { | ||
43 | 'Misc': 'Misc', | ||
44 | 'Unknown': 'Unknown' | ||
45 | }) | ||
46 | |||
47 | const serverTranslations = { | ||
48 | target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'), | ||
49 | data: serverKeys | ||
31 | } | 50 | } |
32 | 51 | ||
33 | saveToXliffFile(playerTarget, obj, err => { | 52 | saveToXliffFile(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 | ||
44 | function saveToXliffFile (targetPath: string, obj: any, cb: Function) { | 64 | function 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 | |||
83 | function handleError (err: any) { | ||
84 | console.error(err) | ||
85 | process.exit(-1) | ||
86 | } \ No newline at end of file | ||