Remove empty keys to allow English fallback
This commit is contained in:
parent
e43c172d96
commit
056d5e7111
1 changed files with 14 additions and 1 deletions
|
|
@ -7,14 +7,27 @@ import en from './en.json'
|
||||||
// Only returns current selected locale if its translations are found in localStorage
|
// Only returns current selected locale if its translations are found in localStorage
|
||||||
const defaultLocale = function () {
|
const defaultLocale = function () {
|
||||||
const locale = localStorage.getItem('locale')
|
const locale = localStorage.getItem('locale')
|
||||||
const current = localStorage.getItem('translation')
|
const current = JSON.parse(localStorage.getItem('translation'))
|
||||||
if (current && current.id === locale) {
|
if (current && current.id === locale) {
|
||||||
return locale
|
return locale
|
||||||
}
|
}
|
||||||
return 'en'
|
return 'en'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const removeEmpty = (obj) => {
|
||||||
|
for (let k in obj) {
|
||||||
|
if (obj.hasOwnProperty(k) && typeof obj[k] === 'object') {
|
||||||
|
removeEmpty(obj[k])
|
||||||
|
} else {
|
||||||
|
if (!obj[k]) {
|
||||||
|
delete obj[k]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const prepareLanguage = (lang) => {
|
const prepareLanguage = (lang) => {
|
||||||
|
removeEmpty(lang)
|
||||||
// Make "albumSongs" resource use the same translations as "song"
|
// Make "albumSongs" resource use the same translations as "song"
|
||||||
lang.resources.albumSong = lang.resources.song
|
lang.resources.albumSong = lang.resources.song
|
||||||
// ra.boolean.null should always be empty
|
// ra.boolean.null should always be empty
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue