diff options
Diffstat (limited to 'src/i18n')
-rw-r--r-- | src/i18n/apply-branding.js | 15 | ||||
-rw-r--r-- | src/i18n/translations.js | 10 |
2 files changed, 14 insertions, 11 deletions
diff --git a/src/i18n/apply-branding.js b/src/i18n/apply-branding.js index 7aeabc4af..8ec573919 100644 --- a/src/i18n/apply-branding.js +++ b/src/i18n/apply-branding.js | |||
@@ -7,7 +7,7 @@ const path = require('path'); | |||
7 | console.log('Applying Ferdi branding to translations...'); | 7 | console.log('Applying Ferdi branding to translations...'); |
8 | 8 | ||
9 | // Keys to ignore when applying branding | 9 | // Keys to ignore when applying branding |
10 | const ignore = [ | 10 | const ignore = new Set([ |
11 | 'login.customServerSuggestion', | 11 | 'login.customServerSuggestion', |
12 | 'login.customServerQuestion', | 12 | 'login.customServerQuestion', |
13 | 'settings.app.todoServerInfo', | 13 | 'settings.app.todoServerInfo', |
@@ -18,10 +18,10 @@ const ignore = [ | |||
18 | 'settings.team.copy', | 18 | 'settings.team.copy', |
19 | 'settings.team.manageAction', | 19 | 'settings.team.manageAction', |
20 | 'settings.app.serverMoneyInfo', | 20 | 'settings.app.serverMoneyInfo', |
21 | ]; | 21 | ]); |
22 | 22 | ||
23 | // Files to ignore when applying branding | 23 | // Files to ignore when applying branding |
24 | const ignoreFiles = ['.DS_Store', '.', '..']; | 24 | const ignoreFiles = new Set(['.DS_Store', '.', '..']); |
25 | 25 | ||
26 | // What to replace | 26 | // What to replace |
27 | const replace = { | 27 | const replace = { |
@@ -38,14 +38,15 @@ const replaceFind = Object.keys(replace); | |||
38 | const replaceReplaceWith = Object.values(replace); | 38 | const replaceReplaceWith = Object.values(replace); |
39 | 39 | ||
40 | const replaceStr = (str, find, replaceWith) => { | 40 | const replaceStr = (str, find, replaceWith) => { |
41 | for (let i = 0; i < find.length; i += 1) { | 41 | for (const [i, element] of find.entries()) { |
42 | str = str.replace(new RegExp(find[i], 'gi'), replaceWith[i]); | 42 | str = str.replace(new RegExp(element, 'gi'), replaceWith[i]); |
43 | } | 43 | } |
44 | return str; | 44 | return str; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | // eslint-disable-next-line unicorn/no-array-for-each | ||
47 | files.forEach(async file => { | 48 | files.forEach(async file => { |
48 | if (ignoreFiles.includes(file)) return; | 49 | if (ignoreFiles.has(file)) return; |
49 | 50 | ||
50 | // Read locale data | 51 | // Read locale data |
51 | const filePath = path.join(locales, file); | 52 | const filePath = path.join(locales, file); |
@@ -53,7 +54,7 @@ files.forEach(async file => { | |||
53 | 54 | ||
54 | // Replace branding | 55 | // Replace branding |
55 | for (const key in locale) { | 56 | for (const key in locale) { |
56 | if (!ignore.includes(key)) { | 57 | if (!ignore.has(key)) { |
57 | locale[key] = replaceStr(locale[key], replaceFind, replaceReplaceWith); | 58 | locale[key] = replaceStr(locale[key], replaceFind, replaceReplaceWith); |
58 | } | 59 | } |
59 | } | 60 | } |
diff --git a/src/i18n/translations.js b/src/i18n/translations.js index 161a172ba..9a7dc7453 100644 --- a/src/i18n/translations.js +++ b/src/i18n/translations.js | |||
@@ -1,13 +1,15 @@ | |||
1 | /* eslint-disable global-require */ | ||
1 | import { APP_LOCALES } from './languages'; | 2 | import { APP_LOCALES } from './languages'; |
2 | 3 | ||
3 | const translations = []; | 4 | const translations = []; |
4 | Object.keys(APP_LOCALES).forEach((key) => { | 5 | for (const key of Object.keys(APP_LOCALES)) { |
5 | try { | 6 | try { |
6 | const translation = require(`./locales/${key}.json`); // eslint-disable-line | 7 | // eslint-disable-next-line import/no-dynamic-require |
8 | const translation = require(`./locales/${key}.json`); | ||
7 | translations[key] = translation; | 9 | translations[key] = translation; |
8 | } catch (err) { | 10 | } catch { |
9 | console.warn(`Can't find translations for ${key}`); | 11 | console.warn(`Can't find translations for ${key}`); |
10 | } | 12 | } |
11 | }); | 13 | } |
12 | 14 | ||
13 | module.exports = translations; | 15 | module.exports = translations; |