From 8f1ea8712c6e4605527166494add804f9ebb7263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Fri, 29 Sep 2023 15:28:02 +0200 Subject: [PATCH] feat(i18n): use i18n strings in delete document action --- .../plugins/locale-no-nb/bundles/desk.ts | 15 +++++++++++++++ .../src/desk/documentActions/DeleteAction.tsx | 16 +++++++++++----- packages/sanity/src/desk/i18n/resources.ts | 14 ++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/dev/test-studio/plugins/locale-no-nb/bundles/desk.ts b/dev/test-studio/plugins/locale-no-nb/bundles/desk.ts index 3dda1fc97a0d..4d965956dc88 100644 --- a/dev/test-studio/plugins/locale-no-nb/bundles/desk.ts +++ b/dev/test-studio/plugins/locale-no-nb/bundles/desk.ts @@ -39,6 +39,21 @@ const deskResources: Record = { /** Tooltip when publish button is waiting for validation and async tasks to complete.*/ 'action.publish.waiting': 'Venter på at andre oppgaver skal fullføre', + + /** --- DELETE ACTION --- **/ + /** + * Tooltip when delete button is disabled because the document does not exist + */ + 'action.delete.disabled.nothingToDelete': + 'Dette dokumentet eksisterer ikke eller har allerede blitt slettet', + /** + * Tooltip when delete button is disabled because the document does not exist + */ + /** Label for the "Delete" document action */ + 'action.delete.label': 'Slett', + + /** Label for the "Delete" document action while the document is being deleted */ + 'action.delete.running.label': 'Sletter…', } export default deskResources diff --git a/packages/sanity/src/desk/documentActions/DeleteAction.tsx b/packages/sanity/src/desk/documentActions/DeleteAction.tsx index 7f1051ecac12..0ef15083d144 100644 --- a/packages/sanity/src/desk/documentActions/DeleteAction.tsx +++ b/packages/sanity/src/desk/documentActions/DeleteAction.tsx @@ -3,17 +3,19 @@ import {TrashIcon} from '@sanity/icons' import React, {useCallback, useState} from 'react' import {ConfirmDeleteDialog} from '../components' +import {useDocumentPane} from '../panes/document/useDocumentPane' +import {deskLocaleNamespace} from '../i18n' import { DocumentActionComponent, InsufficientPermissionsMessage, useCurrentUser, useDocumentOperation, useDocumentPairPermissions, + useTranslation, } from 'sanity' -import {useDocumentPane} from '../panes/document/useDocumentPane' -const DISABLED_REASON_TITLE = { - NOTHING_TO_DELETE: 'This document doesn’t yet exist or is already deleted', +const DISABLED_REASON_TITLE_KEY = { + NOTHING_TO_DELETE: 'action.delete.disabled.nothingToDelete', } /** @internal */ @@ -23,6 +25,8 @@ export const DeleteAction: DocumentActionComponent = ({id, type, draft, onComple const [isDeleting, setIsDeleting] = useState(false) const [isConfirmDialogOpen, setConfirmDialogOpen] = useState(false) + const {t} = useTranslation(deskLocaleNamespace) + const handleCancel = useCallback(() => { setConfirmDialogOpen(false) onComplete() @@ -69,9 +73,11 @@ export const DeleteAction: DocumentActionComponent = ({id, type, draft, onComple disabled: isDeleting || Boolean(deleteOp.disabled) || isPermissionsLoading, title: (deleteOp.disabled && - DISABLED_REASON_TITLE[deleteOp.disabled as keyof typeof DISABLED_REASON_TITLE]) || + t( + DISABLED_REASON_TITLE_KEY[deleteOp.disabled as keyof typeof DISABLED_REASON_TITLE_KEY], + )) || '', - label: isDeleting ? 'Deleting…' : 'Delete', + label: isDeleting ? t('action.deleting.label') : t('action.delete.label'), shortcut: 'Ctrl+Alt+D', onHandle: handle, dialog: isConfirmDialogOpen && { diff --git a/packages/sanity/src/desk/i18n/resources.ts b/packages/sanity/src/desk/i18n/resources.ts index 8c88a89e83e3..e9c14c0b1b0a 100644 --- a/packages/sanity/src/desk/i18n/resources.ts +++ b/packages/sanity/src/desk/i18n/resources.ts @@ -42,6 +42,20 @@ const deskLocaleStrings = { /** Tooltip when publish button is waiting for validation and async tasks to complete.*/ 'action.publish.waiting': 'Waiting for tasks to finish before publishing', + + /** --- DELETE ACTION --- **/ + /** + * Tooltip when delete button is disabled because the document does not exist + */ + 'action.delete.disabled.nothingToDelete': 'This document doesn’t yet exist or is already deleted', + /** + * Tooltip when delete button is disabled because the document does not exist + */ + /** Label for the "Delete" document action */ + 'action.delete.label': 'Delete', + + /** Label for the "Delete" document action while the document is being deleted */ + 'action.delete.running.label': 'Deleting…', } /**