From 3aea8eb2e7ee8fa53e05298030eaeef98d234797 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 7 Nov 2019 09:45:14 +0100 Subject: Try new worflow with french --- scripts/i18n/create-custom-files.ts | 73 +++++++------------------------------ scripts/i18n/generate.sh | 9 ++--- scripts/i18n/pull-hook.sh | 9 ----- 3 files changed, 17 insertions(+), 74 deletions(-) (limited to 'scripts') 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 @@ import { registerTSPaths } from '../../server/helpers/register-ts-paths' -registerTSPaths() - -import * as jsToXliff12 from 'xliff/jsToXliff12' -import { writeFile } from 'fs-extra' +import { writeJSON } from 'fs-extra' import { join } from 'path' import { buildLanguages, VIDEO_CATEGORIES, VIDEO_IMPORT_STATES, - VIDEO_LICENCES, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES, + VIDEO_LICENCES, + VIDEO_PLAYLIST_PRIVACIES, + VIDEO_PLAYLIST_TYPES, VIDEO_PRIVACIES, VIDEO_STATES } from '../../server/initializers/constants' import { values } from 'lodash' -type TranslationType = { - target: string - data: { [id: string]: string } -} +registerTSPaths() -const videojs = require(join(__dirname, '../../../client/src/locale/source/videojs_en_US.json')) +const videojs = require(join(__dirname, '../../../client/src/locale/videojs.en-US.json')) const playerKeys = { 'Quality': 'Quality', 'Auto': 'Auto', @@ -37,10 +33,7 @@ const playerKeys = { 'Total downloaded: ': 'Total downloaded: ', 'Total uploaded: ': 'Total uploaded: ' } -const playerTranslations = { - target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'), - data: Object.assign({}, videojs, playerKeys) -} +Object.assign(playerKeys, videojs) // Server keys const serverKeys: any = {} @@ -65,57 +58,17 @@ Object.assign(serverKeys, { 'Unknown': 'Unknown' }) -const serverTranslations = { - target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'), - data: serverKeys -} - // ISO 639 keys const languageKeys: any = {} const languages = buildLanguages() Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k]) -const iso639Translations = { - target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'), - data: languageKeys -} - -saveToXliffFile(playerTranslations, err => { - if (err) return handleError(err) - - saveToXliffFile(serverTranslations, err => { - if (err) return handleError(err) - - saveToXliffFile(iso639Translations, err => { - if (err) return handleError(err) +Object.assign(serverKeys, languageKeys) - process.exit(0) - }) - }) -}) - -// Then, the server strings - -function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) { - const obj = { - resources: { - namespace1: {} - } - } - Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] }) - - jsToXliff12(obj, (err, res) => { - if (err) return cb(err) - - writeFile(jsonTranslations.target, res, err => { - if (err) return cb(err) - - return cb(null) - }) - }) -} - -function handleError (err: any) { +Promise.all([ + writeJSON(join(__dirname, '../../../client/src/locale/player.en-US.json'), playerKeys), + writeJSON(join(__dirname, '../../../client/src/locale/server.en-US.json'), serverKeys) +]).catch(err => { console.error(err) process.exit(-1) -} +}) 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 @@ set -eu cd client -npm run ng -- xi18n --i18n-locale "en-US" --output-path src/locale/source --out-file angular_en_US.xml -npm run ngx-extractor -- --locale "en-US" -i 'src/**/*.ts' -f xlf -o src/locale/source/angular_en_US.xml +npm run ng -- xi18n --i18n-locale "en-US" --output-path src/locale --out-file angular.xlf +npm run ngx-extractor -- --locale "en-US" -i 'src/**/*.ts' -f xlf -o src/locale/angular.xlf -# 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) -perl -pi -e 's||<x id=\1/>|g' src/locale/source/angular_en_US.xml +# Merge new translations in other language files +npm run ng run -- PeerTube:xliffmerge # Add our strings too cd ../ diff --git a/scripts/i18n/pull-hook.sh b/scripts/i18n/pull-hook.sh index 8d1f7ee55..738469e38 100755 --- a/scripts/i18n/pull-hook.sh +++ b/scripts/i18n/pull-hook.sh @@ -2,14 +2,5 @@ set -eu -for i in $(seq 1 10); do - # Angular does not like when there is not target element, so we create it with the same content than the source element - perl -0pi -e 's#([^<]+)\s*\1\1, so we hack these special elements - # This regex translate the converted elements to initial Angular elements - perl -pi -e 's|<x id=(.+?)/>([^"])|\2|g' client/src/locale/target/*.xml -done - npm run i18n:xliff2json -- cgit v1.2.3 From ad912c3de64939cc2cd128ec45a4b32cb548f8d1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 7 Nov 2019 12:00:09 +0100 Subject: Update server and player --- scripts/i18n/xliff2json.ts | 96 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/i18n/xliff2json.ts b/scripts/i18n/xliff2json.ts index 68fc95f34..d15039bb9 100755 --- a/scripts/i18n/xliff2json.ts +++ b/scripts/i18n/xliff2json.ts @@ -2,14 +2,55 @@ import { registerTSPaths } from '../../server/helpers/register-ts-paths' registerTSPaths() import * as xliff12ToJs from 'xliff/xliff12ToJs' -import { readFileSync, unlink, writeFile } from 'fs-extra' +import { readFileSync, readJSON, unlink, writeFile, writeJSON, existsSync, exists, pathExists } from 'fs-extra' import { join } from 'path' import { buildFileLocale, I18N_LOCALES, isDefaultLocale } from '../../shared/models/i18n/i18n' import { eachSeries } from 'async' const sources: string[] = [] -const availableLocales = Object.keys(I18N_LOCALES) - .filter(l => isDefaultLocale(l) === false) +const l = [ + 'ar-001', + 'ca-ES', + 'cs-CZ', + 'da-DK', + 'de-DE', + 'el-GR', + 'en-GB', + 'en-US', + 'eo', + 'es-ES', + 'eu-ES', + 'fa-IR', + 'fi-FI', + 'fr-FR', + 'gd', + 'gl-ES', + 'hu-HU', + 'it-IT', + 'ja-JP', + 'jbo', + 'ko-KR', + 'lt-LT', + 'nb-NO', + 'nl-NL', + 'oc', + 'pl-PL', + 'pt-BR', + 'pt-PT', + 'ru-RU', + 'sk-SK', + 'sl-SI', + 'sv-SE', + 'ta', + 'th-TH', + 'tr-TR', + 'uk-UA', + 'vi-VN', + 'zh-Hans-CN', + 'zh-Hant-TW' +] + +const availableLocales = l.filter(l => isDefaultLocale(l) === false) .map(l => buildFileLocale(l)) for (const file of [ 'player', 'server', 'iso639' ]) { @@ -26,7 +67,7 @@ eachSeries(sources, (source, cb) => { mergeISO639InServer(err => { if (err) return handleError(err) - process.exit(0) + injectMissingTranslations().then(() => process.exit(0)) }) }) @@ -38,6 +79,11 @@ function handleError (err: any) { function xliffFile2JSON (filePath: string, cb) { const fileTarget = filePath.replace('.xml', '.json') + if (!existsSync(filePath)) { + console.log('No file %s exists.', filePath) + return cb() + } + // Remove the two first lines our xliff module does not like let fileContent = readFileSync(filePath).toString() fileContent = removeFirstLine(fileContent) @@ -60,6 +106,15 @@ function mergeISO639InServer (cb) { const serverPath = join(__dirname, '../../../client/src/locale/target/', `server_${locale}.json`) const iso639Path = join(__dirname, '../../../client/src/locale/target/', `iso639_${locale}.json`) + if (!existsSync(serverPath)) { + console.log('No file %s exists.', serverPath) + return cb() + } + if (!existsSync(iso639Path)) { + console.log('No file %s exists.', iso639Path) + return cb() + } + const resServer = readFileSync(serverPath).toString() const resISO639 = readFileSync(iso639Path).toString() @@ -89,3 +144,36 @@ function createJSONString (obj: any) { return JSON.stringify(res) } + +async function injectMissingTranslations () { + const baseServer = await readJSON(join(__dirname, '../../../client/src/locale/server.en-US.json')) + Object.keys(baseServer).forEach(k => baseServer[k] = '') + + for (const locale of availableLocales) { + const serverPath = join(__dirname, '../../../client/src/locale/target/', `server_${locale}.json`) + if (!await pathExists(serverPath)) { + console.log('No file exists to inject missing translations: %s.', serverPath) + continue + } + + let serverJSON = await readJSON(serverPath) + + serverJSON = Object.assign({}, baseServer, serverJSON) + await writeJSON(serverPath, serverJSON) + } + + const basePlayer = await readJSON(join(__dirname, '../../../client/src/locale/player.en-US.json')) + Object.keys(basePlayer).forEach(k => basePlayer[k] = '') + for (const locale of availableLocales) { + const serverPath = join(__dirname, '../../../client/src/locale/target/', `player_${locale}.json`) + if (!await pathExists(serverPath)) { + console.log('No file exists to inject missing translations: %s.', serverPath) + continue + } + + let serverJSON = await readJSON(serverPath) + + serverJSON = Object.assign({}, basePlayer, serverJSON) + await writeJSON(serverPath, serverJSON) + } +} -- cgit v1.2.3 From 24b1c65abd6fa84b2e21bc2cb87c0b3006120787 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 7 Nov 2019 14:12:57 +0100 Subject: Remove html tags --- scripts/i18n/pull-hook.sh | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'scripts') diff --git a/scripts/i18n/pull-hook.sh b/scripts/i18n/pull-hook.sh index 738469e38..66f3b4588 100755 --- a/scripts/i18n/pull-hook.sh +++ b/scripts/i18n/pull-hook.sh @@ -2,5 +2,11 @@ set -eu +for i in $(seq 1 10); do + # Zanata does not support inner elements in , so we hack these special elements + # This regex translate the converted elements to initial Angular elements + perl -pi -e 's|<x id=(.+?)/>([^"])|\2|g' client/src/locale/target/*.xml +done + npm run i18n:xliff2json -- cgit v1.2.3 From 350131cbaf99bd1cbb2d0911093aa94d105de709 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 7 Nov 2019 15:33:23 +0100 Subject: Make build works --- scripts/build/client.sh | 28 ++++++++++++++-------------- scripts/watch/server.sh | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'scripts') 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 @@ set -eu pre_build_hook () { - mkdir "./src/locale/pending_target/" > /dev/null || true - mv ./src/locale/target/angular_*.xml "./src/locale/pending_target" + mkdir "./src/pending_locale" > /dev/null || true + mv ./src/locale/angular.*.xlf "./src/pending_locale" if [ ! -z ${1+x} ]; then - mv "./src/locale/pending_target/angular_$1.xml" "./src/locale/target" + mv "./src/pending_locale/angular.$1.xlf" "./src/locale" fi } post_build_hook () { - mv ./src/locale/pending_target/* "./src/locale/target/" - rmdir "./src/locale/pending_target/" + mv ./src/pending_locale/* "./src/locale" + rmdir "./src/pending_locale/" } # Previous build failed -if [ ! -f client/src/locale/target/angular_fr_FR.xml ]; then - git checkout -- client/src/locale/target/ - rm -r client/src/locale/pending_target/ +if [ ! -f "client/src/locale/angular.fr-FR.xlf" ]; then + git checkout -- client/src/locale/ + rm -r client/src/pending_locale fi cd client @@ -28,7 +28,7 @@ rm -rf ./dist ./compiled pre_build_hook -defaultLanguage="en_US" +defaultLanguage="en-US" npm run ng build -- --output-path "dist/$defaultLanguage/" --deploy-url "/client/$defaultLanguage/" --prod --stats-json mv "./dist/$defaultLanguage/assets" "./dist" mv "./dist/$defaultLanguage/manifest.webmanifest" "./dist/manifest.webmanifest" @@ -38,12 +38,12 @@ post_build_hook # Don't build other languages if --light arg is provided if [ -z ${1+x} ] || [ "$1" != "--light" ]; then if [ ! -z ${1+x} ] && [ "$1" == "--light-fr" ]; then - languages=("fr_FR") + languages=("fr-FR") else # Supported languages languages=( - "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" - "fr_FR" "ja_JP" "eu_ES" "ca_ES" "cs_CZ" "eo" "de_DE" "it_IT" + "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" + "fr-FR" "ja-JP" "eu-ES" "ca-ES" "cs-CZ" "eo" "de-DE" "it-IT" ) fi @@ -51,7 +51,7 @@ if [ -z ${1+x} ] || [ "$1" != "--light" ]; then # TODO: remove when the project will use runtime translations pre_build_hook "$lang" - npm run ng build -- --prod --i18n-file "./src/locale/target/angular_$lang.xml" --i18n-format xlf --i18n-locale "$lang" \ + npm run ng build -- --prod --i18n-file "./src/locale/angular.$lang.xlf" --i18n-format xlf --i18n-locale "$lang" \ --output-path "dist/$lang/" --deploy-url "/client/$lang/" # Do not duplicate assets @@ -65,4 +65,4 @@ fi NODE_ENV=production npm run webpack -- --config webpack/webpack.video-embed.js --mode production --json > "./dist/embed-stats.json" # Copy runtime locales -cp -r "./src/locale/target" "./dist/locale" +cp -r "./src/locale" "./dist/locale" 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 # Copy locales mkdir -p "./client/dist" rm -rf "./client/dist/locale" -cp -r "./client/src/locale/target" "./client/dist/locale" +cp -r "./client/src/locale" "./client/dist/locale" rm -rf "./dist" -- cgit v1.2.3 From cd1d6c23dae0fd08e69d49b21333742db86eeff7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 13 Nov 2019 09:45:27 +0100 Subject: Remove unused files --- scripts/i18n/pull-hook.sh | 12 --- scripts/i18n/xliff2json.ts | 179 --------------------------------------------- 2 files changed, 191 deletions(-) delete mode 100755 scripts/i18n/pull-hook.sh delete mode 100755 scripts/i18n/xliff2json.ts (limited to 'scripts') diff --git a/scripts/i18n/pull-hook.sh b/scripts/i18n/pull-hook.sh deleted file mode 100755 index 66f3b4588..000000000 --- a/scripts/i18n/pull-hook.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -set -eu - -for i in $(seq 1 10); do - # Zanata does not support inner elements in , so we hack these special elements - # This regex translate the converted elements to initial Angular elements - perl -pi -e 's|<x id=(.+?)/>([^"])|\2|g' client/src/locale/target/*.xml -done - -npm run i18n:xliff2json - diff --git a/scripts/i18n/xliff2json.ts b/scripts/i18n/xliff2json.ts deleted file mode 100755 index d15039bb9..000000000 --- a/scripts/i18n/xliff2json.ts +++ /dev/null @@ -1,179 +0,0 @@ -import { registerTSPaths } from '../../server/helpers/register-ts-paths' -registerTSPaths() - -import * as xliff12ToJs from 'xliff/xliff12ToJs' -import { readFileSync, readJSON, unlink, writeFile, writeJSON, existsSync, exists, pathExists } from 'fs-extra' -import { join } from 'path' -import { buildFileLocale, I18N_LOCALES, isDefaultLocale } from '../../shared/models/i18n/i18n' -import { eachSeries } from 'async' - -const sources: string[] = [] -const l = [ - 'ar-001', - 'ca-ES', - 'cs-CZ', - 'da-DK', - 'de-DE', - 'el-GR', - 'en-GB', - 'en-US', - 'eo', - 'es-ES', - 'eu-ES', - 'fa-IR', - 'fi-FI', - 'fr-FR', - 'gd', - 'gl-ES', - 'hu-HU', - 'it-IT', - 'ja-JP', - 'jbo', - 'ko-KR', - 'lt-LT', - 'nb-NO', - 'nl-NL', - 'oc', - 'pl-PL', - 'pt-BR', - 'pt-PT', - 'ru-RU', - 'sk-SK', - 'sl-SI', - 'sv-SE', - 'ta', - 'th-TH', - 'tr-TR', - 'uk-UA', - 'vi-VN', - 'zh-Hans-CN', - 'zh-Hant-TW' -] - -const availableLocales = l.filter(l => isDefaultLocale(l) === false) - .map(l => buildFileLocale(l)) - -for (const file of [ 'player', 'server', 'iso639' ]) { - for (const locale of availableLocales) { - sources.push(join(__dirname, '../../../client/src/locale/target/', `${file}_${locale}.xml`)) - } -} - -eachSeries(sources, (source, cb) => { - xliffFile2JSON(source, cb) -}, err => { - if (err) return handleError(err) - - mergeISO639InServer(err => { - if (err) return handleError(err) - - injectMissingTranslations().then(() => process.exit(0)) - }) -}) - -function handleError (err: any) { - console.error(err) - process.exit(-1) -} - -function xliffFile2JSON (filePath: string, cb) { - const fileTarget = filePath.replace('.xml', '.json') - - if (!existsSync(filePath)) { - console.log('No file %s exists.', filePath) - return cb() - } - - // Remove the two first lines our xliff module does not like - let fileContent = readFileSync(filePath).toString() - fileContent = removeFirstLine(fileContent) - fileContent = removeFirstLine(fileContent) - - xliff12ToJs(fileContent, (err, res) => { - if (err) return cb(err) - - const json = createJSONString(res) - writeFile(fileTarget, json, err => { - if (err) return cb(err) - - return unlink(filePath, cb) - }) - }) -} - -function mergeISO639InServer (cb) { - eachSeries(availableLocales, (locale, eachCallback) => { - const serverPath = join(__dirname, '../../../client/src/locale/target/', `server_${locale}.json`) - const iso639Path = join(__dirname, '../../../client/src/locale/target/', `iso639_${locale}.json`) - - if (!existsSync(serverPath)) { - console.log('No file %s exists.', serverPath) - return cb() - } - if (!existsSync(iso639Path)) { - console.log('No file %s exists.', iso639Path) - return cb() - } - - const resServer = readFileSync(serverPath).toString() - const resISO639 = readFileSync(iso639Path).toString() - - const jsonServer = JSON.parse(resServer) - const jsonISO639 = JSON.parse(resISO639) - - Object.assign(jsonServer, jsonISO639) - const serverString = JSON.stringify(jsonServer) - - writeFile(serverPath, serverString, err => { - if (err) return eachCallback(err) - - return unlink(iso639Path, eachCallback) - }) - }, cb) -} - -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) -} - -async function injectMissingTranslations () { - const baseServer = await readJSON(join(__dirname, '../../../client/src/locale/server.en-US.json')) - Object.keys(baseServer).forEach(k => baseServer[k] = '') - - for (const locale of availableLocales) { - const serverPath = join(__dirname, '../../../client/src/locale/target/', `server_${locale}.json`) - if (!await pathExists(serverPath)) { - console.log('No file exists to inject missing translations: %s.', serverPath) - continue - } - - let serverJSON = await readJSON(serverPath) - - serverJSON = Object.assign({}, baseServer, serverJSON) - await writeJSON(serverPath, serverJSON) - } - - const basePlayer = await readJSON(join(__dirname, '../../../client/src/locale/player.en-US.json')) - Object.keys(basePlayer).forEach(k => basePlayer[k] = '') - for (const locale of availableLocales) { - const serverPath = join(__dirname, '../../../client/src/locale/target/', `player_${locale}.json`) - if (!await pathExists(serverPath)) { - console.log('No file exists to inject missing translations: %s.', serverPath) - continue - } - - let serverJSON = await readJSON(serverPath) - - serverJSON = Object.assign({}, basePlayer, serverJSON) - await writeJSON(serverPath, serverJSON) - } -} -- cgit v1.2.3