X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=scripts%2Fi18n%2Fxliff2json.ts;h=ed6854514c560d5fb58ef28aa7f617cef22c5759;hb=9a12f169c15b638fe78cf6e85a1993550a25e404;hp=c607395615399100759c75e27ab2a004a5a7b507;hpb=74b7c6d48e9ca377fe938c8134ed74b612e62ba0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/i18n/xliff2json.ts b/scripts/i18n/xliff2json.ts index c60739561..ed6854514 100755 --- a/scripts/i18n/xliff2json.ts +++ b/scripts/i18n/xliff2json.ts @@ -1,7 +1,7 @@ import * as xliff12ToJs from 'xliff/xliff12ToJs' -import { unlink, readFileSync, writeFile } from 'fs' +import { readFileSync, unlink, writeFile } from 'fs' import { join } from 'path' -import { buildFileLocale, I18N_LOCALES, isDefaultLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n' +import { buildFileLocale, I18N_LOCALES, isDefaultLocale } from '../../shared/models/i18n/i18n' import { eachSeries } from 'async' const sources: string[] = [] @@ -9,7 +9,7 @@ const availableLocales = Object.keys(I18N_LOCALES) .filter(l => isDefaultLocale(l) === false) .map(l => buildFileLocale(l)) -for (const file of LOCALE_FILES) { +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) }