diff options
Diffstat (limited to 'src/i18n/apply-branding.ts')
-rw-r--r-- | src/i18n/apply-branding.ts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/i18n/apply-branding.ts b/src/i18n/apply-branding.ts new file mode 100644 index 000000000..801a4a525 --- /dev/null +++ b/src/i18n/apply-branding.ts | |||
@@ -0,0 +1,66 @@ | |||
1 | /** | ||
2 | * Apply Ferdi branding to i18n translations | ||
3 | */ | ||
4 | import fs from 'fs-extra'; | ||
5 | import path from 'path'; | ||
6 | |||
7 | console.log('Applying Ferdi branding to translations...'); | ||
8 | |||
9 | // Keys to ignore when applying branding | ||
10 | const ignore = new Set([ | ||
11 | 'login.customServerSuggestion', | ||
12 | 'login.customServerQuestion', | ||
13 | 'settings.app.todoServerInfo', | ||
14 | 'settings.app.serverMoneyInfo', | ||
15 | 'settings.team.teamsUnavailableInfo', | ||
16 | 'settings.team.contentHeadline', | ||
17 | 'settings.team.intro', | ||
18 | 'settings.team.copy', | ||
19 | 'settings.team.manageAction', | ||
20 | 'settings.app.serverMoneyInfo', | ||
21 | ]); | ||
22 | |||
23 | // Files to ignore when applying branding | ||
24 | const ignoreFiles = new Set(['.DS_Store', '.', '..']); | ||
25 | |||
26 | // What to replace | ||
27 | const replace = { | ||
28 | 'meetfranz.com': 'getferdi.com', | ||
29 | 'meetferdi.com': 'getferdi.com', // If Franz already got replaced with Ferdi | ||
30 | franz: 'Ferdi', | ||
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 (const [i, element] of find.entries()) { | ||
42 | str = str.replace(new RegExp(element, 'gi'), replaceWith[i]); | ||
43 | } | ||
44 | return str; | ||
45 | }; | ||
46 | |||
47 | // eslint-disable-next-line unicorn/no-array-for-each | ||
48 | files.forEach(async file => { | ||
49 | if (ignoreFiles.has(file)) return; | ||
50 | |||
51 | // Read locale data | ||
52 | const filePath = path.join(locales, file); | ||
53 | const locale = await fs.readJson(filePath); | ||
54 | |||
55 | // Replace branding | ||
56 | for (const key in locale) { | ||
57 | if (!ignore.has(key)) { | ||
58 | locale[key] = replaceStr(locale[key], replaceFind, replaceReplaceWith); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | await fs.writeJson(filePath, locale, { | ||
63 | spaces: 2, | ||
64 | EOL: '\n', | ||
65 | }); | ||
66 | }); | ||