-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: accept multiple locales in fallbackLocale #13822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we think?
18e2d2c
to
b8898ee
Compare
if ( | ||
typeof fallbackLocale === 'string' && | ||
fallbackLocale.startsWith('[') && | ||
fallbackLocale.endsWith(']') | ||
) { | ||
fallbackLocale = fallbackLocale | ||
.slice(1, -1) | ||
.split(',') | ||
.map((l) => l.trim()) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels out of place. Seems like any logic like this should be done outside of this function and the fallbackLocale should then be passed in. Not sure about the string manipulation here. Feels like we should be able to get the fallbackLocale off of the parsed params and pass it in.
What?
This change allows
fallbackLocale
to accept an array of locales in find queries and locale configuration.Why?
This update is part of the planned localization enhancements. Currently, only one fallback locale can be specified. If that locale doesn’t contain data, the query returns nothing. To work around this, users have to inspect the response themselves and then make additional queries for other locales.
With this change, Payload handles that work automatically. Users only need to provide a list of fallback locales in their preferred order, and Payload will check each one until it finds a value.
How?
Updates query handling across the local API, REST API, and GraphQL so that
fallbackLocale
can accept either a string or an array of locales. When an array is passed, Payload will iterate through them in order and return the first found localized value. This behavior applies to both collections and globals.Feature request: #13443