From 007bb9b1d65e1da0367168888d8cb7a6e13e14b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Fri, 13 Oct 2023 05:48:33 +0200 Subject: [PATCH] feat(i18n): convert document actions strings to use i18n primitives (#4968) --- .../plugins/locale-no-nb/bundles/desk.ts | 98 ++++++++++++++++--- .../src/desk/documentActions/DeleteAction.tsx | 20 ++-- .../documentActions/DiscardChangesAction.tsx | 26 ++--- .../desk/documentActions/DuplicateAction.tsx | 18 ++-- .../documentActions/HistoryRestoreAction.tsx | 17 ++-- .../desk/documentActions/PublishAction.tsx | 12 +-- .../desk/documentActions/UnpublishAction.tsx | 15 +-- packages/sanity/src/desk/i18n/resources.ts | 96 +++++++++++++++--- 8 files changed, 232 insertions(+), 70 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..ca4e6a77d16d 100644 --- a/dev/test-studio/plugins/locale-no-nb/bundles/desk.ts +++ b/dev/test-studio/plugins/locale-no-nb/bundles/desk.ts @@ -1,7 +1,11 @@ import type {DeskLocaleResourceKeys} from 'sanity/desk' const deskResources: Record = { - /** Label for the "Publish" document action when there are pending changes.*/ + /** --- PUBLISH ACTION --- */ + /** Tooltip when action is disabled because the studio is not ready.*/ + 'action.publish.disabled.not-ready': 'Operasjonen er ikke klar', + + /** Label for action when there are pending changes.*/ 'action.publish.draft.label': 'Publiser', /** Label for the "Publish" document action while publish is being executed.*/ @@ -11,34 +15,104 @@ const deskResources: Record = { 'action.publish.published.label': 'Publisert', /** Label for the "Publish" document action when the document has live edit enabled.*/ - 'action.publish.liveEdit.label': 'Publiser', + 'action.publish.live-edit.label': 'Publiser', /** Tooltip for the "Publish" document action when the document has live edit enabled.*/ - 'action.publish.liveEdit.tooltip': + 'action.publish.live-edit.tooltip': '"Live Edit" er skrudd på for denne dokumenttypen og publisering skjer automatisk når du gjør endringer', /** Fallback tooltip for the "Publish" document action when publish is invoked for a document with live edit enabled.*/ - 'action.publish.liveEdit.publishDisabled': - 'Kan ikke publsere fordi liveEdit er skrudd på for denne dokumenttypen.', + 'action.publish.live-edit.publish-disabled': + 'Kan ikke publisere fordi "Live Edit" er skrudd på for denne dokumenttypen.', /** Tooltip when the "Publish" document action is disabled due to validation issues */ - 'action.publish.validationIssues.tooltip': + 'action.publish.validation-issues.tooltip': 'Valideringsfeil som må rettes før dokumentet kan publiseres', /** Tooltip when publish button is disabled because the document is already published.*/ - 'action.publish.alreadyPublished.tooltip': 'Publisert for {{timeSincePublished}} siden', + 'action.publish.already-published.tooltip': 'Publisert for {{timeSincePublished}} siden', /** Tooltip when publish button is disabled because the document is already published, and published time is unavailable.*/ - 'action.publish.alreadyPublished.noTimeAgo.tooltip': 'Allerede publisert', + 'action.publish.already-published.no-time-ago.tooltip': 'Allerede publisert', /** Tooltip when publish button is disabled because there are no changes.*/ - 'action.publish.tooltip.noChanges': 'Ingen upubliserte endringer', - - /** Tooltip when publish button is disabled because the studio is not ready.*/ - 'action.publish.disabled.notReady': 'Operasjonen er ikke klar', + 'action.publish.tooltip.no-changes': 'Ingen upubliserte endringer', /** 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 action button is disabled because the operation is not ready */ + 'action.delete.disabled.not-ready': 'Operasjonen er ikke klar', + + /** Tooltip when action button is disabled because the document does not exist */ + 'action.delete.disabled.nothing-to-delete': + 'Dette dokumentet eksisterer ikke eller har allerede blitt slettet', + + /** Label for the "Delete" document action button */ + 'action.delete.label': 'Slett', + + /** Label for the "Delete" document action while the document is being deleted */ + 'action.delete.running.label': 'Sletter…', + + /** --- DISCARD CHANGES ACTION --- **/ + /** Tooltip when action button is disabled because the operation is not ready */ + 'action.discard-changes.disabled.not-ready': 'Operasjonen er ikke klar', + + /** Label for the "Discard changes" document action */ + 'action.discard-changes.label': 'Forkast endringer', + + /** Tooltip when action is disabled because the document has no unpublished changes */ + 'action.discard-changes.disabled.no-change': 'Dette dokumentet har ingen endringer', + + /** Tooltip when action is disabled because the document is not published */ + 'action.discard-changes.disabled.not-published': 'Dette dokumentet er ikke publisert', + + /** Message prompting the user to confirm discarding changes */ + 'action.discard-changes.confirm-dialog.confirm-discard-changes': + 'Er du sikker på at du vil forkaste alle endringer siden forrige gang dette dokumentet ble publisert?', + + /** --- DUPLICATE ACTION --- */ + /** Tooltip when action is disabled because the operation is not ready */ + 'action.duplicate.disabled.not-ready': 'Operasjonen er ikke klar', + + /** Tooltip when action is disabled because the document doesn't exist */ + 'action.duplicate.disabled.nothing-to-duplicate': + 'Dette dokumentet er tomt og kan ikke dupliseres', + + /** Label for the "Duplicate" document action */ + 'action.duplicate.label': 'Duplisèr', + + /** Label for the "Duplicate" document action while the document is being duplicated */ + 'action.duplicate.running.label': 'Duplisèrer…', + + /** --- UNPUBLISH ACTION --- */ + /** Tooltip when action is disabled because the operation is not ready */ + 'action.unpublish.disabled.not-ready': 'Operasjonen er ikke klar', + + /** Label for the "Unpublish" document action */ + 'action.unpublish.label': 'Avpubliser', + + /** Tooltip when action is disabled because the document is not already published */ + 'action.unpublish.disabled.not-published': 'Dette dokumentet er ikke publisert', + + /** Fallback tooltip for the Unpublish document action when publish is invoked for a document with live edit enabled.*/ + 'action.unpublish.live-edit.disabled': + 'Dette dokumentet har "Live Edit" skrudd på og kan ikke avpubliseres', + + /** --- RESTORE ACTION --- */ + /** Label for the "Restore" document action */ + 'action.restore.label': 'Gjenopprett', + + /** Fallback tooltip for when user is looking at the initial version */ + 'action.restore.disabled.cannot-restore-initial': 'Kan ikke gjenopprette til første version', + + /** Default tooltip for the action */ + 'action.restore.tooltip': 'Gjenopprett til denne versjonen', + + /** Message prompting the user to confirm that they want to restore to an earlier version*/ + 'action.restore.confirm-dialog.confirm-discard-changes': + 'Er du sikker på at du vil gjenopprette til valgte versjon?', } export default deskResources diff --git a/packages/sanity/src/desk/documentActions/DeleteAction.tsx b/packages/sanity/src/desk/documentActions/DeleteAction.tsx index 7f1051ecac12..e10cc2a505be 100644 --- a/packages/sanity/src/desk/documentActions/DeleteAction.tsx +++ b/packages/sanity/src/desk/documentActions/DeleteAction.tsx @@ -3,17 +3,20 @@ 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', + NOT_READY: 'action.delete.disabled.notReady', } /** @internal */ @@ -23,6 +26,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() @@ -53,7 +58,7 @@ export const DeleteAction: DocumentActionComponent = ({id, type, draft, onComple tone: 'critical', icon: TrashIcon, disabled: true, - label: 'Delete', + label: t('action.delete.label'), title: ( { discardChanges.execute() onComplete() @@ -49,9 +54,9 @@ export const DiscardChangesAction: DocumentActionComponent = ({ tone: 'critical', onCancel: onComplete, onConfirm: handleConfirm, - message: <>Are you sure you want to discard all changes since last published?, + message: t('action.discardChanges.confirmDialog.confirm-discard-changes'), }, - [handleConfirm, isConfirmDialogOpen, onComplete], + [handleConfirm, isConfirmDialogOpen, onComplete, t], ) if (!published || liveEdit) { @@ -63,7 +68,7 @@ export const DiscardChangesAction: DocumentActionComponent = ({ tone: 'critical', icon: ResetIcon, disabled: true, - label: 'Discard changes', + label: t('action.discardChanges.label'), title: ( { @@ -40,7 +45,7 @@ export const DuplicateAction: DocumentActionComponent = ({id, type, onComplete}) return { icon: CopyIcon, disabled: true, - label: 'Duplicate', + label: t('action.duplicate.label'), title: ( { restore.execute(revision!) @@ -45,12 +48,12 @@ export const HistoryRestoreAction: DocumentActionComponent = ({id, type, revisio tone: 'critical', onCancel: onComplete, onConfirm: handleConfirm, - message: <>Are you sure you want to restore this document?, + message: t('action.restore.confirm.message'), } } return null - }, [handleConfirm, isConfirmDialogOpen, onComplete]) + }, [handleConfirm, isConfirmDialogOpen, onComplete, t]) const isRevisionInitialVersion = revision === '@initial' const isRevisionLatestVersion = revision === undefined // undefined means latest version @@ -60,12 +63,14 @@ export const HistoryRestoreAction: DocumentActionComponent = ({id, type, revisio } return { - label: 'Restore', + label: t('action.restore.label'), color: 'primary', onHandle: handle, - title: isRevisionInitialVersion - ? "You can't restore to the initial version" - : 'Restore to this version', + title: t( + isRevisionInitialVersion + ? 'action.restore.disabled.cannot-restore-initial' + : 'action.restore.tooltip', + ), icon: RestoreIcon, dialog, disabled: isRevisionInitialVersion, diff --git a/packages/sanity/src/desk/documentActions/PublishAction.tsx b/packages/sanity/src/desk/documentActions/PublishAction.tsx index ac375c4b2594..0125fb27740f 100644 --- a/packages/sanity/src/desk/documentActions/PublishAction.tsx +++ b/packages/sanity/src/desk/documentActions/PublishAction.tsx @@ -18,10 +18,10 @@ import { } from 'sanity' const DISABLED_REASON_TITLE_KEY: Record = { - LIVE_EDIT_ENABLED: 'action.publish.liveEdit.publishDisabled', - ALREADY_PUBLISHED: 'action.publish.alreadyPublished.noTimeAgo.tooltip', - NO_CHANGES: 'action.publish.tooltip.noChanges', - NOT_READY: 'action.publish.disabled.notReady', + LIVE_EDIT_ENABLED: 'action.publish.live-edit.publish-disabled', + ALREADY_PUBLISHED: 'action.publish.already-published.no-time-ago.tooltip', + NO_CHANGES: 'action.publish.tooltip.no-changes', + NOT_READY: 'action.publish.disabled.not-ready', } as const function getDisabledReason( @@ -143,8 +143,8 @@ export const PublishAction: DocumentActionComponent = (props) => { if (liveEdit) { return { tone: 'positive', - label: t('action.publish.liveEdit.label'), - title: t('action.publish.liveEdit.tooltip'), + label: t('action.publish.live-edit.label'), + title: t('action.publish.live-edit.tooltip'), disabled: true, } } diff --git a/packages/sanity/src/desk/documentActions/UnpublishAction.tsx b/packages/sanity/src/desk/documentActions/UnpublishAction.tsx index 264ac3218b3c..7126125638d7 100644 --- a/packages/sanity/src/desk/documentActions/UnpublishAction.tsx +++ b/packages/sanity/src/desk/documentActions/UnpublishAction.tsx @@ -1,6 +1,7 @@ import {UnpublishIcon} from '@sanity/icons' import React, {useCallback, useMemo, useState} from 'react' import {ConfirmDeleteDialog} from '../components' +import {deskLocaleNamespace} from '../i18n' import { DocumentActionComponent, InsufficientPermissionsMessage, @@ -8,10 +9,13 @@ import { useCurrentUser, useDocumentOperation, DocumentActionModalDialogProps, + useTranslation, } from 'sanity' -const DISABLED_REASON_TITLE = { - NOT_PUBLISHED: 'This document is not published', +const DISABLED_REASON_KEY = { + NOT_PUBLISHED: 'action.unpublish.disabled.notPublished', + NOT_READY: 'action.unpublish.disabled.notReady', + LIVE_EDIT_ENABLED: 'action.unpublish.disabled.liveEditEnabled', } /** @internal */ @@ -30,6 +34,7 @@ export const UnpublishAction: DocumentActionComponent = ({ permission: 'unpublish', }) const currentUser = useCurrentUser() + const {t} = useTranslation(deskLocaleNamespace) const handleCancel = useCallback(() => { setConfirmDialogOpen(false) @@ -85,10 +90,8 @@ export const UnpublishAction: DocumentActionComponent = ({ tone: 'critical', icon: UnpublishIcon, disabled: Boolean(unpublish.disabled) || isPermissionsLoading, - label: 'Unpublish', - title: unpublish.disabled - ? DISABLED_REASON_TITLE[unpublish.disabled as keyof typeof DISABLED_REASON_TITLE] - : '', + label: t('action.unpublish.label'), + title: unpublish.disabled ? t(DISABLED_REASON_KEY[unpublish.disabled]) : '', onHandle: () => setConfirmDialogOpen(true), dialog, } diff --git a/packages/sanity/src/desk/i18n/resources.ts b/packages/sanity/src/desk/i18n/resources.ts index 8c88a89e83e3..11c11a1fb1c0 100644 --- a/packages/sanity/src/desk/i18n/resources.ts +++ b/packages/sanity/src/desk/i18n/resources.ts @@ -4,7 +4,11 @@ * @internal */ const deskLocaleStrings = { - /** Label for the "Publish" document action when there are pending changes.*/ + /** --- PUBLISH ACTION --- */ + /** Tooltip when action is disabled because the studio is not ready.*/ + 'action.publish.disabled.not-ready': 'Operation not ready', + + /** Label for action when there are pending changes.*/ 'action.publish.draft.label': 'Publish', /** Label for the "Publish" document action while publish is being executed.*/ @@ -14,34 +18,104 @@ const deskLocaleStrings = { 'action.publish.published.label': 'Published', /** Label for the "Publish" document action when the document has live edit enabled.*/ - 'action.publish.liveEdit.label': 'Publish', + 'action.publish.live-edit.label': 'Publish', /** Tooltip for the "Publish" document action when the document has live edit enabled.*/ - 'action.publish.liveEdit.tooltip': + 'action.publish.live-edit.tooltip': 'Live Edit is enabled for this content type and publishing happens automatically as you make changes', /** Fallback tooltip for the "Publish" document action when publish is invoked for a document with live edit enabled.*/ - 'action.publish.liveEdit.publishDisabled': + 'action.publish.live-edit.publish-disabled': 'Cannot publish since liveEdit is enabled for this document type', /** Tooltip when the "Publish" document action is disabled due to validation issues */ - 'action.publish.validationIssues.tooltip': + 'action.publish.validation-issues.tooltip': 'There are validation errors that need to be fixed before this document can be published', /** Tooltip when publish button is disabled because the document is already published.*/ - 'action.publish.alreadyPublished.tooltip': 'Published {{timeSincePublished}} ago', + 'action.publish.already-published.tooltip': 'Published {{timeSincePublished}} ago', /** Tooltip when publish button is disabled because the document is already published, and published time is unavailable.*/ - 'action.publish.alreadyPublished.noTimeAgo.tooltip': 'Already published', + 'action.publish.already-published.no-time-ago.tooltip': 'Already published', /** Tooltip when publish button is disabled because there are no changes.*/ - 'action.publish.tooltip.noChanges': 'No unpublished changes', - - /** Tooltip when publish button is disabled because the studio is not ready.*/ - 'action.publish.disabled.notReady': 'Operation not ready', + 'action.publish.tooltip.no-changes': 'No unpublished changes', /** 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 action button is disabled because the operation is not ready */ + 'action.delete.disabled.not-ready': 'Operation not ready', + + /** Tooltip when action button is disabled because the document does not exist */ + 'action.delete.disabled.nothing-to-delete': + 'This document doesn’t yet exist or is already deleted', + + /** Label for the "Delete" document action button */ + 'action.delete.label': 'Delete', + + /** Label for the "Delete" document action while the document is being deleted */ + 'action.delete.running.label': 'Deleting…', + + /** --- DISCARD CHANGES ACTION --- **/ + /** Tooltip when action button is disabled because the operation is not ready */ + 'action.discard-changes.disabled.not-ready': 'Operation not ready', + + /** Label for the "Discard changes" document action */ + 'action.discard-changes.label': 'Discard changes', + + /** Tooltip when action is disabled because the document has no unpublished changes */ + 'action.discard-changes.disabled.no-change': 'This document has no unpublished changes', + + /** Tooltip when action is disabled because the document is not published */ + 'action.discard-changes.disabled.not-published': 'This document is not published', + + /** Message prompting the user to confirm discarding changes */ + 'action.discard-changes.confirm-dialog.confirm-discard-changes': + 'Are you sure you want to discard all changes since last published?', + + /** --- DUPLICATE ACTION --- */ + /** Tooltip when action is disabled because the operation is not ready */ + 'action.duplicate.disabled.not-ready': 'Operation not ready', + + /** Tooltip when action is disabled because the document doesn't exist */ + 'action.duplicate.disabled.nothing-to-duplicate': + "This document doesn't yet exist so there‘s nothing to duplicate", + + /** Label for the "Duplicate" document action */ + 'action.duplicate.label': 'Duplicate', + + /** Label for the "Duplicate" document action while the document is being duplicated */ + 'action.duplicate.running.label': 'Duplicating…', + + /** --- UNPUBLISH ACTION --- */ + /** Tooltip when action is disabled because the operation is not ready */ + 'action.unpublish.disabled.not-ready': 'Operation not ready', + + /** Label for the "Unpublish" document action */ + 'action.unpublish.label': 'Unpublish', + + /** Tooltip when action is disabled because the document is not already published */ + 'action.unpublish.disabled.not-published': 'This document is not published', + + /** Fallback tooltip for the Unpublish document action when publish is invoked for a document with live edit enabled.*/ + 'action.unpublish.live-edit.disabled': + 'This document has live edit enabled and cannot be unpublished', + + /** --- RESTORE ACTION --- */ + /** Label for the "Restore" document action */ + 'action.restore.label': 'Restore', + + /** Fallback tooltip for when user is looking at the initial version */ + 'action.restore.disabled.cannot-restore-initial': "You can't restore to the initial version", + + /** Default tooltip for the action */ + 'action.restore.tooltip': 'Restore to this version', + + /** Message prompting the user to confirm that they want to restore to an earlier version*/ + 'action.restore.confirm-dialog.confirm-discard-changes': + 'Are you sure you want to restore this document?', } /**