Skip to content

Commit 56387e7

Browse files
committed
feat(helper): always try to return a valid locale config
1 parent 02d058c commit 56387e7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tools/helper/src/client/composables/useLocaleConfig.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@ export const useLocaleConfig = <T extends LocaleData>(
1818
): ComputedRef<T> => {
1919
const routeLocale = useRouteLocale()
2020

21-
return computed(() => toValue(localesConfig)[routeLocale.value] ?? {})
21+
return computed(() => {
22+
const config = toValue(localesConfig)
23+
24+
return (
25+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
26+
config[routeLocale.value] ??
27+
// fallback to root locale config
28+
config['/'] ??
29+
// falling back to first locale config that exists
30+
Object.values(config)[0]
31+
)
32+
})
2233
}
2334

2435
/**

0 commit comments

Comments
 (0)