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.js60
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..39497967e
--- /dev/null
+++ b/src/i18n/apply-branding.js
@@ -0,0 +1,60 @@
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 franz: 'Ferdi',
25 'meetfranz.com': 'getferdi.com',
26};
27
28
29const locales = path.join(__dirname, 'locales');
30const files = fs.readdirSync(locales);
31
32const replaceFind = Object.keys(replace);
33const replaceReplaceWith = Object.values(replace);
34
35const replaceStr = (str, find, replaceWith) => {
36 for (let i = 0; i < find.length; i += 1) {
37 str = str.replace(new RegExp(find[i], 'gi'), replaceWith[i]);
38 }
39 return str;
40};
41
42files.forEach(async (file) => {
43 if (ignoreFiles.includes(file)) return;
44
45 // Read locale data
46 const filePath = path.join(locales, file);
47 const locale = await fs.readJson(filePath);
48
49 // Replace branding
50 for (const key in locale) {
51 if (!ignore.includes(key)) {
52 locale[key] = replaceStr(locale[key], replaceFind, replaceReplaceWith);
53 }
54 }
55
56 await fs.writeJson(filePath, locale, {
57 spaces: 2,
58 EOL: '\n',
59 });
60});