Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update i18n docs #8766

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions docs/best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Markdown will be translated as whole pages of content, so no specific action is

- _tl;dr Each individual JSON entry should be a complete phrase by itself_

- This is done using the `Translation` component. However there is an alternative method for regular JS: `gatsby-theme-i18n` with `/src/utils/translations.ts`
- This is done using the `Translation` component. However there is an alternative method for regular JS: using the `t` function from `gatsby-plugin-react-i18next`

- **Method one: `<Translation />` component (preferred if only needed in JSX)**

Expand All @@ -63,19 +63,18 @@ Markdown will be translated as whole pages of content, so no specific action is
;<Translation id="language-json-key" />
```

- **Method two: `translateMessageId()`**
- **Method two: `t()`**

```tsx
import { useIntl } from "react-intl"
import { translateMessageId } from "src/utils/translations"
import { useTranslation } from "gatsby-plugin-react-i18next"

// Utilize anywhere in JS using
const intl = useIntl()
translateMessageId("language-json-key", intl)
const { t } = useTranslation()
t("language-json-key")
```

```tsx
const siteTitle = translateMessageId("site-title", intl)
const siteTitle = t("site-title")
```

## React Hooks
Expand Down