Skip to content

Commit

Permalink
feat(i18n): add localization for UnknownPaneType (#5019)
Browse files Browse the repository at this point in the history
* feat(i18n): add localization for UnknownPaneType

* feat(i18n): disable no-literal-string lint rule for __workshop__

* feat(i18n): disable no-literal-string lint rule for timeline/__workshop__

* feat(i18n): fix to properly style code elements with translation
  • Loading branch information
jtpetty authored and bjoerge committed Nov 27, 2023
1 parent 00fc77a commit 4aea437
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 10 additions & 0 deletions packages/sanity/src/desk/i18n/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ const deskLocaleStrings = {

/** --- "PRODUCTION PREVIEW", eg link to content --- */
'production-preview.menu-item.title': 'Open preview',

/** -- UNKNOWN PANE TYPE */

/** The text to display when type is missing */
'panes.unknown-pane-type.missing-type.text':
'Structure item is missing required <Code>type</Code> property.',

/** The text to display when type is unknown */
'panes.unknown-pane-type.unknown-type.text':
'Structure item of type <Code>{{type}}</Code> is not a known entity.',
}

/**
Expand Down
18 changes: 14 additions & 4 deletions packages/sanity/src/desk/panes/unknown/UnknownPaneType.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Box, Text} from '@sanity/ui'
import React from 'react'
import {Pane, PaneContent, PaneHeader} from '../../components/pane'
import {isRecord} from 'sanity'
import {deskLocaleNamespace} from '../../i18n'
import {isRecord, Translate, useTranslation} from 'sanity'

interface UnknownPaneProps {
isSelected: boolean
Expand All @@ -15,19 +16,28 @@ interface UnknownPaneProps {
export function UnknownPane(props: UnknownPaneProps) {
const {isSelected, pane, paneKey} = props
const type = (isRecord(pane) && pane.type) || null

const {t} = useTranslation(deskLocaleNamespace)
return (
<Pane id={paneKey} selected={isSelected}>
<PaneHeader title="Unknown pane type" />
<PaneContent>
<Box padding={4}>
{typeof type === 'string' ? (
<Text as="p" muted>
Structure item of type <code>{type}</code> is not a known entity.
<Translate
t={t}
i18nKey="panes.unknown-pane-type.unknown-type.text"
components={{Code: ({children}) => <code>{children}</code>}}
values={{type}}
/>
</Text>
) : (
<Text as="p" muted>
Structure item is missing required <code>type</code> property.
<Translate
t={t}
i18nKey="panes.unknown-pane-type.missing-type.text"
components={{Code: ({children}) => <code>{children}</code>}}
/>
</Text>
)}
</Box>
Expand Down

0 comments on commit 4aea437

Please sign in to comment.