From e6a5bf116efc6f4c34c7d61aa27563c23807bde5 Mon Sep 17 00:00:00 2001 From: Oleg Lobanov Date: Tue, 19 Jan 2021 16:55:22 +0100 Subject: [PATCH] chore: remove empty string from locales (closes #1245) --- frontend/src/i18n/index.js | 45 ++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/frontend/src/i18n/index.js b/frontend/src/i18n/index.js index bdc37b03..25e1dc2b 100644 --- a/frontend/src/i18n/index.js +++ b/frontend/src/i18n/index.js @@ -77,28 +77,39 @@ export function detectLocale () { return locale } +const removeEmpty = (obj) => + Object.keys(obj) + .filter((k) => obj[k] !== null && obj[k] !== undefined && obj[k] !== '') // Remove undef. and null and empty.string. + .reduce( + (newObj, k) => + typeof obj[k] === 'object' + ? Object.assign(newObj, { [k]: removeEmpty(obj[k]) }) // Recurse. + : Object.assign(newObj, { [k]: obj[k] }), // Copy value. + {}, + ); + const i18n = new VueI18n({ locale: detectLocale(), fallbackLocale: 'en', messages: { - 'ar': ar, - 'de': de, + 'ar': removeEmpty(ar), + 'de': removeEmpty(de), 'en': en, - 'es': es, - 'fr': fr, - 'is': is, - 'it': it, - 'ja': ja, - 'ko': ko, - 'nl-be': nlBE, - 'pl': pl, - 'pt-br': ptBR, - 'pt': pt, - 'ru': ru, - 'ro': ro, - 'sv-se': svSE, - 'zh-cn': zhCN, - 'zh-tw': zhTW + 'es': removeEmpty(es), + 'fr': removeEmpty(fr), + 'is': removeEmpty(is), + 'it': removeEmpty(it), + 'ja': removeEmpty(ja), + 'ko': removeEmpty(ko), + 'nl-be': removeEmpty(nlBE), + 'pl': removeEmpty(pl), + 'pt-br': removeEmpty(ptBR), + 'pt': removeEmpty(pt), + 'ru': removeEmpty(ru), + 'ro': removeEmpty(ro), + 'sv-se': removeEmpty(svSE), + 'zh-cn': removeEmpty(zhCN), + 'zh-tw': removeEmpty(zhTW) } })