Skip to content

Commit

Permalink
refactor(i18n): make components prop required for <Translate>
Browse files Browse the repository at this point in the history
Rationale: We prefer that people use the `useTranslation` hook instead,
as it has a lower overhead. The only two use cases we're tailoring for
is when you need to use React components as part of the translation resource,
or you are using a non-functional component and thus cannot use hooks.
  • Loading branch information
rexxars committed Oct 5, 2023
1 parent 1374639 commit 3b9c357
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/sanity/src/core/i18n/Translate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ComponentMap = Record<string, ComponentType<{children?: ReactNode}>>
export interface TranslationProps {
t: TFunction
i18nKey: string
components?: ComponentMap
components: ComponentMap
values?: Record<string, string | string[]>
}

Expand Down
4 changes: 2 additions & 2 deletions packages/sanity/src/core/i18n/__tests__/Translate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ describe('Translate component', () => {
it('it translates a key', async () => {
const {findByTestId} = render(
<TestProviders bundles={[createBundle({title: 'English title'})]}>
<TestComponent i18nKey="title" />
<TestComponent i18nKey="title" components={{}} />
</TestProviders>,
)
expect((await findByTestId('output')).innerHTML).toEqual('English title')
})
it('it renders the key as-is if translation is missing', async () => {
const {findByTestId} = render(
<TestProviders bundles={[createBundle({title: 'English title'})]}>
<TestComponent i18nKey="does-not-exist" />
<TestComponent i18nKey="does-not-exist" components={{}} />
</TestProviders>,
)
expect((await findByTestId('output')).innerHTML).toEqual('does-not-exist')
Expand Down

0 comments on commit 3b9c357

Please sign in to comment.