-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add react-i18next with ICU (#183)
- Loading branch information
Sean Scully
committed
Feb 6, 2024
1 parent
78ac7d3
commit fde0ce6
Showing
9 changed files
with
155 additions
and
2 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
8 changes: 7 additions & 1 deletion
8
packages/frontend-design-poc/src/components/HelloWorld/HelloWorld.tsx
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,18 @@ | ||
import styles from "./helloWorld.module.css"; | ||
import { useQuery } from "react-query"; | ||
import { getUser } from "../../api/queries.ts"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
export const HelloWorld = () => { | ||
const { isLoading, data } = useQuery("user", getUser); | ||
const { t } = useTranslation(); | ||
return ( | ||
<section className={styles.helloWorld}> | ||
{isLoading ? <span>Loading ...</span> : <h1>Hello, {data?.name}!</h1>} | ||
{isLoading ? ( | ||
<span>Loading ...</span> | ||
) : ( | ||
<h1>{t("example.hello", { person: data?.name })}!</h1> | ||
)} | ||
</section> | ||
); | ||
}; |
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,13 @@ | ||
import nb from "./resources/nb.json"; | ||
|
||
export const i18nInitConfig = { | ||
resources: { | ||
nb: { translation: nb }, | ||
}, | ||
lng: "nb", | ||
fallbackLng: "nb", | ||
debug: false, | ||
interpolation: { | ||
escapeValue: false, | ||
}, | ||
}; |
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 @@ | ||
import i18n from "i18next"; | ||
import ICU from "i18next-icu"; | ||
import { initReactI18next } from "react-i18next"; | ||
|
||
import nb from "./resources/nb.json"; | ||
|
||
const i18nInitConfig = { | ||
resources: { | ||
nb: { translation: nb }, | ||
}, | ||
lng: "nb", | ||
fallbackLng: "nb", | ||
debug: false, | ||
interpolation: { | ||
escapeValue: false, | ||
}, | ||
}; | ||
|
||
await i18n.use(ICU).use(initReactI18next).init(i18nInitConfig); |
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,3 @@ | ||
{ | ||
"example.hello": "Hei, {person}" | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.