aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/i18n/xliff2json.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-13 15:55:13 +0200
committerChocobozzz <me@florianbigard.com>2018-06-13 15:55:13 +0200
commit850c1bf7cc438b935f6e283c801b34b91bf629c6 (patch)
tree0789b822fb01ebf061d957cbbeaf9e7ae5cd76ba /scripts/i18n/xliff2json.ts
parent749c7247ae9042a74d132afda0c7eefab66a0428 (diff)
downloadPeerTube-850c1bf7cc438b935f6e283c801b34b91bf629c6.tar.gz
PeerTube-850c1bf7cc438b935f6e283c801b34b91bf629c6.tar.zst
PeerTube-850c1bf7cc438b935f6e283c801b34b91bf629c6.zip
Move iso639 strings in its own translation file
Diffstat (limited to 'scripts/i18n/xliff2json.ts')
-rwxr-xr-xscripts/i18n/xliff2json.ts34
1 files changed, 30 insertions, 4 deletions
diff --git a/scripts/i18n/xliff2json.ts b/scripts/i18n/xliff2json.ts
index c60739561..17c73181b 100755
--- a/scripts/i18n/xliff2json.ts
+++ b/scripts/i18n/xliff2json.ts
@@ -1,7 +1,7 @@
1import * as xliff12ToJs from 'xliff/xliff12ToJs' 1import * as xliff12ToJs from 'xliff/xliff12ToJs'
2import { unlink, readFileSync, writeFile } from 'fs' 2import { readFile, readFileSync, unlink, writeFile } from 'fs'
3import { join } from 'path' 3import { join } from 'path'
4import { buildFileLocale, I18N_LOCALES, isDefaultLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n' 4import { buildFileLocale, I18N_LOCALES, isDefaultLocale } from '../../shared/models/i18n/i18n'
5import { eachSeries } from 'async' 5import { eachSeries } from 'async'
6 6
7const sources: string[] = [] 7const sources: string[] = []
@@ -9,7 +9,7 @@ const availableLocales = Object.keys(I18N_LOCALES)
9 .filter(l => isDefaultLocale(l) === false) 9 .filter(l => isDefaultLocale(l) === false)
10 .map(l => buildFileLocale(l)) 10 .map(l => buildFileLocale(l))
11 11
12for (const file of LOCALE_FILES) { 12for (const file of [ 'player', 'server', 'iso639' ]) {
13 for (const locale of availableLocales) { 13 for (const locale of availableLocales) {
14 sources.push(join(__dirname, '../../../client/src/locale/target/', `${file}_${locale}.xml`)) 14 sources.push(join(__dirname, '../../../client/src/locale/target/', `${file}_${locale}.xml`))
15 } 15 }
@@ -20,7 +20,11 @@ eachSeries(sources, (source, cb) => {
20}, err => { 20}, err => {
21 if (err) return handleError(err) 21 if (err) return handleError(err)
22 22
23 process.exit(0) 23 mergeISO639InServer(err => {
24 if (err) return handleError(err)
25
26 process.exit(0)
27 })
24}) 28})
25 29
26function handleError (err: any) { 30function handleError (err: any) {
@@ -48,6 +52,28 @@ function xliffFile2JSON (filePath: string, cb) {
48 }) 52 })
49} 53}
50 54
55function mergeISO639InServer (cb) {
56 eachSeries(availableLocales, (locale, eachCallback) => {
57 const serverPath = join(__dirname, '../../../client/src/locale/target/', `server_${locale}.json`)
58 const iso639Path = join(__dirname, '../../../client/src/locale/target/', `iso639_${locale}.json`)
59
60 const resServer = readFileSync(serverPath).toString()
61 const resISO639 = readFileSync(iso639Path).toString()
62
63 const jsonServer = JSON.parse(resServer)
64 const jsonISO639 = JSON.parse(resISO639)
65
66 Object.assign(jsonServer, jsonISO639)
67 const serverString = JSON.stringify(jsonServer)
68
69 writeFile(serverPath, serverString, err => {
70 if (err) return eachCallback(err)
71
72 return unlink(iso639Path, eachCallback)
73 })
74 }, cb)
75}
76
51function removeFirstLine (str: string) { 77function removeFirstLine (str: string) {
52 return str.substring(str.indexOf('\n') + 1) 78 return str.substring(str.indexOf('\n') + 1)
53} 79}