mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-11-16 09:59:58 +01:00
refactor: 💡 include generic locales on id not found message
This commit is contained in:
parent
3f73cce65f
commit
690822b6ac
@ -59,7 +59,13 @@ const formatMessage: Formatter = (id, options = {}) => {
|
||||
const message = lookupMessage(id, locale)
|
||||
|
||||
if (!message) {
|
||||
console.warn(`[svelte-i18n] The message "${id}" was not found in the locale "${locale}".`)
|
||||
console.warn(
|
||||
`[svelte-i18n] The message "${id}" was not found in "${locale
|
||||
.split('-')
|
||||
.map((_, i, arr) => arr.slice(0, i + 1).join('-'))
|
||||
.reverse()
|
||||
.join('", "')}".`,
|
||||
)
|
||||
if (defaultValue != null) return defaultValue
|
||||
return id
|
||||
}
|
||||
|
@ -137,8 +137,8 @@ describe('utilities', () => {
|
||||
})
|
||||
|
||||
it('should get the fallback locale', () => {
|
||||
expect(getClientLocale({ navigator: false, fallback: 'pt' })).toBe('pt')
|
||||
expect(getClientLocale({ hash: 'locale', fallback: 'pt' })).toBe('pt')
|
||||
expect(getClientLocale({ navigator: false, default: 'pt' })).toBe('pt')
|
||||
expect(getClientLocale({ hash: 'locale', default: 'pt' })).toBe('pt')
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user