X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=scripts%2Fi18n%2Fxliff2json.ts;h=7e6de28935069e03aa485700178a6821574c61fa;hb=40b8906957719bf8ece5d5f8179136bc604dbf84;hp=fa5a71d659133430aa7b5f4052fd701f4f5d94ef;hpb=7ce44a74a3b052190cfacd4bd5ee6b92cfc620ac;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/i18n/xliff2json.ts b/scripts/i18n/xliff2json.ts index fa5a71d65..7e6de2893 100755 --- a/scripts/i18n/xliff2json.ts +++ b/scripts/i18n/xliff2json.ts @@ -1,5 +1,5 @@ import * as xliff12ToJs from 'xliff/xliff12ToJs' -import { unlink, readFileSync, writeFile } from 'fs' +import { readFileSync, unlink, writeFile } from 'fs-extra' import { join } from 'path' import { buildFileLocale, I18N_LOCALES, isDefaultLocale } from '../../shared/models/i18n/i18n' import { eachSeries } from 'async' @@ -9,7 +9,7 @@ const availableLocales = Object.keys(I18N_LOCALES) .filter(l => isDefaultLocale(l) === false) .map(l => buildFileLocale(l)) -for (const file of [ 'server', 'player' ]) { +for (const file of [ 'player', 'server', 'iso639' ]) { for (const locale of availableLocales) { sources.push(join(__dirname, '../../../client/src/locale/target/', `${file}_${locale}.xml`)) } @@ -20,7 +20,11 @@ eachSeries(sources, (source, cb) => { }, err => { if (err) return handleError(err) - process.exit(0) + mergeISO639InServer(err => { + if (err) return handleError(err) + + process.exit(0) + }) }) function handleError (err: any) { @@ -48,6 +52,28 @@ function xliffFile2JSON (filePath: string, 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`) + + 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) }