-
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.
use htmr to parse html inside json files
- Loading branch information
1 parent
b362468
commit 45124c8
Showing
11 changed files
with
82 additions
and
99 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,26 @@ | ||
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 | ||
} | ||
|
||
const transform = { | ||
a: Link, | ||
} | ||
|
||
// 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} /> | ||
const Translation = ({ id, ...rest }: Props) => { | ||
const { t } = useTranslation() | ||
|
||
const translatedText = t(id) | ||
|
||
// @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