]>
Commit | Line | Data |
---|---|---|
e945b184 C |
1 | import * as jsToXliff12 from 'xliff/jsToXliff12' |
2 | import { writeFile } from 'fs' | |
3 | import { join } from 'path' | |
7ce44a74 C |
4 | import { buildLanguages, VIDEO_CATEGORIES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../server/initializers/constants' |
5 | import { values } from 'lodash' | |
e945b184 | 6 | |
7ce44a74 C |
7 | type TranslationType = { |
8 | target: string | |
9 | data: { [id: string]: string } | |
10 | } | |
e945b184 | 11 | |
7ce44a74 | 12 | const videojs = require(join(__dirname, '../../../client/src/locale/source/videojs_en_US.json')) |
e945b184 C |
13 | const playerKeys = { |
14 | 'Quality': 'Quality', | |
15 | 'Auto': 'Auto', | |
16 | 'Speed': 'Speed', | |
17 | 'peers': 'peers', | |
18 | 'Go to the video page': 'Go to the video page', | |
19 | 'Settings': 'Settings', | |
20 | 'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.', | |
21 | 'Copy the video URL': 'Copy the video URL', | |
22 | 'Copy the video URL at the current time': 'Copy the video URL at the current time', | |
23 | 'Copy embed code': 'Copy embed code' | |
24 | } | |
7ce44a74 C |
25 | const playerTranslations = { |
26 | target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'), | |
27 | data: Object.assign({}, videojs, playerKeys) | |
e945b184 C |
28 | } |
29 | ||
7ce44a74 C |
30 | // Server keys |
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 | |
e945b184 C |
50 | } |
51 | ||
7ce44a74 C |
52 | saveToXliffFile(playerTranslations, err => { |
53 | if (err) return handleError(err) | |
54 | ||
55 | saveToXliffFile(serverTranslations, err => { | |
56 | if (err) return handleError(err) | |
e945b184 | 57 | |
7ce44a74 C |
58 | process.exit(0) |
59 | }) | |
e945b184 C |
60 | }) |
61 | ||
62 | // Then, the server strings | |
f07d6385 | 63 | |
7ce44a74 C |
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 | ||
f07d6385 C |
72 | jsToXliff12(obj, (err, res) => { |
73 | if (err) return cb(err) | |
74 | ||
7ce44a74 | 75 | writeFile(jsonTranslations.target, res, err => { |
f07d6385 C |
76 | if (err) return cb(err) |
77 | ||
78 | return cb(null) | |
79 | }) | |
80 | }) | |
81 | } | |
7ce44a74 C |
82 | |
83 | function handleError (err: any) { | |
84 | console.error(err) | |
85 | process.exit(-1) | |
86 | } |