aboutsummaryrefslogtreecommitdiffstats
path: root/src/i18n/apply-branding.js
blob: 98fdce963e93b8db4824f4c2fb6be2a91b681982 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
 * Apply Ferdi branding to i18n translations
 */
const fs = require('fs-extra');
const path = require('path');

console.log('Applying Ferdi branding to translations...');

// Keys to ignore when applying branding
const ignore = [
    'login.customServerSuggestion'
]

// Files to ignore when applying branding
const ignoreFiles = [
    'defaultMessages.json',
    '.DS_Store',
    '.',
    '..'
]

// What to replace
const replace = {
    'franz': 'Ferdi',
    'meetfranz.com': 'getferdi.com'
}


const locales = path.join(__dirname, 'locales');
const files = fs.readdirSync(locales)

const replaceFind = Object.keys(replace);
const replaceReplaceWith = Object.values(replace);

const replaceStr = (str, find, replace) => {
    for (var i = 0; i < find.length; i++) {
        str = str.replace(new RegExp(find[i], 'gi'), replace[i]);
    }
    return str;
}

files.forEach(async file => {
    if (ignoreFiles.includes(file)) return;

    // Read locale data
    const filePath = path.join(locales, file);
    let locale = await fs.readJson(filePath);

    // Replace branding
    for (const key in locale) {
        if (ignore.includes(key)) return;

        locale[key] = replaceStr(locale[key], replaceFind, replaceReplaceWith);
    }

    await fs.writeJson(filePath, locale, {
        spaces: 2,
        EOL: '\n',
    });
})