aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar vantezzen <hello@vantezzen.io>2019-09-19 14:44:24 +0200
committerLibravatar vantezzen <hello@vantezzen.io>2019-09-19 14:44:24 +0200
commitaf4cca158e083906ce1105cdba9bcef28eeb83ba (patch)
tree88392f402ab0beee793fcc1da4c3284016dae626
parentFix incorrect link (diff)
downloadferdium-app-af4cca158e083906ce1105cdba9bcef28eeb83ba.tar.gz
ferdium-app-af4cca158e083906ce1105cdba9bcef28eeb83ba.tar.zst
ferdium-app-af4cca158e083906ce1105cdba9bcef28eeb83ba.zip
Add automatic brand replacement
-rw-r--r--package.json5
-rw-r--r--src/i18n/apply-branding.js60
2 files changed, 63 insertions, 2 deletions
diff --git a/package.json b/package.json
index 061eb7e6b..84228befc 100644
--- a/package.json
+++ b/package.json
@@ -30,7 +30,8 @@
30 "packages": "npx lerna publish --no-git-tag-version", 30 "packages": "npx lerna publish --no-git-tag-version",
31 "uidev": "cd uidev && webpack-dev-server", 31 "uidev": "cd uidev && webpack-dev-server",
32 "postinstall": "npx lerna run prepare", 32 "postinstall": "npx lerna run prepare",
33 "prepare-code": "npm run lint && npm run reformat-files && npm run manage-translations" 33 "apply-branding": "node ./src/i18n/apply-branding.js",
34 "prepare-code": "npm run lint && npm run reformat-files && npm run apply-branding && npm run manage-translations"
34 }, 35 },
35 "keywords": [], 36 "keywords": [],
36 "author": "Amine Mouafik <amine@mouafik.fr>", 37 "author": "Amine Mouafik <amine@mouafik.fr>",
@@ -171,7 +172,7 @@
171 ], 172 ],
172 "husky": { 173 "husky": {
173 "hooks": { 174 "hooks": {
174 "pre-push": "npm run lint && npm run reformat-files && npm run manage-translations" 175 "pre-push": "npm run lint && npm run reformat-files && npm run apply-branding && npm run manage-translations"
175 } 176 }
176 } 177 }
177} 178}
diff --git a/src/i18n/apply-branding.js b/src/i18n/apply-branding.js
new file mode 100644
index 000000000..98fdce963
--- /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, replace) => {
36 for (var i = 0; i < find.length; i++) {
37 str = str.replace(new RegExp(find[i], 'gi'), replace[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 let locale = await fs.readJson(filePath);
48
49 // Replace branding
50 for (const key in locale) {
51 if (ignore.includes(key)) return;
52
53 locale[key] = replaceStr(locale[key], replaceFind, replaceReplaceWith);
54 }
55
56 await fs.writeJson(filePath, locale, {
57 spaces: 2,
58 EOL: '\n',
59 });
60}) \ No newline at end of file