diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-06 14:23:40 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-06 16:48:40 +0200 |
commit | e945b184a0f29b47c33bbd05578f3493ca9c8e6c (patch) | |
tree | 46c821006d170e6e28658d978e313761adfaf55a /scripts/i18n | |
parent | 550a562ceca45ea78d6f7054024c8d3a6b89c30c (diff) | |
download | PeerTube-e945b184a0f29b47c33bbd05578f3493ca9c8e6c.tar.gz PeerTube-e945b184a0f29b47c33bbd05578f3493ca9c8e6c.tar.zst PeerTube-e945b184a0f29b47c33bbd05578f3493ca9c8e6c.zip |
Localize player
Diffstat (limited to 'scripts/i18n')
-rwxr-xr-x | scripts/i18n/create-custom-files.ts | 49 | ||||
-rwxr-xr-x | scripts/i18n/generate.sh | 6 | ||||
-rwxr-xr-x | scripts/i18n/pull-hook.sh | 6 | ||||
-rwxr-xr-x | scripts/i18n/xliff2json.ts | 42 |
4 files changed, 100 insertions, 3 deletions
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 @@ | |||
1 | import * as jsToXliff12 from 'xliff/jsToXliff12' | ||
2 | import { writeFile } from 'fs' | ||
3 | import { join } from 'path' | ||
4 | |||
5 | // First, the player | ||
6 | const playerSource = join(__dirname, '../../../client/src/locale/source/videojs_en_US.json') | ||
7 | const playerTarget = join(__dirname, '../../../client/src/locale/source/player_en_US.xml') | ||
8 | |||
9 | const videojs = require(playerSource) | ||
10 | const playerKeys = { | ||
11 | 'Quality': 'Quality', | ||
12 | 'Auto': 'Auto', | ||
13 | 'Speed': 'Speed', | ||
14 | 'peers': 'peers', | ||
15 | 'Go to the video page': 'Go to the video page', | ||
16 | 'Settings': 'Settings', | ||
17 | 'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.', | ||
18 | 'Copy the video URL': 'Copy the video URL', | ||
19 | 'Copy the video URL at the current time': 'Copy the video URL at the current time', | ||
20 | 'Copy embed code': 'Copy embed code' | ||
21 | } | ||
22 | |||
23 | const obj = { | ||
24 | resources: { | ||
25 | namespace1: {} | ||
26 | } | ||
27 | } | ||
28 | |||
29 | for (const sourceObject of [ videojs, playerKeys ]) { | ||
30 | Object.keys(sourceObject).forEach(k => obj.resources.namespace1[ k ] = { source: sourceObject[ k ] }) | ||
31 | } | ||
32 | |||
33 | jsToXliff12(obj, (err, res) => { | ||
34 | if (err) { | ||
35 | console.error(err) | ||
36 | process.exit(-1) | ||
37 | } | ||
38 | |||
39 | writeFile(playerTarget, res, err => { | ||
40 | if (err) { | ||
41 | console.error(err) | ||
42 | process.exit(-1) | ||
43 | } | ||
44 | |||
45 | process.exit(0) | ||
46 | }) | ||
47 | }) | ||
48 | |||
49 | // 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/ | |||
9 | # Zanata does not support inner elements in <source>, so we hack these special elements | 9 | # Zanata does not support inner elements in <source>, so we hack these special elements |
10 | # This regex translate the Angular elements to special entities (that we will reconvert on pull) | 10 | # This regex translate the Angular elements to special entities (that we will reconvert on pull) |
11 | #sed -i 's/<x id=\(.\+\?\)\/>/\<x id=\1\/\>/g' src/locale/source/messages_en_US.xml | 11 | #sed -i 's/<x id=\(.\+\?\)\/>/\<x id=\1\/\>/g' src/locale/source/messages_en_US.xml |
12 | perl -pi -e 's|<x id=(.+?)/>|<x id=\1/>|g' src/locale/source/messages_en_US.xml \ No newline at end of file | 12 | perl -pi -e 's|<x id=(.+?)/>|<x id=\1/>|g' src/locale/source/messages_en_US.xml |
13 | |||
14 | # Add our strings too | ||
15 | cd ../ | ||
16 | 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 | |||
7 | #sed -i 's/\<x id=\(.\+\?\)\/\>/<x id=\1\/>/g' client/src/locale/target/* | 7 | #sed -i 's/\<x id=\(.\+\?\)\/\>/<x id=\1\/>/g' client/src/locale/target/* |
8 | 8 | ||
9 | for i in 1 2 3; do | 9 | for i in 1 2 3; do |
10 | perl -pi -e 's|<x id=(.+?)/>([^"])|<x id=\1/>\2|g' client/src/locale/target/* | 10 | perl -pi -e 's|<x id=(.+?)/>([^"])|<x id=\1/>\2|g' client/src/locale/target/*.xml |
11 | done \ No newline at end of file | 11 | done |
12 | |||
13 | 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 @@ | |||
1 | import * as xliff12ToJs from 'xliff/xliff12ToJs' | ||
2 | import { readFileSync, writeFile } from 'fs' | ||
3 | import { join } from 'path' | ||
4 | |||
5 | // First, the player | ||
6 | const playerSource = join(__dirname, '../../../client/src/locale/target/player_fr.xml') | ||
7 | const playerTarget = join(__dirname, '../../../client/src/locale/target/player_fr.json') | ||
8 | |||
9 | // Remove the two first lines our xliff module does not like | ||
10 | let playerFile = readFileSync(playerSource).toString() | ||
11 | playerFile = removeFirstLine(playerFile) | ||
12 | playerFile = removeFirstLine(playerFile) | ||
13 | |||
14 | xliff12ToJs(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 | |||
31 | function removeFirstLine (str: string) { | ||
32 | return str.substring(str.indexOf('\n') + 1) | ||
33 | } | ||
34 | |||
35 | function 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 | } | ||