aboutsummaryrefslogtreecommitdiffstats
path: root/src/i18n/apply-branding.ts
diff options
context:
space:
mode:
authorLibravatar Markus Hatvan <markus_hatvan@aon.at>2021-09-18 11:15:25 +0200
committerLibravatar GitHub <noreply@github.com>2021-09-18 11:15:25 +0200
commitd4101a48b3eee8b1fb177831aa02a4b4fbec2588 (patch)
treec92f2fbe91197fde8589207463d0d6526b4ff76b /src/i18n/apply-branding.ts
parent5.6.3-nightly.6 [skip ci] (diff)
downloadferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.tar.gz
ferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.tar.zst
ferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.zip
chore: convert various files from JS to TS (#1959)
Diffstat (limited to 'src/i18n/apply-branding.ts')
-rw-r--r--src/i18n/apply-branding.ts66
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 */
4import fs from 'fs-extra';
5import path from 'path';
6
7console.log('Applying Ferdi branding to translations...');
8
9// Keys to ignore when applying branding
10const 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
24const ignoreFiles = new Set(['.DS_Store', '.', '..']);
25
26// What to replace
27const replace = {
28 'meetfranz.com': 'getferdi.com',
29 'meetferdi.com': 'getferdi.com', // If Franz already got replaced with Ferdi
30 franz: 'Ferdi',
31 '!!!': '',
32};
33
34const locales = path.join(__dirname, 'locales');
35const files = fs.readdirSync(locales);
36
37const replaceFind = Object.keys(replace);
38const replaceReplaceWith = Object.values(replace);
39
40const 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
48files.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});