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