diff options
author | Chocobozzz <me@florianbigard.com> | 2019-11-13 10:05:27 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-11-13 10:05:27 +0100 |
commit | a42294c5edbdea3075c8defc03ba2cb73e0d86fc (patch) | |
tree | aca95591d1fb7ed89dd5f05f81406b4a4f282bac /scripts | |
parent | f0c0c0abd88d0177f8be769f12d5affcacd934e8 (diff) | |
parent | 2ef1d2bb74f333b05bbbbd27282605ee5654061e (diff) | |
download | PeerTube-a42294c5edbdea3075c8defc03ba2cb73e0d86fc.tar.gz PeerTube-a42294c5edbdea3075c8defc03ba2cb73e0d86fc.tar.zst PeerTube-a42294c5edbdea3075c8defc03ba2cb73e0d86fc.zip |
Merge branch 'weblate' into develop
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/build/client.sh | 28 | ||||
-rwxr-xr-x | scripts/i18n/create-custom-files.ts | 73 | ||||
-rwxr-xr-x | scripts/i18n/generate.sh | 9 | ||||
-rwxr-xr-x | scripts/i18n/pull-hook.sh | 15 | ||||
-rwxr-xr-x | scripts/i18n/xliff2json.ts | 91 | ||||
-rwxr-xr-x | scripts/watch/server.sh | 2 |
6 files changed, 32 insertions, 186 deletions
diff --git a/scripts/build/client.sh b/scripts/build/client.sh index 9dfa6c618..2518702cf 100755 --- a/scripts/build/client.sh +++ b/scripts/build/client.sh | |||
@@ -3,23 +3,23 @@ | |||
3 | set -eu | 3 | set -eu |
4 | 4 | ||
5 | pre_build_hook () { | 5 | pre_build_hook () { |
6 | mkdir "./src/locale/pending_target/" > /dev/null || true | 6 | mkdir "./src/pending_locale" > /dev/null || true |
7 | mv ./src/locale/target/angular_*.xml "./src/locale/pending_target" | 7 | mv ./src/locale/angular.*.xlf "./src/pending_locale" |
8 | 8 | ||
9 | if [ ! -z ${1+x} ]; then | 9 | if [ ! -z ${1+x} ]; then |
10 | mv "./src/locale/pending_target/angular_$1.xml" "./src/locale/target" | 10 | mv "./src/pending_locale/angular.$1.xlf" "./src/locale" |
11 | fi | 11 | fi |
12 | } | 12 | } |
13 | 13 | ||
14 | post_build_hook () { | 14 | post_build_hook () { |
15 | mv ./src/locale/pending_target/* "./src/locale/target/" | 15 | mv ./src/pending_locale/* "./src/locale" |
16 | rmdir "./src/locale/pending_target/" | 16 | rmdir "./src/pending_locale/" |
17 | } | 17 | } |
18 | 18 | ||
19 | # Previous build failed | 19 | # Previous build failed |
20 | if [ ! -f client/src/locale/target/angular_fr_FR.xml ]; then | 20 | if [ ! -f "client/src/locale/angular.fr-FR.xlf" ]; then |
21 | git checkout -- client/src/locale/target/ | 21 | git checkout -- client/src/locale/ |
22 | rm -r client/src/locale/pending_target/ | 22 | rm -r client/src/pending_locale |
23 | fi | 23 | fi |
24 | 24 | ||
25 | cd client | 25 | cd client |
@@ -28,7 +28,7 @@ rm -rf ./dist ./compiled | |||
28 | 28 | ||
29 | pre_build_hook | 29 | pre_build_hook |
30 | 30 | ||
31 | defaultLanguage="en_US" | 31 | defaultLanguage="en-US" |
32 | npm run ng build -- --output-path "dist/$defaultLanguage/" --deploy-url "/client/$defaultLanguage/" --prod --stats-json | 32 | npm run ng build -- --output-path "dist/$defaultLanguage/" --deploy-url "/client/$defaultLanguage/" --prod --stats-json |
33 | mv "./dist/$defaultLanguage/assets" "./dist" | 33 | mv "./dist/$defaultLanguage/assets" "./dist" |
34 | mv "./dist/$defaultLanguage/manifest.webmanifest" "./dist/manifest.webmanifest" | 34 | mv "./dist/$defaultLanguage/manifest.webmanifest" "./dist/manifest.webmanifest" |
@@ -38,12 +38,12 @@ post_build_hook | |||
38 | # Don't build other languages if --light arg is provided | 38 | # Don't build other languages if --light arg is provided |
39 | if [ -z ${1+x} ] || [ "$1" != "--light" ]; then | 39 | if [ -z ${1+x} ] || [ "$1" != "--light" ]; then |
40 | if [ ! -z ${1+x} ] && [ "$1" == "--light-fr" ]; then | 40 | if [ ! -z ${1+x} ] && [ "$1" == "--light-fr" ]; then |
41 | languages=("fr_FR") | 41 | languages=("fr-FR") |
42 | else | 42 | else |
43 | # Supported languages | 43 | # Supported languages |
44 | languages=( | 44 | languages=( |
45 | "fi_FI" "nl_NL" "gd" "el_GR" "es_ES" "oc" "pt_BR" "pt_PT" "sv_SE" "pl_PL" "ru_RU" "zh_Hans_CN" "zh_Hant_TW" | 45 | "fi-FI" "nl-NL" "gd" "el-GR" "es-ES" "oc" "pt-BR" "pt-PT" "sv-SE" "pl-PL" "ru-RU" "zh-Hans-CN" "zh-Hant-TW" |
46 | "fr_FR" "ja_JP" "eu_ES" "ca_ES" "cs_CZ" "eo" "de_DE" "it_IT" | 46 | "fr-FR" "ja-JP" "eu-ES" "ca-ES" "cs-CZ" "eo" "de-DE" "it-IT" |
47 | ) | 47 | ) |
48 | fi | 48 | fi |
49 | 49 | ||
@@ -51,7 +51,7 @@ if [ -z ${1+x} ] || [ "$1" != "--light" ]; then | |||
51 | # TODO: remove when the project will use runtime translations | 51 | # TODO: remove when the project will use runtime translations |
52 | pre_build_hook "$lang" | 52 | pre_build_hook "$lang" |
53 | 53 | ||
54 | npm run ng build -- --prod --i18n-file "./src/locale/target/angular_$lang.xml" --i18n-format xlf --i18n-locale "$lang" \ | 54 | npm run ng build -- --prod --i18n-file "./src/locale/angular.$lang.xlf" --i18n-format xlf --i18n-locale "$lang" \ |
55 | --output-path "dist/$lang/" --deploy-url "/client/$lang/" | 55 | --output-path "dist/$lang/" --deploy-url "/client/$lang/" |
56 | 56 | ||
57 | # Do not duplicate assets | 57 | # Do not duplicate assets |
@@ -65,4 +65,4 @@ fi | |||
65 | NODE_ENV=production npm run webpack -- --config webpack/webpack.video-embed.js --mode production --json > "./dist/embed-stats.json" | 65 | NODE_ENV=production npm run webpack -- --config webpack/webpack.video-embed.js --mode production --json > "./dist/embed-stats.json" |
66 | 66 | ||
67 | # Copy runtime locales | 67 | # Copy runtime locales |
68 | cp -r "./src/locale/target" "./dist/locale" | 68 | cp -r "./src/locale" "./dist/locale" |
diff --git a/scripts/i18n/create-custom-files.ts b/scripts/i18n/create-custom-files.ts index e946b8fd6..47b3e3784 100755 --- a/scripts/i18n/create-custom-files.ts +++ b/scripts/i18n/create-custom-files.ts | |||
@@ -1,25 +1,21 @@ | |||
1 | import { registerTSPaths } from '../../server/helpers/register-ts-paths' | 1 | import { registerTSPaths } from '../../server/helpers/register-ts-paths' |
2 | registerTSPaths() | 2 | import { writeJSON } from 'fs-extra' |
3 | |||
4 | import * as jsToXliff12 from 'xliff/jsToXliff12' | ||
5 | import { writeFile } from 'fs-extra' | ||
6 | import { join } from 'path' | 3 | import { join } from 'path' |
7 | import { | 4 | import { |
8 | buildLanguages, | 5 | buildLanguages, |
9 | VIDEO_CATEGORIES, | 6 | VIDEO_CATEGORIES, |
10 | VIDEO_IMPORT_STATES, | 7 | VIDEO_IMPORT_STATES, |
11 | VIDEO_LICENCES, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES, | 8 | VIDEO_LICENCES, |
9 | VIDEO_PLAYLIST_PRIVACIES, | ||
10 | VIDEO_PLAYLIST_TYPES, | ||
12 | VIDEO_PRIVACIES, | 11 | VIDEO_PRIVACIES, |
13 | VIDEO_STATES | 12 | VIDEO_STATES |
14 | } from '../../server/initializers/constants' | 13 | } from '../../server/initializers/constants' |
15 | import { values } from 'lodash' | 14 | import { values } from 'lodash' |
16 | 15 | ||
17 | type TranslationType = { | 16 | registerTSPaths() |
18 | target: string | ||
19 | data: { [id: string]: string } | ||
20 | } | ||
21 | 17 | ||
22 | const videojs = require(join(__dirname, '../../../client/src/locale/source/videojs_en_US.json')) | 18 | const videojs = require(join(__dirname, '../../../client/src/locale/videojs.en-US.json')) |
23 | const playerKeys = { | 19 | const playerKeys = { |
24 | 'Quality': 'Quality', | 20 | 'Quality': 'Quality', |
25 | 'Auto': 'Auto', | 21 | 'Auto': 'Auto', |
@@ -37,10 +33,7 @@ const playerKeys = { | |||
37 | 'Total downloaded: ': 'Total downloaded: ', | 33 | 'Total downloaded: ': 'Total downloaded: ', |
38 | 'Total uploaded: ': 'Total uploaded: ' | 34 | 'Total uploaded: ': 'Total uploaded: ' |
39 | } | 35 | } |
40 | const playerTranslations = { | 36 | Object.assign(playerKeys, videojs) |
41 | target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'), | ||
42 | data: Object.assign({}, videojs, playerKeys) | ||
43 | } | ||
44 | 37 | ||
45 | // Server keys | 38 | // Server keys |
46 | const serverKeys: any = {} | 39 | const serverKeys: any = {} |
@@ -65,57 +58,17 @@ Object.assign(serverKeys, { | |||
65 | 'Unknown': 'Unknown' | 58 | 'Unknown': 'Unknown' |
66 | }) | 59 | }) |
67 | 60 | ||
68 | const serverTranslations = { | ||
69 | target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'), | ||
70 | data: serverKeys | ||
71 | } | ||
72 | |||
73 | // ISO 639 keys | 61 | // ISO 639 keys |
74 | const languageKeys: any = {} | 62 | const languageKeys: any = {} |
75 | const languages = buildLanguages() | 63 | const languages = buildLanguages() |
76 | Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k]) | 64 | Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k]) |
77 | 65 | ||
78 | const iso639Translations = { | 66 | Object.assign(serverKeys, languageKeys) |
79 | target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'), | ||
80 | data: languageKeys | ||
81 | } | ||
82 | |||
83 | saveToXliffFile(playerTranslations, err => { | ||
84 | if (err) return handleError(err) | ||
85 | |||
86 | saveToXliffFile(serverTranslations, err => { | ||
87 | if (err) return handleError(err) | ||
88 | |||
89 | saveToXliffFile(iso639Translations, err => { | ||
90 | if (err) return handleError(err) | ||
91 | 67 | ||
92 | process.exit(0) | 68 | Promise.all([ |
93 | }) | 69 | writeJSON(join(__dirname, '../../../client/src/locale/player.en-US.json'), playerKeys), |
94 | }) | 70 | writeJSON(join(__dirname, '../../../client/src/locale/server.en-US.json'), serverKeys) |
95 | }) | 71 | ]).catch(err => { |
96 | |||
97 | // Then, the server strings | ||
98 | |||
99 | function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) { | ||
100 | const obj = { | ||
101 | resources: { | ||
102 | namespace1: {} | ||
103 | } | ||
104 | } | ||
105 | Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] }) | ||
106 | |||
107 | jsToXliff12(obj, (err, res) => { | ||
108 | if (err) return cb(err) | ||
109 | |||
110 | writeFile(jsonTranslations.target, res, err => { | ||
111 | if (err) return cb(err) | ||
112 | |||
113 | return cb(null) | ||
114 | }) | ||
115 | }) | ||
116 | } | ||
117 | |||
118 | function handleError (err: any) { | ||
119 | console.error(err) | 72 | console.error(err) |
120 | process.exit(-1) | 73 | process.exit(-1) |
121 | } | 74 | }) |
diff --git a/scripts/i18n/generate.sh b/scripts/i18n/generate.sh index 3f3e3d8e5..f9c2f0613 100755 --- a/scripts/i18n/generate.sh +++ b/scripts/i18n/generate.sh | |||
@@ -3,12 +3,11 @@ | |||
3 | set -eu | 3 | set -eu |
4 | 4 | ||
5 | cd client | 5 | cd client |
6 | npm run ng -- xi18n --i18n-locale "en-US" --output-path src/locale/source --out-file angular_en_US.xml | 6 | npm run ng -- xi18n --i18n-locale "en-US" --output-path src/locale --out-file angular.xlf |
7 | npm run ngx-extractor -- --locale "en-US" -i 'src/**/*.ts' -f xlf -o src/locale/source/angular_en_US.xml | 7 | npm run ngx-extractor -- --locale "en-US" -i 'src/**/*.ts' -f xlf -o src/locale/angular.xlf |
8 | 8 | ||
9 | # Zanata does not support inner elements in <source>, so we hack these special elements | 9 | # Merge new translations in other language files |
10 | # This regex translate the Angular elements to special entities (that we will reconvert on pull) | 10 | npm run ng run -- PeerTube:xliffmerge |
11 | perl -pi -e 's|<x id=(.+?)/>|<x id=\1/>|g' src/locale/source/angular_en_US.xml | ||
12 | 11 | ||
13 | # Add our strings too | 12 | # Add our strings too |
14 | cd ../ | 13 | cd ../ |
diff --git a/scripts/i18n/pull-hook.sh b/scripts/i18n/pull-hook.sh deleted file mode 100755 index 8d1f7ee55..000000000 --- a/scripts/i18n/pull-hook.sh +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | set -eu | ||
4 | |||
5 | for i in $(seq 1 10); do | ||
6 | # Angular does not like when there is not target element, so we create it with the same content than the source element | ||
7 | perl -0pi -e 's#<source>([^<]+)</source>\s*<context-group #<source>\1</source><target>\1</target><context-group #g' client/src/locale/target/angular_*.xml | ||
8 | |||
9 | # Zanata does not support inner elements in <source>, so we hack these special elements | ||
10 | # This regex translate the converted elements to initial Angular elements | ||
11 | perl -pi -e 's|<x id=(.+?)/>([^"])|<x id=\1/>\2|g' client/src/locale/target/*.xml | ||
12 | done | ||
13 | |||
14 | npm run i18n:xliff2json | ||
15 | |||
diff --git a/scripts/i18n/xliff2json.ts b/scripts/i18n/xliff2json.ts deleted file mode 100755 index 68fc95f34..000000000 --- a/scripts/i18n/xliff2json.ts +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | import { registerTSPaths } from '../../server/helpers/register-ts-paths' | ||
2 | registerTSPaths() | ||
3 | |||
4 | import * as xliff12ToJs from 'xliff/xliff12ToJs' | ||
5 | import { readFileSync, unlink, writeFile } from 'fs-extra' | ||
6 | import { join } from 'path' | ||
7 | import { buildFileLocale, I18N_LOCALES, isDefaultLocale } from '../../shared/models/i18n/i18n' | ||
8 | import { eachSeries } from 'async' | ||
9 | |||
10 | const sources: string[] = [] | ||
11 | const availableLocales = Object.keys(I18N_LOCALES) | ||
12 | .filter(l => isDefaultLocale(l) === false) | ||
13 | .map(l => buildFileLocale(l)) | ||
14 | |||
15 | for (const file of [ 'player', 'server', 'iso639' ]) { | ||
16 | for (const locale of availableLocales) { | ||
17 | sources.push(join(__dirname, '../../../client/src/locale/target/', `${file}_${locale}.xml`)) | ||
18 | } | ||
19 | } | ||
20 | |||
21 | eachSeries(sources, (source, cb) => { | ||
22 | xliffFile2JSON(source, cb) | ||
23 | }, err => { | ||
24 | if (err) return handleError(err) | ||
25 | |||
26 | mergeISO639InServer(err => { | ||
27 | if (err) return handleError(err) | ||
28 | |||
29 | process.exit(0) | ||
30 | }) | ||
31 | }) | ||
32 | |||
33 | function handleError (err: any) { | ||
34 | console.error(err) | ||
35 | process.exit(-1) | ||
36 | } | ||
37 | |||
38 | function xliffFile2JSON (filePath: string, cb) { | ||
39 | const fileTarget = filePath.replace('.xml', '.json') | ||
40 | |||
41 | // Remove the two first lines our xliff module does not like | ||
42 | let fileContent = readFileSync(filePath).toString() | ||
43 | fileContent = removeFirstLine(fileContent) | ||
44 | fileContent = removeFirstLine(fileContent) | ||
45 | |||
46 | xliff12ToJs(fileContent, (err, res) => { | ||
47 | if (err) return cb(err) | ||
48 | |||
49 | const json = createJSONString(res) | ||
50 | writeFile(fileTarget, json, err => { | ||
51 | if (err) return cb(err) | ||
52 | |||
53 | return unlink(filePath, cb) | ||
54 | }) | ||
55 | }) | ||
56 | } | ||
57 | |||
58 | function mergeISO639InServer (cb) { | ||
59 | eachSeries(availableLocales, (locale, eachCallback) => { | ||
60 | const serverPath = join(__dirname, '../../../client/src/locale/target/', `server_${locale}.json`) | ||
61 | const iso639Path = join(__dirname, '../../../client/src/locale/target/', `iso639_${locale}.json`) | ||
62 | |||
63 | const resServer = readFileSync(serverPath).toString() | ||
64 | const resISO639 = readFileSync(iso639Path).toString() | ||
65 | |||
66 | const jsonServer = JSON.parse(resServer) | ||
67 | const jsonISO639 = JSON.parse(resISO639) | ||
68 | |||
69 | Object.assign(jsonServer, jsonISO639) | ||
70 | const serverString = JSON.stringify(jsonServer) | ||
71 | |||
72 | writeFile(serverPath, serverString, err => { | ||
73 | if (err) return eachCallback(err) | ||
74 | |||
75 | return unlink(iso639Path, eachCallback) | ||
76 | }) | ||
77 | }, cb) | ||
78 | } | ||
79 | |||
80 | function removeFirstLine (str: string) { | ||
81 | return str.substring(str.indexOf('\n') + 1) | ||
82 | } | ||
83 | |||
84 | function createJSONString (obj: any) { | ||
85 | const res: any = {} | ||
86 | const strings = obj.resources[''] | ||
87 | |||
88 | Object.keys(strings).forEach(k => res[k] = strings[k].target) | ||
89 | |||
90 | return JSON.stringify(res) | ||
91 | } | ||
diff --git a/scripts/watch/server.sh b/scripts/watch/server.sh index 635bebf8e..8d8470954 100755 --- a/scripts/watch/server.sh +++ b/scripts/watch/server.sh | |||
@@ -5,7 +5,7 @@ set -eu | |||
5 | # Copy locales | 5 | # Copy locales |
6 | mkdir -p "./client/dist" | 6 | mkdir -p "./client/dist" |
7 | rm -rf "./client/dist/locale" | 7 | rm -rf "./client/dist/locale" |
8 | cp -r "./client/src/locale/target" "./client/dist/locale" | 8 | cp -r "./client/src/locale" "./client/dist/locale" |
9 | 9 | ||
10 | rm -rf "./dist" | 10 | rm -rf "./dist" |
11 | 11 | ||