aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/i18n
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-11-13 09:45:27 +0100
committerChocobozzz <me@florianbigard.com>2019-11-13 10:04:16 +0100
commitcd1d6c23dae0fd08e69d49b21333742db86eeff7 (patch)
treed03a862b3488b2bfbd3c69cc73d0af6912c51553 /scripts/i18n
parent350131cbaf99bd1cbb2d0911093aa94d105de709 (diff)
downloadPeerTube-cd1d6c23dae0fd08e69d49b21333742db86eeff7.tar.gz
PeerTube-cd1d6c23dae0fd08e69d49b21333742db86eeff7.tar.zst
PeerTube-cd1d6c23dae0fd08e69d49b21333742db86eeff7.zip
Remove unused files
Diffstat (limited to 'scripts/i18n')
-rwxr-xr-xscripts/i18n/pull-hook.sh12
-rwxr-xr-xscripts/i18n/xliff2json.ts179
2 files changed, 0 insertions, 191 deletions
diff --git a/scripts/i18n/pull-hook.sh b/scripts/i18n/pull-hook.sh
deleted file mode 100755
index 66f3b4588..000000000
--- a/scripts/i18n/pull-hook.sh
+++ /dev/null
@@ -1,12 +0,0 @@
1#!/bin/sh
2
3set -eu
4
5for i in $(seq 1 10); do
6 # Zanata does not support inner elements in <source>, so we hack these special elements
7 # This regex translate the converted elements to initial Angular elements
8 perl -pi -e 's|&lt;x id=(.+?)/&gt;([^"])|<x id=\1/>\2|g' client/src/locale/target/*.xml
9done
10
11npm run i18n:xliff2json
12
diff --git a/scripts/i18n/xliff2json.ts b/scripts/i18n/xliff2json.ts
deleted file mode 100755
index d15039bb9..000000000
--- a/scripts/i18n/xliff2json.ts
+++ /dev/null
@@ -1,179 +0,0 @@
1import { registerTSPaths } from '../../server/helpers/register-ts-paths'
2registerTSPaths()
3
4import * as xliff12ToJs from 'xliff/xliff12ToJs'
5import { readFileSync, readJSON, unlink, writeFile, writeJSON, existsSync, exists, pathExists } from 'fs-extra'
6import { join } from 'path'
7import { buildFileLocale, I18N_LOCALES, isDefaultLocale } from '../../shared/models/i18n/i18n'
8import { eachSeries } from 'async'
9
10const sources: string[] = []
11const l = [
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)
54 .map(l => buildFileLocale(l))
55
56for (const file of [ 'player', 'server', 'iso639' ]) {
57 for (const locale of availableLocales) {
58 sources.push(join(__dirname, '../../../client/src/locale/target/', `${file}_${locale}.xml`))
59 }
60}
61
62eachSeries(sources, (source, cb) => {
63 xliffFile2JSON(source, cb)
64}, err => {
65 if (err) return handleError(err)
66
67 mergeISO639InServer(err => {
68 if (err) return handleError(err)
69
70 injectMissingTranslations().then(() => process.exit(0))
71 })
72})
73
74function handleError (err: any) {
75 console.error(err)
76 process.exit(-1)
77}
78
79function xliffFile2JSON (filePath: string, cb) {
80 const fileTarget = filePath.replace('.xml', '.json')
81
82 if (!existsSync(filePath)) {
83 console.log('No file %s exists.', filePath)
84 return cb()
85 }
86
87 // Remove the two first lines our xliff module does not like
88 let fileContent = readFileSync(filePath).toString()
89 fileContent = removeFirstLine(fileContent)
90 fileContent = removeFirstLine(fileContent)
91
92 xliff12ToJs(fileContent, (err, res) => {
93 if (err) return cb(err)
94
95 const json = createJSONString(res)
96 writeFile(fileTarget, json, err => {
97 if (err) return cb(err)
98
99 return unlink(filePath, cb)
100 })
101 })
102}
103
104function mergeISO639InServer (cb) {
105 eachSeries(availableLocales, (locale, eachCallback) => {
106 const serverPath = join(__dirname, '../../../client/src/locale/target/', `server_${locale}.json`)
107 const iso639Path = join(__dirname, '../../../client/src/locale/target/', `iso639_${locale}.json`)
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
118 const resServer = readFileSync(serverPath).toString()
119 const resISO639 = readFileSync(iso639Path).toString()
120
121 const jsonServer = JSON.parse(resServer)
122 const jsonISO639 = JSON.parse(resISO639)
123
124 Object.assign(jsonServer, jsonISO639)
125 const serverString = JSON.stringify(jsonServer)
126
127 writeFile(serverPath, serverString, err => {
128 if (err) return eachCallback(err)
129
130 return unlink(iso639Path, eachCallback)
131 })
132 }, cb)
133}
134
135function removeFirstLine (str: string) {
136 return str.substring(str.indexOf('\n') + 1)
137}
138
139function createJSONString (obj: any) {
140 const res: any = {}
141 const strings = obj.resources['']
142
143 Object.keys(strings).forEach(k => res[k] = strings[k].target)
144
145 return JSON.stringify(res)
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}