aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/i18n
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/i18n')
-rwxr-xr-xscripts/i18n/create-custom-files.ts70
-rwxr-xr-xscripts/i18n/xliff2json.ts62
2 files changed, 92 insertions, 40 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
diff --git a/scripts/i18n/xliff2json.ts b/scripts/i18n/xliff2json.ts
index 34784ac11..fa5a71d65 100755
--- a/scripts/i18n/xliff2json.ts
+++ b/scripts/i18n/xliff2json.ts
@@ -1,33 +1,53 @@
1import * as xliff12ToJs from 'xliff/xliff12ToJs' 1import * as xliff12ToJs from 'xliff/xliff12ToJs'
2import { readFileSync, writeFile } from 'fs' 2import { unlink, readFileSync, writeFile } from 'fs'
3import { join } from 'path' 3import { join } from 'path'
4import { buildFileLocale, I18N_LOCALES, isDefaultLocale } from '../../shared/models/i18n/i18n'
5import { eachSeries } from 'async'
4 6
5// First, the player 7const sources: string[] = []
6const playerSource = join(__dirname, '../../../client/src/locale/target/player_fr.xml') 8const availableLocales = Object.keys(I18N_LOCALES)
7const playerTarget = join(__dirname, '../../../client/src/locale/target/player_fr.json') 9 .filter(l => isDefaultLocale(l) === false)
10 .map(l => buildFileLocale(l))
8 11
9// Remove the two first lines our xliff module does not like 12for (const file of [ 'server', 'player' ]) {
10let playerFile = readFileSync(playerSource).toString() 13 for (const locale of availableLocales) {
11playerFile = removeFirstLine(playerFile) 14 sources.push(join(__dirname, '../../../client/src/locale/target/', `${file}_${locale}.xml`))
12playerFile = removeFirstLine(playerFile)
13
14xliff12ToJs(playerFile, (err, res) => {
15 if (err) {
16 console.error(err)
17 process.exit(-1)
18 } 15 }
16}
19 17
20 const json = createJSONString(res) 18eachSeries(sources, (source, cb) => {
21 writeFile(playerTarget, json, err => { 19 xliffFile2JSON(source, cb)
22 if (err) { 20}, err => {
23 console.error(err) 21 if (err) return handleError(err)
24 process.exit(-1)
25 }
26 22
27 process.exit(0) 23 process.exit(0)
28 })
29}) 24})
30 25
26function handleError (err: any) {
27 console.error(err)
28 process.exit(-1)
29}
30
31function xliffFile2JSON (filePath: string, cb) {
32 const fileTarget = filePath.replace('.xml', '.json')
33
34 // Remove the two first lines our xliff module does not like
35 let fileContent = readFileSync(filePath).toString()
36 fileContent = removeFirstLine(fileContent)
37 fileContent = removeFirstLine(fileContent)
38
39 xliff12ToJs(fileContent, (err, res) => {
40 if (err) return cb(err)
41
42 const json = createJSONString(res)
43 writeFile(fileTarget, json, err => {
44 if (err) return cb(err)
45
46 return unlink(filePath, cb)
47 })
48 })
49}
50
31function removeFirstLine (str: string) { 51function removeFirstLine (str: string) {
32 return str.substring(str.indexOf('\n') + 1) 52 return str.substring(str.indexOf('\n') + 1)
33} 53}