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