From e945b184a0f29b47c33bbd05578f3493ca9c8e6c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 6 Jun 2018 14:23:40 +0200 Subject: Localize player --- scripts/i18n/xliff2json.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 scripts/i18n/xliff2json.ts (limited to 'scripts/i18n/xliff2json.ts') 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 @@ +import * as xliff12ToJs from 'xliff/xliff12ToJs' +import { readFileSync, writeFile } from 'fs' +import { join } from 'path' + +// First, the player +const playerSource = join(__dirname, '../../../client/src/locale/target/player_fr.xml') +const playerTarget = join(__dirname, '../../../client/src/locale/target/player_fr.json') + +// Remove the two first lines our xliff module does not like +let playerFile = readFileSync(playerSource).toString() +playerFile = removeFirstLine(playerFile) +playerFile = removeFirstLine(playerFile) + +xliff12ToJs(playerFile, (err, res) => { + if (err) { + console.error(err) + process.exit(-1) + } + + const json = createJSONString(res) + writeFile(playerTarget, json, err => { + if (err) { + console.error(err) + process.exit(-1) + } + + process.exit(0) + }) +}) + +function removeFirstLine (str: string) { + return str.substring(str.indexOf('\n') + 1) +} + +function createJSONString (obj: any) { + const res: any = {} + const strings = obj.resources[''] + + Object.keys(strings).forEach(k => res[k] = strings[k].target) + + return JSON.stringify(res) +} -- cgit v1.2.3