From 51efe4f39bcaadccb109a2a02a690ca65041ee57 Mon Sep 17 00:00:00 2001 From: Jessica Chowdhury <67977755+JessChowdhury@users.noreply.github.com> Date: Tue, 14 May 2024 15:45:39 +0100 Subject: [PATCH] fix: collection labels with locales not working when creating new doc (#5995) --- .../components/elements/DocumentControls/index.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/payload/src/admin/components/elements/DocumentControls/index.tsx b/packages/payload/src/admin/components/elements/DocumentControls/index.tsx index 4b2a30a0e2..305dd5e252 100644 --- a/packages/payload/src/admin/components/elements/DocumentControls/index.tsx +++ b/packages/payload/src/admin/components/elements/DocumentControls/index.tsx @@ -5,6 +5,7 @@ import type { CollectionPermission, GlobalPermission } from '../../../../auth' import type { SanitizedCollectionConfig } from '../../../../collections/config/types' import type { SanitizedGlobalConfig } from '../../../../globals/config/types' +import { getTranslation } from '../../../../utilities/getTranslation' import { formatDate } from '../../../utilities/formatDate' import { useConfig } from '../../utilities/Config' import { useDocumentInfo } from '../../utilities/DocumentInfo' @@ -63,6 +64,12 @@ export const DocumentControls: React.FC<{ collection && id && !disableActions && (hasCreatePermission || hasDeletePermission), ) + const collectionLabel = () => { + const label = collection?.labels?.singular + if (!label) return t('document') + return typeof label === 'string' ? label : getTranslation(label, i18n) + } + return (
@@ -71,12 +78,7 @@ export const DocumentControls: React.FC<{ {collection && !isEditing && !isAccountView && (
  • - {t('creatingNewLabel', { - label: - typeof collection?.labels?.singular === 'string' - ? collection.labels.singular - : t('document'), - })} + {t('creatingNewLabel', { label: collectionLabel() })}

  • )}