aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-11-07 12:00:09 +0100
committerChocobozzz <me@florianbigard.com>2019-11-07 12:00:09 +0100
commitad912c3de64939cc2cd128ec45a4b32cb548f8d1 (patch)
tree5955008f66911fd67d2944d078b888986d837a61 /scripts
parentfbe771350b5e330a58c2b609b8159db5144d0789 (diff)
downloadPeerTube-ad912c3de64939cc2cd128ec45a4b32cb548f8d1.tar.gz
PeerTube-ad912c3de64939cc2cd128ec45a4b32cb548f8d1.tar.zst
PeerTube-ad912c3de64939cc2cd128ec45a4b32cb548f8d1.zip
Update server and player
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/i18n/xliff2json.ts96
1 files changed, 92 insertions, 4 deletions
diff --git a/scripts/i18n/xliff2json.ts b/scripts/i18n/xliff2json.ts
index 68fc95f34..d15039bb9 100755
--- a/scripts/i18n/xliff2json.ts
+++ b/scripts/i18n/xliff2json.ts
@@ -2,14 +2,55 @@ import { registerTSPaths } from '../../server/helpers/register-ts-paths'
2registerTSPaths() 2registerTSPaths()
3 3
4import * as xliff12ToJs from 'xliff/xliff12ToJs' 4import * as xliff12ToJs from 'xliff/xliff12ToJs'
5import { readFileSync, unlink, writeFile } from 'fs-extra' 5import { readFileSync, readJSON, unlink, writeFile, writeJSON, existsSync, exists, pathExists } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { buildFileLocale, I18N_LOCALES, isDefaultLocale } from '../../shared/models/i18n/i18n' 7import { buildFileLocale, I18N_LOCALES, isDefaultLocale } from '../../shared/models/i18n/i18n'
8import { eachSeries } from 'async' 8import { eachSeries } from 'async'
9 9
10const sources: string[] = [] 10const sources: string[] = []
11const availableLocales = Object.keys(I18N_LOCALES) 11const l = [
12 .filter(l => isDefaultLocale(l) === false) 12 'ar-001',
13 'ca-ES',
14 'cs-CZ',
15 'da-DK',
16 'de-DE',
17 'el-GR',
18 'en-GB',
19 'en-US',
20 'eo',
21 'es-ES',
22 'eu-ES',
23 'fa-IR',
24 'fi-FI',
25 'fr-FR',
26 'gd',
27 'gl-ES',
28 'hu-HU',
29 'it-IT',
30 'ja-JP',
31 'jbo',
32 'ko-KR',
33 'lt-LT',
34 'nb-NO',
35 'nl-NL',
36 'oc',
37 'pl-PL',
38 'pt-BR',
39 'pt-PT',
40 'ru-RU',
41 'sk-SK',
42 'sl-SI',
43 'sv-SE',
44 'ta',
45 'th-TH',
46 'tr-TR',
47 'uk-UA',
48 'vi-VN',
49 'zh-Hans-CN',
50 'zh-Hant-TW'
51]
52
53const availableLocales = l.filter(l => isDefaultLocale(l) === false)
13 .map(l => buildFileLocale(l)) 54 .map(l => buildFileLocale(l))
14 55
15for (const file of [ 'player', 'server', 'iso639' ]) { 56for (const file of [ 'player', 'server', 'iso639' ]) {
@@ -26,7 +67,7 @@ eachSeries(sources, (source, cb) => {
26 mergeISO639InServer(err => { 67 mergeISO639InServer(err => {
27 if (err) return handleError(err) 68 if (err) return handleError(err)
28 69
29 process.exit(0) 70 injectMissingTranslations().then(() => process.exit(0))
30 }) 71 })
31}) 72})
32 73
@@ -38,6 +79,11 @@ function handleError (err: any) {
38function xliffFile2JSON (filePath: string, cb) { 79function xliffFile2JSON (filePath: string, cb) {
39 const fileTarget = filePath.replace('.xml', '.json') 80 const fileTarget = filePath.replace('.xml', '.json')
40 81
82 if (!existsSync(filePath)) {
83 console.log('No file %s exists.', filePath)
84 return cb()
85 }
86
41 // Remove the two first lines our xliff module does not like 87 // Remove the two first lines our xliff module does not like
42 let fileContent = readFileSync(filePath).toString() 88 let fileContent = readFileSync(filePath).toString()
43 fileContent = removeFirstLine(fileContent) 89 fileContent = removeFirstLine(fileContent)
@@ -60,6 +106,15 @@ function mergeISO639InServer (cb) {
60 const serverPath = join(__dirname, '../../../client/src/locale/target/', `server_${locale}.json`) 106 const serverPath = join(__dirname, '../../../client/src/locale/target/', `server_${locale}.json`)
61 const iso639Path = join(__dirname, '../../../client/src/locale/target/', `iso639_${locale}.json`) 107 const iso639Path = join(__dirname, '../../../client/src/locale/target/', `iso639_${locale}.json`)
62 108
109 if (!existsSync(serverPath)) {
110 console.log('No file %s exists.', serverPath)
111 return cb()
112 }
113 if (!existsSync(iso639Path)) {
114 console.log('No file %s exists.', iso639Path)
115 return cb()
116 }
117
63 const resServer = readFileSync(serverPath).toString() 118 const resServer = readFileSync(serverPath).toString()
64 const resISO639 = readFileSync(iso639Path).toString() 119 const resISO639 = readFileSync(iso639Path).toString()
65 120
@@ -89,3 +144,36 @@ function createJSONString (obj: any) {
89 144
90 return JSON.stringify(res) 145 return JSON.stringify(res)
91} 146}
147
148async function injectMissingTranslations () {
149 const baseServer = await readJSON(join(__dirname, '../../../client/src/locale/server.en-US.json'))
150 Object.keys(baseServer).forEach(k => baseServer[k] = '')
151
152 for (const locale of availableLocales) {
153 const serverPath = join(__dirname, '../../../client/src/locale/target/', `server_${locale}.json`)
154 if (!await pathExists(serverPath)) {
155 console.log('No file exists to inject missing translations: %s.', serverPath)
156 continue
157 }
158
159 let serverJSON = await readJSON(serverPath)
160
161 serverJSON = Object.assign({}, baseServer, serverJSON)
162 await writeJSON(serverPath, serverJSON)
163 }
164
165 const basePlayer = await readJSON(join(__dirname, '../../../client/src/locale/player.en-US.json'))
166 Object.keys(basePlayer).forEach(k => basePlayer[k] = '')
167 for (const locale of availableLocales) {
168 const serverPath = join(__dirname, '../../../client/src/locale/target/', `player_${locale}.json`)
169 if (!await pathExists(serverPath)) {
170 console.log('No file exists to inject missing translations: %s.', serverPath)
171 continue
172 }
173
174 let serverJSON = await readJSON(serverPath)
175
176 serverJSON = Object.assign({}, basePlayer, serverJSON)
177 await writeJSON(serverPath, serverJSON)
178 }
179}