diff options
Diffstat (limited to 'scripts/i18n/create-custom-files.ts')
-rwxr-xr-x | scripts/i18n/create-custom-files.ts | 73 |
1 files changed, 13 insertions, 60 deletions
diff --git a/scripts/i18n/create-custom-files.ts b/scripts/i18n/create-custom-files.ts index e946b8fd6..47b3e3784 100755 --- a/scripts/i18n/create-custom-files.ts +++ b/scripts/i18n/create-custom-files.ts | |||
@@ -1,25 +1,21 @@ | |||
1 | import { registerTSPaths } from '../../server/helpers/register-ts-paths' | 1 | import { registerTSPaths } from '../../server/helpers/register-ts-paths' |
2 | registerTSPaths() | 2 | import { writeJSON } from 'fs-extra' |
3 | |||
4 | import * as jsToXliff12 from 'xliff/jsToXliff12' | ||
5 | import { writeFile } from 'fs-extra' | ||
6 | import { join } from 'path' | 3 | import { join } from 'path' |
7 | import { | 4 | import { |
8 | buildLanguages, | 5 | buildLanguages, |
9 | VIDEO_CATEGORIES, | 6 | VIDEO_CATEGORIES, |
10 | VIDEO_IMPORT_STATES, | 7 | VIDEO_IMPORT_STATES, |
11 | VIDEO_LICENCES, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES, | 8 | VIDEO_LICENCES, |
9 | VIDEO_PLAYLIST_PRIVACIES, | ||
10 | VIDEO_PLAYLIST_TYPES, | ||
12 | VIDEO_PRIVACIES, | 11 | VIDEO_PRIVACIES, |
13 | VIDEO_STATES | 12 | VIDEO_STATES |
14 | } from '../../server/initializers/constants' | 13 | } from '../../server/initializers/constants' |
15 | import { values } from 'lodash' | 14 | import { values } from 'lodash' |
16 | 15 | ||
17 | type TranslationType = { | 16 | registerTSPaths() |
18 | target: string | ||
19 | data: { [id: string]: string } | ||
20 | } | ||
21 | 17 | ||
22 | const videojs = require(join(__dirname, '../../../client/src/locale/source/videojs_en_US.json')) | 18 | const videojs = require(join(__dirname, '../../../client/src/locale/videojs.en-US.json')) |
23 | const playerKeys = { | 19 | const playerKeys = { |
24 | 'Quality': 'Quality', | 20 | 'Quality': 'Quality', |
25 | 'Auto': 'Auto', | 21 | 'Auto': 'Auto', |
@@ -37,10 +33,7 @@ const playerKeys = { | |||
37 | 'Total downloaded: ': 'Total downloaded: ', | 33 | 'Total downloaded: ': 'Total downloaded: ', |
38 | 'Total uploaded: ': 'Total uploaded: ' | 34 | 'Total uploaded: ': 'Total uploaded: ' |
39 | } | 35 | } |
40 | const playerTranslations = { | 36 | Object.assign(playerKeys, videojs) |
41 | target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'), | ||
42 | data: Object.assign({}, videojs, playerKeys) | ||
43 | } | ||
44 | 37 | ||
45 | // Server keys | 38 | // Server keys |
46 | const serverKeys: any = {} | 39 | const serverKeys: any = {} |
@@ -65,57 +58,17 @@ Object.assign(serverKeys, { | |||
65 | 'Unknown': 'Unknown' | 58 | 'Unknown': 'Unknown' |
66 | }) | 59 | }) |
67 | 60 | ||
68 | const serverTranslations = { | ||
69 | target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'), | ||
70 | data: serverKeys | ||
71 | } | ||
72 | |||
73 | // ISO 639 keys | 61 | // ISO 639 keys |
74 | const languageKeys: any = {} | 62 | const languageKeys: any = {} |
75 | const languages = buildLanguages() | 63 | const languages = buildLanguages() |
76 | Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k]) | 64 | Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k]) |
77 | 65 | ||
78 | const iso639Translations = { | 66 | Object.assign(serverKeys, languageKeys) |
79 | target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'), | ||
80 | data: languageKeys | ||
81 | } | ||
82 | |||
83 | saveToXliffFile(playerTranslations, err => { | ||
84 | if (err) return handleError(err) | ||
85 | |||
86 | saveToXliffFile(serverTranslations, err => { | ||
87 | if (err) return handleError(err) | ||
88 | |||
89 | saveToXliffFile(iso639Translations, err => { | ||
90 | if (err) return handleError(err) | ||
91 | 67 | ||
92 | process.exit(0) | 68 | Promise.all([ |
93 | }) | 69 | writeJSON(join(__dirname, '../../../client/src/locale/player.en-US.json'), playerKeys), |
94 | }) | 70 | writeJSON(join(__dirname, '../../../client/src/locale/server.en-US.json'), serverKeys) |
95 | }) | 71 | ]).catch(err => { |
96 | |||
97 | // Then, the server strings | ||
98 | |||
99 | function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) { | ||
100 | const obj = { | ||
101 | resources: { | ||
102 | namespace1: {} | ||
103 | } | ||
104 | } | ||
105 | Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] }) | ||
106 | |||
107 | jsToXliff12(obj, (err, res) => { | ||
108 | if (err) return cb(err) | ||
109 | |||
110 | writeFile(jsonTranslations.target, res, err => { | ||
111 | if (err) return cb(err) | ||
112 | |||
113 | return cb(null) | ||
114 | }) | ||
115 | }) | ||
116 | } | ||
117 | |||
118 | function handleError (err: any) { | ||
119 | console.error(err) | 72 | console.error(err) |
120 | process.exit(-1) | 73 | process.exit(-1) |
121 | } | 74 | }) |