aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/i18n/xliff2json.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-06 14:23:40 +0200
committerChocobozzz <me@florianbigard.com>2018-06-06 16:48:40 +0200
commite945b184a0f29b47c33bbd05578f3493ca9c8e6c (patch)
tree46c821006d170e6e28658d978e313761adfaf55a /scripts/i18n/xliff2json.ts
parent550a562ceca45ea78d6f7054024c8d3a6b89c30c (diff)
downloadPeerTube-e945b184a0f29b47c33bbd05578f3493ca9c8e6c.tar.gz
PeerTube-e945b184a0f29b47c33bbd05578f3493ca9c8e6c.tar.zst
PeerTube-e945b184a0f29b47c33bbd05578f3493ca9c8e6c.zip
Localize player
Diffstat (limited to 'scripts/i18n/xliff2json.ts')
-rwxr-xr-xscripts/i18n/xliff2json.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/i18n/xliff2json.ts b/scripts/i18n/xliff2json.ts
new file mode 100755
index 000000000..34784ac11
--- /dev/null
+++ b/scripts/i18n/xliff2json.ts
@@ -0,0 +1,42 @@
1import * as xliff12ToJs from 'xliff/xliff12ToJs'
2import { readFileSync, writeFile } from 'fs'
3import { join } from 'path'
4
5// First, the player
6const playerSource = join(__dirname, '../../../client/src/locale/target/player_fr.xml')
7const playerTarget = join(__dirname, '../../../client/src/locale/target/player_fr.json')
8
9// Remove the two first lines our xliff module does not like
10let playerFile = readFileSync(playerSource).toString()
11playerFile = removeFirstLine(playerFile)
12playerFile = removeFirstLine(playerFile)
13
14xliff12ToJs(playerFile, (err, res) => {
15 if (err) {
16 console.error(err)
17 process.exit(-1)
18 }
19
20 const json = createJSONString(res)
21 writeFile(playerTarget, json, err => {
22 if (err) {
23 console.error(err)
24 process.exit(-1)
25 }
26
27 process.exit(0)
28 })
29})
30
31function removeFirstLine (str: string) {
32 return str.substring(str.indexOf('\n') + 1)
33}
34
35function createJSONString (obj: any) {
36 const res: any = {}
37 const strings = obj.resources['']
38
39 Object.keys(strings).forEach(k => res[k] = strings[k].target)
40
41 return JSON.stringify(res)
42}