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/create-custom-files.ts | 49 +++++++++++++++++++++++++++++++++++++ scripts/i18n/generate.sh | 6 ++++- scripts/i18n/pull-hook.sh | 6 +++-- scripts/i18n/xliff2json.ts | 42 +++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 3 deletions(-) create mode 100755 scripts/i18n/create-custom-files.ts create mode 100755 scripts/i18n/xliff2json.ts (limited to 'scripts/i18n') diff --git a/scripts/i18n/create-custom-files.ts b/scripts/i18n/create-custom-files.ts new file mode 100755 index 000000000..3895b3b9d --- /dev/null +++ b/scripts/i18n/create-custom-files.ts @@ -0,0 +1,49 @@ +import * as jsToXliff12 from 'xliff/jsToXliff12' +import { writeFile } from 'fs' +import { join } from 'path' + +// First, the player +const playerSource = join(__dirname, '../../../client/src/locale/source/videojs_en_US.json') +const playerTarget = join(__dirname, '../../../client/src/locale/source/player_en_US.xml') + +const videojs = require(playerSource) +const playerKeys = { + 'Quality': 'Quality', + 'Auto': 'Auto', + 'Speed': 'Speed', + 'peers': 'peers', + 'Go to the video page': 'Go to the video page', + 'Settings': 'Settings', + 'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.', + 'Copy the video URL': 'Copy the video URL', + 'Copy the video URL at the current time': 'Copy the video URL at the current time', + 'Copy embed code': 'Copy embed code' +} + +const obj = { + resources: { + namespace1: {} + } +} + +for (const sourceObject of [ videojs, playerKeys ]) { + Object.keys(sourceObject).forEach(k => obj.resources.namespace1[ k ] = { source: sourceObject[ k ] }) +} + +jsToXliff12(obj, (err, res) => { + if (err) { + console.error(err) + process.exit(-1) + } + + writeFile(playerTarget, res, err => { + if (err) { + console.error(err) + process.exit(-1) + } + + process.exit(0) + }) +}) + +// Then, the server strings diff --git a/scripts/i18n/generate.sh b/scripts/i18n/generate.sh index f8ad8a3c1..0a5b6dee1 100755 --- a/scripts/i18n/generate.sh +++ b/scripts/i18n/generate.sh @@ -9,4 +9,8 @@ npm run ngx-extractor -- --locale "en-US" -i 'src/**/*.ts' -f xlf -o src/locale/ # Zanata does not support inner elements in , so we hack these special elements # This regex translate the Angular elements to special entities (that we will reconvert on pull) #sed -i 's//\<x id=\1\/\>/g' src/locale/source/messages_en_US.xml -perl -pi -e 's||<x id=\1/>|g' src/locale/source/messages_en_US.xml \ No newline at end of file +perl -pi -e 's||<x id=\1/>|g' src/locale/source/messages_en_US.xml + +# Add our strings too +cd ../ +npm run i18n:create-custom-files \ No newline at end of file diff --git a/scripts/i18n/pull-hook.sh b/scripts/i18n/pull-hook.sh index bbe4a813e..dec426b88 100755 --- a/scripts/i18n/pull-hook.sh +++ b/scripts/i18n/pull-hook.sh @@ -7,5 +7,7 @@ set -eu #sed -i 's/\<x id=\(.\+\?\)\/\>//g' client/src/locale/target/* for i in 1 2 3; do - perl -pi -e 's|<x id=(.+?)/>([^"])|\2|g' client/src/locale/target/* -done \ No newline at end of file + perl -pi -e 's|<x id=(.+?)/>([^"])|\2|g' client/src/locale/target/*.xml +done + +npm run i18n:xliff2json \ No newline at end of file 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