chore: align fallbackLocale determination with new fallbackLocale property on Locale

This commit is contained in:
Jarrod Flesch
2024-01-25 12:00:50 -05:00
parent df40bafcfe
commit b8e7b9c8b3
2 changed files with 9 additions and 1 deletions

View File

@@ -303,6 +303,10 @@ export type Locale = {
* @example "en"
*/
code: string
/**
* Code of another locale to use when reading documents with fallback, if not specified defaultLocale is used
*/
fallbackLocale?: string
/**
* label of supported locale
* @example "English"

View File

@@ -40,7 +40,11 @@ export const createLocalReq: CreateLocalReq = (
if (payload.config?.localization) {
const defaultLocale = payload.config.localization.defaultLocale
req.locale = locale || req?.locale || defaultLocale
req.fallbackLocale = fallbackLocale || req?.fallbackLocale || defaultLocale
const fallbackLocaleFromConfig = payload.config.localization.locales.find(
({ code }) => req.locale === code,
)?.fallbackLocale
req.fallbackLocale =
fallbackLocale || req?.fallbackLocale || fallbackLocaleFromConfig || defaultLocale
}
req.context = getRequestContext(req, context)