chore: remove empty string from locales (closes #1245)

pull/1222/head^2
Oleg Lobanov 2021-01-19 16:55:22 +01:00
parent 21b5a76fa7
commit e6a5bf116e
No known key found for this signature in database
GPG Key ID: 7CC64E41212621B0
1 changed files with 28 additions and 17 deletions

View File

@ -77,28 +77,39 @@ export function detectLocale () {
return locale 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({ const i18n = new VueI18n({
locale: detectLocale(), locale: detectLocale(),
fallbackLocale: 'en', fallbackLocale: 'en',
messages: { messages: {
'ar': ar, 'ar': removeEmpty(ar),
'de': de, 'de': removeEmpty(de),
'en': en, 'en': en,
'es': es, 'es': removeEmpty(es),
'fr': fr, 'fr': removeEmpty(fr),
'is': is, 'is': removeEmpty(is),
'it': it, 'it': removeEmpty(it),
'ja': ja, 'ja': removeEmpty(ja),
'ko': ko, 'ko': removeEmpty(ko),
'nl-be': nlBE, 'nl-be': removeEmpty(nlBE),
'pl': pl, 'pl': removeEmpty(pl),
'pt-br': ptBR, 'pt-br': removeEmpty(ptBR),
'pt': pt, 'pt': removeEmpty(pt),
'ru': ru, 'ru': removeEmpty(ru),
'ro': ro, 'ro': removeEmpty(ro),
'sv-se': svSE, 'sv-se': removeEmpty(svSE),
'zh-cn': zhCN, 'zh-cn': removeEmpty(zhCN),
'zh-tw': zhTW 'zh-tw': removeEmpty(zhTW)
} }
}) })