You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: accept multiple locales in fallbackLocale (#13822)
### What?
This change allows `fallbackLocale` to accept an **array of locales** in
find queries and locale configuration.
```ts
/** Local API **/
await payload.findByID({
id,
collection,
locale: 'en',
fallbackLocale: ['fr', 'es'],
})
/** REST API **/
await fetch(`${baseURL}/api/${collectionSlug}?locale=en&fallbackLocale[]=fr&fallbackLocale[]=es`)
/** GraphQL **/
await restClient.GRAPHQL_POST({
body,
query: { locale: 'en', fallbackLocale: ['fr', 'es']},
})
/** Locale Configs **/
locales: [
{
code: 'en',
label: 'English',
fallbackLocale: ['fr', 'es'],
},
]
```
### Why?
This update is part of the planned [localization
enhancements](#10705).
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
---------
Co-authored-by: Jarrod Flesch <[email protected]>
|**`code`**\*| Unique code to identify the language throughout the APIs for `locale` and `fallbackLocale`|
99
+
|**`label`**| A string to use for the selector when choosing a language, or an object keyed on the i18n keys for different languages in use. |
100
+
|**`rtl`**| A boolean that when true will make the admin UI display in Right-To-Left. |
101
+
|**`fallbackLocale`**| The code for this language to fallback to when properties of a document are not present. This can be a single locale or array of locales.|
102
102
103
103
_\* An asterisk denotes that a property is required._
104
104
@@ -199,7 +199,7 @@ The `locale` arg will only accept valid locales, but locales will be formatted a
199
199
values (dashes or special characters will be converted to underscores, spaces will be removed, etc.). If you are curious
200
200
to see how locales are auto-formatted, you can use the [GraphQL playground](/docs/graphql/overview#graphql-playground).
201
201
202
-
The `fallbackLocale` arg will accept valid locales as well as `none` to disable falling back.
202
+
The `fallbackLocale` arg will accept valid locales, an array of locales, as well as `none` to disable falling back.
203
203
204
204
**Example:**
205
205
@@ -224,7 +224,7 @@ query {
224
224
225
225
You can specify `locale` as well as `fallbackLocale` within the Local API as well as properties on the `options`
226
226
argument. The `locale` property will accept any valid locale, and the `fallbackLocale` property will accept any valid
227
-
locale as well as `'null'`, `'false'`, `false`, and `'none'`.
227
+
locale, array of locales, as well as `'null'`, `'false'`, `false`, and `'none'`.
Copy file name to clipboardExpand all lines: docs/local-api/overview.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,7 @@ You can specify more options within the Local API vs. REST or GraphQL due to the
71
71
|`locale`| Specify [locale](/docs/configuration/localization) for any returned documents. |
72
72
|`select`| Specify [select](../queries/select) to control which fields to include to the result. |
73
73
|`populate`| Specify [populate](../queries/select#populate) to control which fields to include to the result from populated documents. |
74
-
|`fallbackLocale`| Specify a [fallback locale](/docs/configuration/localization) to use for any returned documents. |
74
+
|`fallbackLocale`| Specify a [fallback locale](/docs/configuration/localization) to use for any returned documents. This can be a single locale or array of locales.|
75
75
|`overrideAccess`| Skip access control. By default, this property is set to true within all Local API operations. |
76
76
|`overrideLock`| By default, document locks are ignored (`true`). Set to `false` to enforce locks and prevent operations when a document is locked by another user. [More details](../admin/locked-documents). |
77
77
|`user`| If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks. |
0 commit comments