refactor: 💡 include generic locales on id not found message

This commit is contained in:
Christian Kaisermann 2019-11-19 21:35:49 -03:00
parent 3f73cce65f
commit 690822b6ac
2 changed files with 9 additions and 3 deletions

View File

@ -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
}

View File

@ -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')
})
})