Skip to content

Commit

Permalink
chore: remove empty string from locales (closes #1245)
Browse files Browse the repository at this point in the history
  • Loading branch information
o1egl committed Jan 19, 2021
1 parent 21b5a76 commit e6a5bf1
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions frontend/src/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})

Expand Down

0 comments on commit e6a5bf1

Please sign in to comment.