From 1b7e45b03bf5f043b5ebefb3d6a4ef812678efe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Fri, 13 Oct 2023 05:50:30 +0200 Subject: [PATCH] feat(i18n): convert file, image and imagetool input strings to use i18n primitives (#4984) --- .../plugins/locale-no-nb/bundles/studio.ts | 109 ++++++++++++++++++ .../FileInput/__tests__/fileInput.test.tsx | 8 +- .../files/ImageInput/ImageActionsMenu.tsx | 6 +- .../inputs/files/ImageInput/ImageInput.tsx | 16 +-- .../inputs/files/ImageInput/ImagePreview.tsx | 23 ++-- .../files/ImageInput/InvalidImageWarning.tsx | 9 +- .../files/ImageToolInput/ImageToolInput.tsx | 6 +- .../form/inputs/files/common/ActionsMenu.tsx | 33 ++++-- .../form/inputs/files/common/DropMessage.tsx | 16 +-- .../inputs/files/common/PlaceholderText.tsx | 21 ++-- .../inputs/files/common/UploadPlaceholder.tsx | 1 + .../inputs/files/common/UploadProgress.tsx | 19 +-- .../inputs/files/common/UploadWarning.tsx | 18 ++- .../src/core/form/inputs/files/constants.ts | 6 + .../form/studio/inputs/StudioImageInput.tsx | 3 + .../sanity/src/core/i18n/bundles/studio.ts | 105 +++++++++++++++++ .../sanity/test/form/renderImageInput.tsx | 1 + 17 files changed, 335 insertions(+), 65 deletions(-) create mode 100644 packages/sanity/src/core/form/inputs/files/constants.ts diff --git a/dev/test-studio/plugins/locale-no-nb/bundles/studio.ts b/dev/test-studio/plugins/locale-no-nb/bundles/studio.ts index 8c48f5bd90e6..4a1c0f79feda 100644 --- a/dev/test-studio/plugins/locale-no-nb/bundles/studio.ts +++ b/dev/test-studio/plugins/locale-no-nb/bundles/studio.ts @@ -262,6 +262,115 @@ const studioResources: Record = { /** Error label for toast when array could not resolve the initial value */ 'inputs.array.error.cannot-resolve-initial-value-title': 'Kan ikke finne startverdi for type: {{schemaTypeTitle}}: {{errorMessage}}.', + + /** --- File (Image, File and ImageTool) Inputs --- */ + + /** Open image edit dialog */ + 'inputs.files.image.actions-menu.edit-details.label': 'Åpne bilderedigeringsdialog', + + /** Open image options menu */ + 'inputs.files.image.actions-menu.options.label': 'Åpne bildeinnstillingsmeny', + + /** The upload could not be completed at this time. */ + 'inputs.files.image.upload-error.description': + 'Opplastingen kunne ikke fullføres på dette tidspunktet.', + + /** Upload failed */ + 'inputs.files.image.upload-error.title': 'Opplasting mislyktes', + + /** Edit hotspot and crop */ + 'inputs.files.image.hotspot-dialog.title': 'Rediger fokuspunkt og beskjær', + + /** Preview of uploaded image */ + 'inputs.files.image.preview-uploaded-image': 'Forhåndsvisning av opplastet bilde', + + /** Cannot upload this file here */ + 'inputs.files.image.drag-overlay.cannot-upload-here': 'Kan ikke laste opp denne filen her', + + /** This field is read only */ + 'inputs.files.image.drag-overlay.this-field-is-read-only': 'Dette feltet er skrivebeskyttet', + + /** Drop image to upload */ + 'inputs.files.image.drag-overlay.drop-to-upload-image': 'Slipp bilde for å laste opp', + + /** Invalid image value */ + 'inputs.files.image.invalid-image-warning.title': 'Ugyldig bildeverdi', + + /** The value of this field is not a valid image. Resetting this field will let you choose a new image. */ + 'inputs.files.image.invalid-image-warning.description': + 'Verdien i dette feltet er ikke et gyldig bilde. Ved å tilbakestille dette feltet kan du velge et nytt bilde.', + + /** The URL is copied to the clipboard */ + 'inputs.files.common.actions-menu.notification.url-copied': + 'URL-en er kopiert til utklippstavlen', + + /** Replace */ + 'inputs.files.common.actions-menu.replace.label': 'Erstatt', + + /** Upload */ + 'inputs.files.common.actions-menu.upload.label': 'Last opp', + + /** Download */ + 'inputs.files.common.actions-menu.download.label': 'Last ned', + + /** Copy URL */ + 'inputs.files.common.actions-menu.copy-url.label': 'Kopier URL', + + /** Clear field */ + 'inputs.files.common.actions-menu.clear-field.label': 'Tøm felt', + + /** Can't upload files here */ + 'inputs.files.common.placeholder.upload-not-supported': 'Kan ikke laste opp filer her', + + /** Read only */ + 'inputs.files.common.placeholder.read-only': 'Skrivebeskyttet', + + /** Drop to upload file */ + 'inputs.files.common.placeholder.drop-to-upload_file': 'Slipp for å laste opp fil', + + /** Drop to upload image */ + 'inputs.files.common.placeholder.drop-to-upload_image': 'Slipp for å laste opp bilde', + + /** Cannot upload `{{count}}` files */ + 'inputs.files.common.placeholder.cannot-upload-some-files_one': 'Kan ikke laste opp fil', + 'inputs.files.common.placeholder.cannot-upload-some-files_other': + 'Kan ikke laste opp {{count}} filer', + + /** Drag or paste file here */ + 'inputs.files.common.placeholder.drag-or-paste-to-upload_file': 'Dra eller lim inn fil her', + /** Drag or paste image here */ + 'inputs.files.common.placeholder.drag-or-paste-to-upload_image': 'Dra eller lim inn bilde her', + + /** Drop to upload */ + 'inputs.files.common.drop-message.drop-to-upload': 'Slipp for å laste opp', + + /** Drop to upload `{{count}}` file */ + 'inputs.files.common.drop-message.drop-to-upload-multi_one': + 'Slipp for å laste opp {{count}} fil', + + /** Drop to upload `{{count}}` files */ + 'inputs.files.common.drop-message.drop-to-upload-multi_other': + 'Slipp for å laste opp {{count}} filer', + + /** Uploading */ + 'input.files.common.upload-progress': 'Laster opp ', + + /** Incomplete upload */ + 'inputs.files.common.stale-upload-warning.title': 'Ufullstendig opplasting', + + /** An upload has made no progress for at least `{{staleThresholdMinutes}}` minutes and likely got interrupted. You can safely clear the incomplete upload and try uploading again. */ + 'inputs.files.common.stale-upload-warning.description': + 'En opplasting har ikke gjort fremskritt på minst {{staleThresholdMinutes}} minutter og ble sannsynligvis avbrutt. Du kan trygt fjerne den ufullstendige opplastingen og prøve å laste opp på nytt.', + + /** Clear upload */ + 'inputs.files.common.stale-upload-warning.clear': 'Fjern opplasting', + + /** Hotspot & Crop */ + 'inputs.files.imagetool.field.title': 'Fokuspunkt & beskjæring', + + /** Adjust the rectangle to crop image. Adjust the circle to specify the area that should always be visible. */ + 'inputs.files.imagetool.field.description': + 'Juster rektangelet for å beskjære bildet. Juster sirkelen for å spesifisere området som alltid skal være synlig.', } export default studioResources diff --git a/packages/sanity/src/core/form/inputs/files/FileInput/__tests__/fileInput.test.tsx b/packages/sanity/src/core/form/inputs/files/FileInput/__tests__/fileInput.test.tsx index 72ffe8edf274..d7aaf58479c9 100644 --- a/packages/sanity/src/core/form/inputs/files/FileInput/__tests__/fileInput.test.tsx +++ b/packages/sanity/src/core/form/inputs/files/FileInput/__tests__/fileInput.test.tsx @@ -28,9 +28,7 @@ describe('FileInput with empty state', () => { observeAsset: observeAssetStub, render: (inputProps) => , }) - expect(result.queryByTestId('file-button-input')!.getAttribute('value')).toBe('') - expect(result.queryByText('Drag or paste file here')).toBeInTheDocument() }) it.todo('renders new file when a new file in uploaded') @@ -127,7 +125,9 @@ describe('FileInput with empty state', () => { render: (inputProps) => , }) - expect(result.queryByText(`Can't upload files here`)).toBeInTheDocument() + expect(result.queryByTestId('file-input-upload-button')!.getAttribute('data-disabled')).toBe( + 'true', + ) }) /* readOnly - the file input is read only or not */ @@ -184,7 +184,7 @@ describe('FileInput with empty state', () => { }) await waitFor(() => { - expect(result.queryByText(`Read only`)).toBeInTheDocument() + expect(result.queryByText(`inputs.files.common.placeholder.read-only`)).toBeInTheDocument() }) }) diff --git a/packages/sanity/src/core/form/inputs/files/ImageInput/ImageActionsMenu.tsx b/packages/sanity/src/core/form/inputs/files/ImageInput/ImageActionsMenu.tsx index 93a02fad7909..032cf5211ffd 100644 --- a/packages/sanity/src/core/form/inputs/files/ImageInput/ImageActionsMenu.tsx +++ b/packages/sanity/src/core/form/inputs/files/ImageInput/ImageActionsMenu.tsx @@ -2,6 +2,7 @@ import React, {MouseEventHandler, ReactNode, useCallback, useEffect, useState} f import {EllipsisVerticalIcon, CropIcon} from '@sanity/icons' import {Button, Inline, Menu, Popover, useClickOutside, useGlobalKeyDown} from '@sanity/ui' import styled from 'styled-components' +import {useTranslation} from '../../../../i18n' export const MenuActionsWrapper = styled(Inline)` position: absolute; @@ -79,11 +80,12 @@ export function ImageActionsMenu(props: ImageActionsMenuProps) { } }, [isMenuOpen, menuElement]) + const {t} = useTranslation() return ( {showEdit && (