-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add instructions on how to setup react + acknowledgments section
- Loading branch information
1 parent
aa30a82
commit 761f02f
Showing
2 changed files
with
124 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,80 @@ | ||
# astro-i18next examples - React | ||
# astro-i18next examples - React <!-- omit in toc --> | ||
|
||
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/yassinedoghri/astro-i18next/tree/latest/examples/react) | ||
|
||
- [🛠️ How to setup?](#️-how-to-setup) | ||
- [1. Install](#1-install) | ||
- [2. Configure](#2-configure) | ||
- [🌐 Client-side locale detection](#-client-side-locale-detection) | ||
- [👀 Want to learn more?](#-want-to-learn-more) | ||
|
||
## 🛠️ How to setup? | ||
|
||
astro-i18next loads two i18next configs by default. One on the server side, the | ||
other one client side (where the required `react-i18next` package will be | ||
initialized). | ||
|
||
### 1. Install | ||
|
||
```bash | ||
npm install astro-i18next @astrojs/react react-i18next | ||
``` | ||
|
||
### 2. Configure | ||
|
||
1. Add `astro-i18next` to your `astro.config.mjs`: | ||
|
||
```js | ||
import { defineConfig } from "astro/config"; | ||
import react from "@astrojs/react"; | ||
import astroI18next from "astro-i18next"; | ||
|
||
export default defineConfig({ | ||
integrations: [react(), astroI18next()], | ||
}); | ||
``` | ||
|
||
2. Configure `astro-i18next` in your `astro-i18next.config.mjs` file: | ||
|
||
```js | ||
/** @type {import('astro-i18next').AstroI18nextConfig} */ | ||
export default { | ||
defaultLocale: "en", | ||
locales: ["en", "fr"], | ||
}; | ||
``` | ||
|
||
3. By default, `astro-i18next` expects your translations to be organized inside | ||
your `public` folder, in a `locales` folder: | ||
|
||
```bash | ||
public | ||
└── locales # create this folder to store your translation strings | ||
├── en | ||
| └── translation.json | ||
└── fr | ||
└── translation.json | ||
``` | ||
|
||
**That's it!** You can now start translating! | ||
## 🌐 Client-side locale detection | ||
⚠️ **astro-18next** implements client-side locale detection using the great | ||
[`i18next-browser-languageDetector`](https://github.com/i18next/i18next-browser-languageDetector) | ||
plugin. | ||
To have the page locale be detected, the default configuration is set to check | ||
for the html `lang` attribute in your page: | ||
```astro | ||
--- | ||
import i18next from "i18next"; | ||
--- | ||
<html lang={i18next.language}>...</html> | ||
``` | ||
## 👀 Want to learn more? | ||
Feel free to check [astro-i18next's documentation](../../README.md). |