diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/i18n/create-custom-files.ts | 20 | ||||
-rwxr-xr-x | scripts/i18n/xliff2json.ts | 34 |
2 files changed, 45 insertions, 9 deletions
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) | |||
34 | .concat(values(VIDEO_PRIVACIES)) | 34 | .concat(values(VIDEO_PRIVACIES)) |
35 | .forEach(v => serverKeys[v] = v) | 35 | .forEach(v => serverKeys[v] = v) |
36 | 36 | ||
37 | // ISO 639 keys | ||
38 | const languages = buildLanguages() | ||
39 | Object.keys(languages).forEach(k => serverKeys[languages[k]] = languages[k]) | ||
40 | |||
41 | // More keys | 37 | // More keys |
42 | Object.assign(serverKeys, { | 38 | Object.assign(serverKeys, { |
43 | 'Misc': 'Misc', | 39 | 'Misc': 'Misc', |
@@ -49,13 +45,27 @@ const serverTranslations = { | |||
49 | data: serverKeys | 45 | data: serverKeys |
50 | } | 46 | } |
51 | 47 | ||
48 | // ISO 639 keys | ||
49 | const languageKeys: any = {} | ||
50 | const languages = buildLanguages() | ||
51 | Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k]) | ||
52 | |||
53 | const iso639Translations = { | ||
54 | target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'), | ||
55 | data: languageKeys | ||
56 | } | ||
57 | |||
52 | saveToXliffFile(playerTranslations, err => { | 58 | saveToXliffFile(playerTranslations, err => { |
53 | if (err) return handleError(err) | 59 | if (err) return handleError(err) |
54 | 60 | ||
55 | saveToXliffFile(serverTranslations, err => { | 61 | saveToXliffFile(serverTranslations, err => { |
56 | if (err) return handleError(err) | 62 | if (err) return handleError(err) |
57 | 63 | ||
58 | process.exit(0) | 64 | saveToXliffFile(iso639Translations, err => { |
65 | if (err) return handleError(err) | ||
66 | |||
67 | process.exit(0) | ||
68 | }) | ||
59 | }) | 69 | }) |
60 | }) | 70 | }) |
61 | 71 | ||
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 @@ | |||
1 | import * as xliff12ToJs from 'xliff/xliff12ToJs' | 1 | import * as xliff12ToJs from 'xliff/xliff12ToJs' |
2 | import { unlink, readFileSync, writeFile } from 'fs' | 2 | import { readFile, readFileSync, unlink, writeFile } from 'fs' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { buildFileLocale, I18N_LOCALES, isDefaultLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n' | 4 | import { buildFileLocale, I18N_LOCALES, isDefaultLocale } from '../../shared/models/i18n/i18n' |
5 | import { eachSeries } from 'async' | 5 | import { eachSeries } from 'async' |
6 | 6 | ||
7 | const sources: string[] = [] | 7 | const sources: string[] = [] |
@@ -9,7 +9,7 @@ const availableLocales = Object.keys(I18N_LOCALES) | |||
9 | .filter(l => isDefaultLocale(l) === false) | 9 | .filter(l => isDefaultLocale(l) === false) |
10 | .map(l => buildFileLocale(l)) | 10 | .map(l => buildFileLocale(l)) |
11 | 11 | ||
12 | for (const file of LOCALE_FILES) { | 12 | for (const file of [ 'player', 'server', 'iso639' ]) { |
13 | for (const locale of availableLocales) { | 13 | for (const locale of availableLocales) { |
14 | sources.push(join(__dirname, '../../../client/src/locale/target/', `${file}_${locale}.xml`)) | 14 | sources.push(join(__dirname, '../../../client/src/locale/target/', `${file}_${locale}.xml`)) |
15 | } | 15 | } |
@@ -20,7 +20,11 @@ eachSeries(sources, (source, cb) => { | |||
20 | }, err => { | 20 | }, err => { |
21 | if (err) return handleError(err) | 21 | if (err) return handleError(err) |
22 | 22 | ||
23 | process.exit(0) | 23 | mergeISO639InServer(err => { |
24 | if (err) return handleError(err) | ||
25 | |||
26 | process.exit(0) | ||
27 | }) | ||
24 | }) | 28 | }) |
25 | 29 | ||
26 | function handleError (err: any) { | 30 | function handleError (err: any) { |
@@ -48,6 +52,28 @@ function xliffFile2JSON (filePath: string, cb) { | |||
48 | }) | 52 | }) |
49 | } | 53 | } |
50 | 54 | ||
55 | function mergeISO639InServer (cb) { | ||
56 | eachSeries(availableLocales, (locale, eachCallback) => { | ||
57 | const serverPath = join(__dirname, '../../../client/src/locale/target/', `server_${locale}.json`) | ||
58 | const iso639Path = join(__dirname, '../../../client/src/locale/target/', `iso639_${locale}.json`) | ||
59 | |||
60 | const resServer = readFileSync(serverPath).toString() | ||
61 | const resISO639 = readFileSync(iso639Path).toString() | ||
62 | |||
63 | const jsonServer = JSON.parse(resServer) | ||
64 | const jsonISO639 = JSON.parse(resISO639) | ||
65 | |||
66 | Object.assign(jsonServer, jsonISO639) | ||
67 | const serverString = JSON.stringify(jsonServer) | ||
68 | |||
69 | writeFile(serverPath, serverString, err => { | ||
70 | if (err) return eachCallback(err) | ||
71 | |||
72 | return unlink(iso639Path, eachCallback) | ||
73 | }) | ||
74 | }, cb) | ||
75 | } | ||
76 | |||
51 | function removeFirstLine (str: string) { | 77 | function removeFirstLine (str: string) { |
52 | return str.substring(str.indexOf('\n') + 1) | 78 | return str.substring(str.indexOf('\n') + 1) |
53 | } | 79 | } |