aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/i18n/xliff2json.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-06 16:46:42 +0200
committerChocobozzz <me@florianbigard.com>2018-06-06 16:48:41 +0200
commit7ce44a74a3b052190cfacd4bd5ee6b92cfc620ac (patch)
tree6f178426c165f9136eb08354efa4a06c24725f87 /scripts/i18n/xliff2json.ts
parentf07d6385b4b46c3254898292a8a53ed415b8d49b (diff)
downloadPeerTube-7ce44a74a3b052190cfacd4bd5ee6b92cfc620ac.tar.gz
PeerTube-7ce44a74a3b052190cfacd4bd5ee6b92cfc620ac.tar.zst
PeerTube-7ce44a74a3b052190cfacd4bd5ee6b92cfc620ac.zip
Add server localization
Diffstat (limited to 'scripts/i18n/xliff2json.ts')
-rwxr-xr-xscripts/i18n/xliff2json.ts62
1 files changed, 41 insertions, 21 deletions
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}