-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8592 from ethereum/i18n-parse-html-json
i18n lib change - use htmr to parse html inside json files #8585
- Loading branch information
Showing
11 changed files
with
87 additions
and
101 deletions.
There are no files selected for viewing
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
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
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
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
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 |
---|---|---|
@@ -1,12 +1,29 @@ | ||
import React from "react" | ||
import { Trans } from "gatsby-plugin-react-i18next" | ||
import { useTranslation } from "gatsby-plugin-react-i18next" | ||
import htmr from "htmr" | ||
|
||
interface Props extends React.ComponentProps<typeof Trans> { | ||
import Link from "./Link" | ||
|
||
interface Props { | ||
id: string | ||
} | ||
|
||
// Wrapper on <FormattedHTMLMessage /> to always fallback to English | ||
// Use this component for any user-facing string | ||
const Translation = ({ id, ...rest }: Props) => <Trans i18nKey={id} {...rest} /> | ||
// Custom components mapping to be used by `htmr` when parsing the translation | ||
// text | ||
const transform = { | ||
a: Link, | ||
} | ||
|
||
// Renders the translation string for the given translation key `id`. It | ||
// fallback to English if it doesn't find the given key in the current language | ||
const Translation = ({ id }: Props) => { | ||
const { t } = useTranslation() | ||
|
||
const translatedText = t(id) | ||
|
||
// Use `htmr` to parse html content in the translation text | ||
// @ts-ignore | ||
return <>{htmr(translatedText, { transform })}</> | ||
} | ||
|
||
export default Translation |
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
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
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
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
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
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