From 850c1bf7cc438b935f6e283c801b34b91bf629c6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 13 Jun 2018 15:55:13 +0200 Subject: Move iso639 strings in its own translation file --- scripts/i18n/create-custom-files.ts | 20 +++++++++++++++----- scripts/i18n/xliff2json.ts | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 9 deletions(-) (limited to 'scripts/i18n') diff --git a/scripts/i18n/create-custom-files.ts b/scripts/i18n/create-custom-files.ts index 3519afd47..7d994a710 100755 --- a/scripts/i18n/create-custom-files.ts +++ b/scripts/i18n/create-custom-files.ts @@ -34,10 +34,6 @@ values(VIDEO_CATEGORIES) .concat(values(VIDEO_PRIVACIES)) .forEach(v => serverKeys[v] = v) -// ISO 639 keys -const languages = buildLanguages() -Object.keys(languages).forEach(k => serverKeys[languages[k]] = languages[k]) - // More keys Object.assign(serverKeys, { 'Misc': 'Misc', @@ -49,13 +45,27 @@ const serverTranslations = { 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) - process.exit(0) + saveToXliffFile(iso639Translations, err => { + if (err) return handleError(err) + + process.exit(0) + }) }) }) diff --git a/scripts/i18n/xliff2json.ts b/scripts/i18n/xliff2json.ts index c60739561..17c73181b 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 { readFile, 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) } -- cgit v1.2.3