Skip to content

Commit 18e2d2c

Browse files
committed
chore: updates multipleFallbackLocales to an experimental feature
1 parent b8898ee commit 18e2d2c

File tree

8 files changed

+32
-16
lines changed

8 files changed

+32
-16
lines changed

docs/configuration/localization.mdx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ The locale codes do not need to be in any specific format. It's up to you to def
9393

9494
#### Locale Object
9595

96-
| Option | Description |
97-
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
98-
| **`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. |
96+
| Option | Description |
97+
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
98+
| **`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. You can enable `experimental.multipleFallbackLocales` to allow an array of locales. |
102102

103103
_\* An asterisk denotes that a property is required._
104104

@@ -150,9 +150,10 @@ export default buildConfig({
150150

151151
The following experimental options are available related to localization:
152152

153-
| Option | Description |
154-
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
155-
| **`localizeStatus`** | **Boolean.** When `true`, shows document status per locale in the admin panel instead of always showing the latest overall status. Opt-in for backwards compatibility. Defaults to `false`. |
153+
| Option | Description |
154+
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
155+
| **`localizeStatus`** | **Boolean.** When `true`, shows document status per locale in the admin panel instead of always showing the latest overall status. Opt-in for backwards compatibility. Defaults to `false`. |
156+
| **`multipleFallbackLocales`** | **Boolean.** When `true`, allows `fallbackLocale` to accept an array of locales in find queries and locale configuration. Defaults to `false`. |
156157

157158
## Field Localization
158159

@@ -222,7 +223,7 @@ The `locale` arg will only accept valid locales, but locales will be formatted a
222223
values (dashes or special characters will be converted to underscores, spaces will be removed, etc.). If you are curious
223224
to see how locales are auto-formatted, you can use the [GraphQL playground](/docs/graphql/overview#graphql-playground).
224225

225-
The `fallbackLocale` arg will accept valid locales, an array of locales, as well as `none` to disable falling back.
226+
The `fallbackLocale` arg will accept valid locales as well as `none` to disable falling back.
226227

227228
**Example:**
228229

@@ -247,7 +248,7 @@ query {
247248

248249
You can specify `locale` as well as `fallbackLocale` within the Local API as well as properties on the `options`
249250
argument. The `locale` property will accept any valid locale, and the `fallbackLocale` property will accept any valid
250-
locale, array of locales, as well as `'null'`, `'false'`, `false`, and `'none'`.
251+
locale as well as `'null'`, `'false'`, `false`, and `'none'`.
251252

252253
**Example:**
253254

docs/local-api/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ You can specify more options within the Local API vs. REST or GraphQL due to the
7171
| `locale` | Specify [locale](/docs/configuration/localization) for any returned documents. |
7272
| `select` | Specify [select](../queries/select) to control which fields to include to the result. |
7373
| `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. This can be a single locale or array of locales. |
74+
| `fallbackLocale` | Specify a [fallback locale](/docs/configuration/localization) to use for any returned documents. |
7575
| `overrideAccess` | Skip access control. By default, this property is set to true within all Local API operations. |
7676
| `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). |
7777
| `user` | If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks. |

packages/payload/src/config/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ export const createClientConfig = ({
229229
if (config.experimental?.localizeStatus) {
230230
clientConfig.experimental.localizeStatus = config.experimental.localizeStatus
231231
}
232+
if (config.experimental?.multipleFallbackLocales) {
233+
clientConfig.experimental.multipleFallbackLocales =
234+
config.experimental.multipleFallbackLocales
235+
}
232236
}
233237

234238
break

packages/payload/src/config/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,10 @@ export type ImportMapGenerators = Array<
732732
*/
733733
export type ExperimentalConfig = {
734734
localizeStatus?: boolean
735+
/**
736+
* When true, fallbackLocale accepts an array of locales in find queries and locale configuration.
737+
*/
738+
multipleFallbackLocales?: boolean
735739
}
736740

737741
export type AfterErrorHook = (

packages/payload/src/fields/hooks/afterRead/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export async function afterRead<T extends JsonObject>(args: AfterReadArgs<T>): P
8181
depth,
8282
doc: incomingDoc,
8383
draft,
84+
experimental: req.payload.config.experimental,
8485
fallbackLocale,
8586
fieldPromises,
8687
fields: (collection?.fields || global?.fields)!,

packages/payload/src/fields/hooks/afterRead/promise.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { RichTextAdapter } from '../../../admin/RichText.js'
22
import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'
33
import type { SanitizedGlobalConfig } from '../../../globals/config/types.js'
4+
import type { ExperimentalConfig, RequestContext } from '../../../index.js'
45
import type {
56
JsonObject,
67
PayloadRequest,
@@ -12,7 +13,6 @@ import type { Block, Field, TabAsField } from '../../config/types.js'
1213
import type { AfterReadArgs } from './index.js'
1314

1415
import { MissingEditorProp } from '../../../errors/index.js'
15-
import { type RequestContext } from '../../../index.js'
1616
import { getBlockSelect } from '../../../utilities/getBlockSelect.js'
1717
import { stripUnselectedFields } from '../../../utilities/stripUnselectedFields.js'
1818
import { fieldAffectsData, fieldShouldBeLocalized, tabHasName } from '../../config/types.js'
@@ -33,6 +33,7 @@ type Args = {
3333
depth: number
3434
doc: JsonObject
3535
draft: boolean
36+
experimental?: ExperimentalConfig
3637
fallbackLocale: null | string
3738
field: Field | TabAsField
3839
fieldIndex: number
@@ -79,6 +80,7 @@ export const promise = async ({
7980
depth,
8081
doc,
8182
draft,
83+
experimental,
8284
fallbackLocale,
8385
field,
8486
fieldIndex,
@@ -160,8 +162,8 @@ export const promise = async ({
160162
if (fallbackLocale && fallbackLocale !== locale) {
161163
let fallbackValue
162164
const isNullOrUndefined = typeof value === 'undefined' || value === null
163-
164-
if (Array.isArray(fallbackLocale)) {
165+
console.log(experimental?.multipleFallbackLocales)
166+
if (experimental?.multipleFallbackLocales && Array.isArray(fallbackLocale)) {
165167
for (const locale of fallbackLocale) {
166168
const val = siblingDoc[field.name!]?.[locale]
167169

packages/payload/src/fields/hooks/afterRead/traverseFields.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'
22
import type { SanitizedGlobalConfig } from '../../../globals/config/types.js'
3-
import type { RequestContext } from '../../../index.js'
3+
import type { ExperimentalConfig, RequestContext } from '../../../index.js'
44
import type {
55
JsonObject,
66
PayloadRequest,
@@ -23,6 +23,7 @@ type Args = {
2323
depth: number
2424
doc: JsonObject
2525
draft: boolean
26+
experimental?: ExperimentalConfig
2627
fallbackLocale: null | string
2728
/**
2829
* fieldPromises are used for things like field hooks. They should be awaited before awaiting populationPromises
@@ -60,6 +61,7 @@ export const traverseFields = ({
6061
depth,
6162
doc,
6263
draft,
64+
experimental,
6365
fallbackLocale,
6466
fieldPromises,
6567
fields,
@@ -92,6 +94,7 @@ export const traverseFields = ({
9294
depth,
9395
doc,
9496
draft,
97+
experimental,
9598
fallbackLocale,
9699
field,
97100
fieldIndex,

test/localization/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ export default buildConfigWithDefaults({
430430
],
431431
experimental: {
432432
localizeStatus: true,
433+
multipleFallbackLocales: true,
433434
},
434435
localization: {
435436
filterAvailableLocales: ({ locales }) => {

0 commit comments

Comments
 (0)