fix: 🐛 fallback locale being looked twice

This commit is contained in:
Christian Kaisermann 2019-11-24 20:22:30 -03:00
parent 1ea650860c
commit 9260b83756
2 changed files with 3 additions and 3 deletions

View File

@ -3,7 +3,7 @@
export async function preload() {
return setInitialLocale({
fallback: 'en-US',
fallback: 'en',
// navigator: true,
search: 'lang'
})

View File

@ -25,7 +25,7 @@ export function isFallbackLocaleOf(localeA: string, localeB: string) {
export function getFallbackOf(locale: string) {
const index = locale.lastIndexOf('-')
if (index > 0) return locale.slice(0, index)
if (fallback && !isFallbackLocaleOf(locale, fallback)) return fallback
if (fallback && !isFallbackLocaleOf(fallback, locale)) return fallback
return null
}
@ -34,7 +34,7 @@ export function getFallbacksOf(locale: string): string[] {
.split('-')
.map((_, i, arr) => arr.slice(0, i + 1).join('-'))
if (fallback != null && !isFallbackLocaleOf(locale, fallback)) {
if (fallback != null && !isFallbackLocaleOf(fallback, locale)) {
return locales.concat(getFallbacksOf(fallback))
}
return locales