diff options
author | vantezzen <hello@vantezzen.io> | 2019-09-19 14:44:24 +0200 |
---|---|---|
committer | vantezzen <hello@vantezzen.io> | 2019-09-19 14:44:24 +0200 |
commit | af4cca158e083906ce1105cdba9bcef28eeb83ba (patch) | |
tree | 88392f402ab0beee793fcc1da4c3284016dae626 /src | |
parent | Fix incorrect link (diff) | |
download | ferdium-app-af4cca158e083906ce1105cdba9bcef28eeb83ba.tar.gz ferdium-app-af4cca158e083906ce1105cdba9bcef28eeb83ba.tar.zst ferdium-app-af4cca158e083906ce1105cdba9bcef28eeb83ba.zip |
Add automatic brand replacement
Diffstat (limited to 'src')
-rw-r--r-- | src/i18n/apply-branding.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/i18n/apply-branding.js b/src/i18n/apply-branding.js new file mode 100644 index 000000000..98fdce963 --- /dev/null +++ b/src/i18n/apply-branding.js | |||
@@ -0,0 +1,60 @@ | |||
1 | /** | ||
2 | * Apply Ferdi branding to i18n translations | ||
3 | */ | ||
4 | const fs = require('fs-extra'); | ||
5 | const path = require('path'); | ||
6 | |||
7 | console.log('Applying Ferdi branding to translations...'); | ||
8 | |||
9 | // Keys to ignore when applying branding | ||
10 | const ignore = [ | ||
11 | 'login.customServerSuggestion' | ||
12 | ] | ||
13 | |||
14 | // Files to ignore when applying branding | ||
15 | const ignoreFiles = [ | ||
16 | 'defaultMessages.json', | ||
17 | '.DS_Store', | ||
18 | '.', | ||
19 | '..' | ||
20 | ] | ||
21 | |||
22 | // What to replace | ||
23 | const replace = { | ||
24 | 'franz': 'Ferdi', | ||
25 | 'meetfranz.com': 'getferdi.com' | ||
26 | } | ||
27 | |||
28 | |||
29 | const locales = path.join(__dirname, 'locales'); | ||
30 | const files = fs.readdirSync(locales) | ||
31 | |||
32 | const replaceFind = Object.keys(replace); | ||
33 | const replaceReplaceWith = Object.values(replace); | ||
34 | |||
35 | const replaceStr = (str, find, replace) => { | ||
36 | for (var i = 0; i < find.length; i++) { | ||
37 | str = str.replace(new RegExp(find[i], 'gi'), replace[i]); | ||
38 | } | ||
39 | return str; | ||
40 | } | ||
41 | |||
42 | files.forEach(async file => { | ||
43 | if (ignoreFiles.includes(file)) return; | ||
44 | |||
45 | // Read locale data | ||
46 | const filePath = path.join(locales, file); | ||
47 | let locale = await fs.readJson(filePath); | ||
48 | |||
49 | // Replace branding | ||
50 | for (const key in locale) { | ||
51 | if (ignore.includes(key)) return; | ||
52 | |||
53 | locale[key] = replaceStr(locale[key], replaceFind, replaceReplaceWith); | ||
54 | } | ||
55 | |||
56 | await fs.writeJson(filePath, locale, { | ||
57 | spaces: 2, | ||
58 | EOL: '\n', | ||
59 | }); | ||
60 | }) \ No newline at end of file | ||