-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace translation merge with custom function (#264)
- Loading branch information
1 parent
05cfcc4
commit b28bffa
Showing
3 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
packages/elements-react/src/context/__snapshots__/intl-context.spec.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`intl-context can override individual strings 1`] = ` | ||
<div> | ||
custom navigation title | ||
</div> | ||
`; | ||
|
||
exports[`intl-context uses default messages 1`] = ` | ||
<div> | ||
Account Settings | ||
</div> | ||
`; | ||
|
||
exports[`intl-context uses default messages in different language 1`] = ` | ||
<div> | ||
Kontoeinstellungen | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { render } from "@testing-library/react" | ||
import { IntlProvider } from "./intl-context" | ||
import { useIntl } from "react-intl" | ||
|
||
function Render({ messageId }: { messageId: string }) { | ||
const intl = useIntl() | ||
return intl.formatMessage({ id: messageId }) | ||
} | ||
|
||
describe("intl-context", () => { | ||
test("uses default messages", () => { | ||
const { container } = render( | ||
<IntlProvider locale="en"> | ||
<Render messageId="settings.navigation.title" /> | ||
</IntlProvider>, | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
test("can override individual strings", () => { | ||
const { container } = render( | ||
<IntlProvider | ||
locale="en" | ||
customTranslations={{ | ||
en: { | ||
"settings.navigation.title": "custom navigation title", | ||
}, | ||
}} | ||
> | ||
<Render messageId="settings.navigation.title" /> | ||
</IntlProvider>, | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
|
||
test("uses default messages in different language", () => { | ||
const { container } = render( | ||
<IntlProvider locale="de"> | ||
<Render messageId="settings.navigation.title" /> | ||
</IntlProvider>, | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters