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.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/i18n/apply-branding.js b/src/i18n/apply-branding.js
new file mode 100644
index 000000000..d88d8741b
--- /dev/null
+++ b/src/i18n/apply-branding.js
@@ -0,0 +1,67 @@
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 'login.customServerQuestion',
13 'settings.app.todoServerInfo',
14 'settings.app.serverMoneyInfo',
15 'settings.team.teamsUnavailableInfo',
16 'settings.app.serverMoneyInfo',
17];
18
19// Files to ignore when applying branding
20const ignoreFiles = [
21 'defaultMessages.json',
22 '.DS_Store',
23 '.',
24 '..',
25];
26
27// What to replace
28const replace = {
29 'meetfranz.com': 'getferdi.com',
30 'meetferdi.com': 'getferdi.com', // If Franz already got replaced with Ferdi
31 franz: 'Ferdi',
32 '!!!': '',
33};
34
35
36const locales = path.join(__dirname, 'locales');
37const files = fs.readdirSync(locales);
38
39const replaceFind = Object.keys(replace);
40const replaceReplaceWith = Object.values(replace);
41
42const replaceStr = (str, find, replaceWith) => {
43 for (let i = 0; i < find.length; i += 1) {
44 str = str.replace(new RegExp(find[i], 'gi'), replaceWith[i]);
45 }
46 return str;
47};
48
49files.forEach(async (file) => {
50 if (ignoreFiles.includes(file)) return;
51
52 // Read locale data
53 const filePath = path.join(locales, file);
54 const locale = await fs.readJson(filePath);
55
56 // Replace branding
57 for (const key in locale) {
58 if (!ignore.includes(key)) {
59 locale[key] = replaceStr(locale[key], replaceFind, replaceReplaceWith);
60 }
61 }
62
63 await fs.writeJson(filePath, locale, {
64 spaces: 2,
65 EOL: '\n',
66 });
67});