Skip to content

Commit 18f9f35

Browse files
authored
fix(ui): copy to locale incorrect label when locale label is defined as object (#9705)
Fixes #9701 ### What? Previously, when defining `localization.locales` like this: ```ts localization: { defaultLocale: 'en', locales: [{ label: { en: 'ESLocale' }, code: 'es' },{ label: { en: 'ESLocale' }, code: 'en' }], }, ``` The title in "copy to locale" modal was displayed incorrectly ``` Copy to locale: Copying from [object Object] to [object Object] ``` ### How? Uses the `getTranslation` function to handle this behavior properly
1 parent 7bd1a16 commit 18f9f35

File tree

1 file changed

+4
-4
lines changed
  • packages/ui/src/elements/CopyLocaleData

1 file changed

+4
-4
lines changed

packages/ui/src/elements/CopyLocaleData/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22

33
import { useModal } from '@faceless-ui/modal'
4+
import { getTranslation } from '@payloadcms/translations'
45
import { useRouter } from 'next/navigation.js'
56
import React, { useCallback } from 'react'
67
import { toast } from 'sonner'
@@ -16,8 +17,8 @@ import { useTranslation } from '../../providers/Translation/index.js'
1617
import { DrawerHeader } from '../BulkUpload/Header/index.js'
1718
import { Button } from '../Button/index.js'
1819
import { Drawer } from '../Drawer/index.js'
19-
import { PopupList } from '../Popup/index.js'
2020
import './index.scss'
21+
import { PopupList } from '../Popup/index.js'
2122

2223
const baseClass = 'copy-locale-data'
2324

@@ -32,7 +33,7 @@ export const CopyLocaleData: React.FC = () => {
3233
} = useConfig()
3334
const { code } = useLocale()
3435
const { id, collectionSlug, globalSlug } = useDocumentInfo()
35-
const { t } = useTranslation()
36+
const { i18n, t } = useTranslation()
3637
const modified = useFormModified()
3738
const { toggleModal } = useModal()
3839
const { copyDataFromLocale } = useServerFunctions()
@@ -47,7 +48,7 @@ export const CopyLocaleData: React.FC = () => {
4748

4849
const getLocaleLabel = (code: string) => {
4950
const locale = localization && localization.locales.find((l) => l.code === code)
50-
return locale && locale.label ? locale.label : code
51+
return locale && locale.label ? getTranslation(locale.label, i18n) : code
5152
}
5253

5354
const [copying, setCopying] = React.useState(false)
@@ -57,7 +58,6 @@ export const CopyLocaleData: React.FC = () => {
5758

5859
React.useEffect(() => {
5960
if (fromLocale !== code) {
60-
// eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
6161
setFromLocale(code)
6262
}
6363
}, [code, fromLocale])

0 commit comments

Comments
 (0)