astro-react-i18next 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -11
- package/dist/index.js +1 -1
- package/dist/middleware-server.js +2 -2
- package/package.json +22 -18
package/README.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Integrates i18next and react-i18next seamlessly into your Astro website to provide robust i18n support for React components.
|
|
4
4
|
|
|
5
|
+
[](https://www.npmjs.com/package/astro-react-i18next)
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
## Examples
|
|
9
|
+
|
|
10
|
+
| Example | |
|
|
11
|
+
| ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
12
|
+
| [SSG](https://github.com/jeremyxgo/astro-react-i18next/tree/main/examples/ssg) | [](https://stackblitz.com/github/jeremyxgo/astro-react-i18next/tree/main/examples/ssg?startScript=dev) |
|
|
13
|
+
| [SSR](https://github.com/jeremyxgo/astro-react-i18next/tree/main/examples/ssr) | [](https://stackblitz.com/github/jeremyxgo/astro-react-i18next/tree/main/examples/ssr?startScript=dev) |
|
|
14
|
+
|
|
5
15
|
## Installation
|
|
6
16
|
|
|
7
17
|
```bash
|
|
@@ -108,27 +118,29 @@ The content of the `locales/en-US/common.json` file should look like this:
|
|
|
108
118
|
|
|
109
119
|
```json
|
|
110
120
|
{
|
|
111
|
-
"hello_world": "Hello World!"
|
|
121
|
+
"hello_world": "Hello, World!"
|
|
112
122
|
}
|
|
113
123
|
```
|
|
114
124
|
|
|
115
125
|
## Dynamic Routes for Locales
|
|
116
126
|
|
|
117
|
-
To manage dynamic routes for each locale, create a root route named `[...locale]` in the `
|
|
127
|
+
To manage dynamic routes for each locale, create a root route named `[...locale]` in the `pages` directory.
|
|
118
128
|
|
|
119
129
|
```text
|
|
120
130
|
/
|
|
121
131
|
├── public/
|
|
122
132
|
├── src/
|
|
123
|
-
│ └──
|
|
124
|
-
│
|
|
125
|
-
│
|
|
133
|
+
│ └── pages/
|
|
134
|
+
│ └── [...locale]/
|
|
135
|
+
│ ├── index.astro
|
|
136
|
+
│ ├── page-a.astro
|
|
137
|
+
│ └── page-b.astro
|
|
126
138
|
└── package.json
|
|
127
139
|
```
|
|
128
140
|
|
|
129
141
|
## Static Paths for Locales
|
|
130
142
|
|
|
131
|
-
|
|
143
|
+
If you're using `Static (SSG) Mode`, static paths are required. You can easily generate them by using the `buildStaticPaths` utility function provided by this integration.
|
|
132
144
|
|
|
133
145
|
```js
|
|
134
146
|
---
|
|
@@ -146,15 +158,15 @@ export function getStaticPaths() {
|
|
|
146
158
|
|
|
147
159
|
## Translating Content in Astro Components
|
|
148
160
|
|
|
149
|
-
Use the i18next instance to translate content in your Astro components.
|
|
161
|
+
Use the `i18next` instance to translate content in your Astro components.
|
|
150
162
|
|
|
151
163
|
```js
|
|
152
164
|
---
|
|
153
|
-
import
|
|
165
|
+
import i18n from "i18next";
|
|
154
166
|
---
|
|
155
167
|
|
|
156
|
-
<html lang={
|
|
157
|
-
<p>{
|
|
168
|
+
<html lang={i18n.language}>
|
|
169
|
+
<p>{i18n.t("hello_world")}</p>
|
|
158
170
|
</html>
|
|
159
171
|
```
|
|
160
172
|
|
|
@@ -167,7 +179,7 @@ import { useTranslation } from "react-i18next";
|
|
|
167
179
|
|
|
168
180
|
export function MyComponent() {
|
|
169
181
|
const { t } = useTranslation();
|
|
170
|
-
return <p>{t("
|
|
182
|
+
return <p>{t("hello_world")}</p>;
|
|
171
183
|
}
|
|
172
184
|
```
|
|
173
185
|
|
package/dist/index.js
CHANGED
|
@@ -34,10 +34,10 @@ async function onRequest(context, next) {
|
|
|
34
34
|
].find((locale) => locale && locales.includes(locale));
|
|
35
35
|
await i18n2.changeLanguage(nextLocale);
|
|
36
36
|
context.cookies.set("i18next", nextLocale || "", { path: "/" });
|
|
37
|
-
const { hash,
|
|
37
|
+
const { hash, pathname, search } = context.url;
|
|
38
38
|
const nextPathname = getLocalizedPathname(pathname, nextLocale);
|
|
39
39
|
if (nextPathname !== pathname) {
|
|
40
|
-
const nextUrl =
|
|
40
|
+
const nextUrl = nextPathname + search + hash;
|
|
41
41
|
return context.redirect(nextUrl);
|
|
42
42
|
}
|
|
43
43
|
return next();
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-react-i18next",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Integrates i18next and react-i18next seamlessly into your Astro website to provide robust i18n support for React components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro-integration",
|
|
7
|
-
"withastro"
|
|
7
|
+
"withastro",
|
|
8
|
+
"i18n",
|
|
9
|
+
"i18next",
|
|
10
|
+
"react"
|
|
8
11
|
],
|
|
9
12
|
"author": "jeremyxgo",
|
|
10
13
|
"license": "MIT",
|
|
@@ -12,10 +15,11 @@
|
|
|
12
15
|
"type": "git",
|
|
13
16
|
"url": "https://github.com/jeremyxgo/astro-react-i18next.git"
|
|
14
17
|
},
|
|
15
|
-
"type": "module",
|
|
16
18
|
"files": [
|
|
17
19
|
"dist"
|
|
18
20
|
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
19
23
|
"exports": {
|
|
20
24
|
".": "./dist/index.js",
|
|
21
25
|
"./middleware/server": "./dist/middleware-server.js",
|
|
@@ -29,29 +33,29 @@
|
|
|
29
33
|
"prepare": "husky"
|
|
30
34
|
},
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"i18next": "^
|
|
36
|
+
"i18next": "^24.0.2",
|
|
33
37
|
"i18next-browser-languagedetector": "^8.0.0",
|
|
34
|
-
"i18next-fs-backend": "^2.
|
|
35
|
-
"i18next-http-backend": "^
|
|
36
|
-
"react-i18next": "^15.
|
|
38
|
+
"i18next-fs-backend": "^2.6.0",
|
|
39
|
+
"i18next-http-backend": "^3.0.1",
|
|
40
|
+
"react-i18next": "^15.1.2"
|
|
37
41
|
},
|
|
38
42
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^22.
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
41
|
-
"@typescript-eslint/parser": "^8.
|
|
42
|
-
"astro": "^4.
|
|
43
|
-
"astro-eslint-parser": "^1.0
|
|
43
|
+
"@types/node": "^22.10.1",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^8.16.0",
|
|
45
|
+
"@typescript-eslint/parser": "^8.16.0",
|
|
46
|
+
"astro": "^4.16.16",
|
|
47
|
+
"astro-eslint-parser": "^1.1.0",
|
|
44
48
|
"esbuild": "^0.24.0",
|
|
45
49
|
"eslint": "^8.57.1",
|
|
46
50
|
"eslint-config-prettier": "^9.1.0",
|
|
47
|
-
"eslint-plugin-astro": "^1.
|
|
48
|
-
"eslint-plugin-import": "^2.
|
|
49
|
-
"eslint-plugin-react": "^7.37.
|
|
50
|
-
"husky": "^9.1.
|
|
51
|
+
"eslint-plugin-astro": "^1.3.1",
|
|
52
|
+
"eslint-plugin-import": "^2.31.0",
|
|
53
|
+
"eslint-plugin-react": "^7.37.2",
|
|
54
|
+
"husky": "^9.1.7",
|
|
51
55
|
"lint-staged": "^15.2.10",
|
|
52
|
-
"prettier": "^3.
|
|
56
|
+
"prettier": "^3.4.1",
|
|
53
57
|
"prettier-plugin-astro": "^0.14.1",
|
|
54
|
-
"typescript": "^5.
|
|
58
|
+
"typescript": "^5.7.2"
|
|
55
59
|
},
|
|
56
60
|
"engines": {
|
|
57
61
|
"node": "^18.17.1 || ^20.3.0 || >=21.0.0"
|