diff options
Diffstat (limited to 'src/i18n/apply-branding.js')
-rw-r--r-- | src/i18n/apply-branding.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/i18n/apply-branding.js b/src/i18n/apply-branding.js new file mode 100644 index 000000000..521186d08 --- /dev/null +++ b/src/i18n/apply-branding.js | |||
@@ -0,0 +1,65 @@ | |||
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 | 'login.customServerQuestion', | ||
13 | 'settings.app.todoServerInfo', | ||
14 | 'settings.app.serverMoneyInfo', | ||
15 | ]; | ||
16 | |||
17 | // Files to ignore when applying branding | ||
18 | const ignoreFiles = [ | ||
19 | 'defaultMessages.json', | ||
20 | '.DS_Store', | ||
21 | '.', | ||
22 | '..', | ||
23 | ]; | ||
24 | |||
25 | // What to replace | ||
26 | const replace = { | ||
27 | 'meetfranz.com': 'getferdi.com', | ||
28 | 'meetferdi.com': 'getferdi.com', // If Franz already got replaced with Ferdi | ||
29 | franz: 'Ferdi', | ||
30 | '!!!': '', | ||
31 | }; | ||
32 | |||
33 | |||
34 | const locales = path.join(__dirname, 'locales'); | ||
35 | const files = fs.readdirSync(locales); | ||
36 | |||
37 | const replaceFind = Object.keys(replace); | ||
38 | const replaceReplaceWith = Object.values(replace); | ||
39 | |||
40 | const replaceStr = (str, find, replaceWith) => { | ||
41 | for (let i = 0; i < find.length; i += 1) { | ||
42 | str = str.replace(new RegExp(find[i], 'gi'), replaceWith[i]); | ||
43 | } | ||
44 | return str; | ||
45 | }; | ||
46 | |||
47 | files.forEach(async (file) => { | ||
48 | if (ignoreFiles.includes(file)) return; | ||
49 | |||
50 | // Read locale data | ||
51 | const filePath = path.join(locales, file); | ||
52 | const locale = await fs.readJson(filePath); | ||
53 | |||
54 | // Replace branding | ||
55 | for (const key in locale) { | ||
56 | if (!ignore.includes(key)) { | ||
57 | locale[key] = replaceStr(locale[key], replaceFind, replaceReplaceWith); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | await fs.writeJson(filePath, locale, { | ||
62 | spaces: 2, | ||
63 | EOL: '\n', | ||
64 | }); | ||
65 | }); | ||