@intlayer/docs 5.7.4 → 5.7.6-canary.0
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/blog/ar/intlayer_with_i18next.md +1 -1
- package/dist/cjs/common.cjs +0 -1
- package/dist/cjs/common.cjs.map +1 -1
- package/dist/cjs/generated/docs.entry.cjs +80 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/common.mjs +0 -1
- package/dist/esm/common.mjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +80 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +1 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/CI_CD.md +0 -1
- package/docs/ar/configuration.md +42 -5
- package/docs/ar/dictionary/enumeration.md +0 -1
- package/docs/ar/packages/react-intlayer/useI18n.md +250 -0
- package/docs/de/CI_CD.md +0 -1
- package/docs/de/configuration.md +42 -5
- package/docs/de/dictionary/gender.md +3 -3
- package/docs/de/packages/react-intlayer/useI18n.md +250 -0
- package/docs/en/configuration.md +44 -7
- package/docs/en/packages/react-intlayer/useI18n.md +250 -0
- package/docs/en-GB/configuration.md +42 -5
- package/docs/en-GB/packages/react-intlayer/useI18n.md +254 -0
- package/docs/es/configuration.md +42 -5
- package/docs/es/dictionary/enumeration.md +1 -2
- package/docs/es/dictionary/gender.md +3 -3
- package/docs/es/locale_mapper.md +1 -1
- package/docs/es/packages/react-intlayer/useI18n.md +250 -0
- package/docs/fr/configuration.md +44 -7
- package/docs/fr/intlayer_with_nextjs_15.md +0 -1
- package/docs/fr/intlayer_with_vite+preact.md +1 -1
- package/docs/fr/packages/react-intlayer/useI18n.md +250 -0
- package/docs/hi/configuration.md +42 -5
- package/docs/hi/dictionary/enumeration.md +0 -2
- package/docs/hi/packages/react-intlayer/useI18n.md +259 -0
- package/docs/it/configuration.md +42 -5
- package/docs/it/dictionary/enumeration.md +0 -1
- package/docs/it/packages/react-intlayer/useI18n.md +250 -0
- package/docs/it/vs_code_extension.md +0 -1
- package/docs/ja/configuration.md +43 -28
- package/docs/ja/dictionary/enumeration.md +0 -2
- package/docs/ja/packages/react-intlayer/useI18n.md +250 -0
- package/docs/ko/configuration.md +42 -5
- package/docs/ko/dictionary/enumeration.md +0 -2
- package/docs/ko/packages/react-intlayer/useI18n.md +250 -0
- package/docs/pt/configuration.md +42 -5
- package/docs/pt/packages/react-intlayer/useI18n.md +250 -0
- package/docs/ru/configuration.md +42 -5
- package/docs/ru/dictionary/enumeration.md +0 -2
- package/docs/ru/packages/react-intlayer/useI18n.md +250 -0
- package/docs/ru/vs_code_extension.md +0 -1
- package/docs/zh/configuration.md +42 -5
- package/docs/zh/dictionary/enumeration.md +0 -1
- package/docs/zh/packages/react-intlayer/useI18n.md +250 -0
- package/frequent_questions/ar/unknown_command.md +1 -1
- package/frequent_questions/de/array_as_content_declaration.md +1 -1
- package/frequent_questions/de/build_dictionaries.md +1 -1
- package/frequent_questions/de/build_error_CI_CD.md +1 -1
- package/frequent_questions/de/customized_locale_list.md +1 -1
- package/frequent_questions/de/esbuild_error.md +1 -1
- package/frequent_questions/de/intlayer_command_undefined.md +1 -1
- package/frequent_questions/de/locale_incorect_in_url.md +1 -1
- package/frequent_questions/de/static_rendering.md +1 -1
- package/frequent_questions/de/translated_path_url.md +1 -1
- package/frequent_questions/de/unknown_command.md +1 -1
- package/frequent_questions/en-GB/customized_locale_list.md +1 -1
- package/frequent_questions/es/array_as_content_declaration.md +1 -1
- package/frequent_questions/es/build_dictionaries.md +1 -1
- package/frequent_questions/es/customized_locale_list.md +1 -1
- package/frequent_questions/es/domain_routing.md +1 -1
- package/frequent_questions/es/get_locale_cookie.md +1 -1
- package/frequent_questions/es/intlayer_command_undefined.md +1 -1
- package/frequent_questions/es/locale_incorect_in_url.md +1 -1
- package/frequent_questions/es/static_rendering.md +1 -1
- package/frequent_questions/es/translated_path_url.md +1 -1
- package/frequent_questions/es/unknown_command.md +1 -1
- package/frequent_questions/fr/array_as_content_declaration.md +1 -1
- package/frequent_questions/fr/build_dictionaries.md +1 -1
- package/frequent_questions/fr/customized_locale_list.md +1 -1
- package/frequent_questions/fr/domain_routing.md +1 -1
- package/frequent_questions/fr/esbuild_error.md +1 -1
- package/frequent_questions/fr/intlayer_command_undefined.md +1 -1
- package/frequent_questions/fr/static_rendering.md +1 -1
- package/frequent_questions/fr/translated_path_url.md +1 -1
- package/frequent_questions/fr/unknown_command.md +1 -1
- package/frequent_questions/it/array_as_content_declaration.md +1 -1
- package/frequent_questions/it/build_dictionaries.md +1 -1
- package/frequent_questions/it/customized_locale_list.md +1 -1
- package/frequent_questions/it/esbuild_error.md +1 -1
- package/frequent_questions/it/intlayer_command_undefined.md +1 -1
- package/frequent_questions/it/locale_incorect_in_url.md +1 -1
- package/frequent_questions/it/static_rendering.md +1 -1
- package/frequent_questions/it/translated_path_url.md +1 -1
- package/frequent_questions/it/unknown_command.md +1 -1
- package/frequent_questions/ko/build_dictionaries.md +2 -2
- package/frequent_questions/ko/customized_locale_list.md +3 -3
- package/frequent_questions/ko/intlayer_command_undefined.md +3 -3
- package/frequent_questions/pt/array_as_content_declaration.md +1 -1
- package/frequent_questions/pt/build_dictionaries.md +1 -1
- package/frequent_questions/pt/build_error_CI_CD.md +1 -1
- package/frequent_questions/pt/customized_locale_list.md +1 -1
- package/frequent_questions/pt/domain_routing.md +1 -1
- package/frequent_questions/pt/esbuild_error.md +1 -1
- package/frequent_questions/pt/intlayer_command_undefined.md +1 -1
- package/frequent_questions/pt/locale_incorect_in_url.md +1 -1
- package/frequent_questions/pt/static_rendering.md +1 -1
- package/frequent_questions/pt/translated_path_url.md +1 -1
- package/frequent_questions/pt/unknown_command.md +1 -1
- package/frequent_questions/zh/build_dictionaries.md +3 -3
- package/frequent_questions/zh/customized_locale_list.md +3 -3
- package/frequent_questions/zh/esbuild_error.md +3 -3
- package/frequent_questions/zh/intlayer_command_undefined.md +3 -3
- package/frequent_questions/zh/translated_path_url.md +3 -3
- package/package.json +9 -9
- package/src/common.ts +0 -1
- package/src/generated/docs.entry.ts +80 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2024-08-11
|
|
3
|
+
updatedAt: 2025-06-29
|
|
4
|
+
title: useI18n 훅 문서 | react-intlayer
|
|
5
|
+
description: react-intlayer 패키지에서 useI18n 훅을 사용하는 방법을 알아보세요
|
|
6
|
+
keywords:
|
|
7
|
+
- useI18n
|
|
8
|
+
- i18n
|
|
9
|
+
- 번역
|
|
10
|
+
- 사전
|
|
11
|
+
- Intlayer
|
|
12
|
+
- 국제화
|
|
13
|
+
- 문서
|
|
14
|
+
- Next.js
|
|
15
|
+
- 자바스크립트
|
|
16
|
+
- 리액트
|
|
17
|
+
slugs:
|
|
18
|
+
- doc
|
|
19
|
+
- packages
|
|
20
|
+
- react-intlayer
|
|
21
|
+
- useI18n
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
# React 통합: `useI18n` 훅 문서
|
|
25
|
+
|
|
26
|
+
이 섹션에서는 React 애플리케이션 내에서 `useI18n` 훅을 사용하는 방법에 대해 자세히 안내하며, 효율적인 콘텐츠 현지화를 가능하게 합니다.
|
|
27
|
+
|
|
28
|
+
## React에서 `useI18n` 가져오기
|
|
29
|
+
|
|
30
|
+
`useI18n` 훅은 다음과 같이 상황에 맞게 React 애플리케이션에 가져와 통합할 수 있습니다:
|
|
31
|
+
|
|
32
|
+
- **클라이언트 컴포넌트:**
|
|
33
|
+
|
|
34
|
+
```typescript codeFormat="typescript"
|
|
35
|
+
import { useI18n } from "react-intlayer"; // 클라이언트 측 React 컴포넌트에서 사용
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```javascript codeFormat="esm"
|
|
39
|
+
import { useI18n } from "react-intlayer"; // 클라이언트 측 React 컴포넌트에서 사용
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```javascript codeFormat="commonjs"
|
|
43
|
+
const { useI18n } = require("react-intlayer"); // 클라이언트 측 React 컴포넌트에서 사용
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- **서버 컴포넌트:**
|
|
47
|
+
|
|
48
|
+
```typescript codeFormat="commonjs"
|
|
49
|
+
import { useI18n } from "react-intlayer/server"; // 서버 측 React 컴포넌트에서 사용
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```javascript codeFormat="esm"
|
|
53
|
+
import { useI18n } from "react-intlayer/server"; // 서버 측 React 컴포넌트에서 사용
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```javascript codeFormat="commonjs"
|
|
57
|
+
const { useI18n } = require("react-intlayer/server"); // 서버 측 React 컴포넌트에서 사용
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 매개변수
|
|
61
|
+
|
|
62
|
+
이 훅은 두 개의 매개변수를 받습니다:
|
|
63
|
+
|
|
64
|
+
1. **`namespace`**: 번역 키의 범위를 지정하는 사전 네임스페이스입니다.
|
|
65
|
+
2. **`locale`** (선택 사항): 원하는 로케일입니다. 지정하지 않으면 컨텍스트의 로케일이 기본값으로 사용됩니다.
|
|
66
|
+
|
|
67
|
+
## 사전
|
|
68
|
+
|
|
69
|
+
모든 사전 키는 타입 안전성을 높이고 오류를 방지하기 위해 콘텐츠 선언 파일 내에 선언되어야 합니다. [설정 지침은 여기에서 확인할 수 있습니다](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ko/dictionary/get_started.md).
|
|
70
|
+
|
|
71
|
+
## React에서의 사용 예시
|
|
72
|
+
|
|
73
|
+
React 컴포넌트 내에서 `useI18n` 훅을 사용하는 예시:
|
|
74
|
+
|
|
75
|
+
```tsx fileName="src/App.tsx" codeFormat="typescript"
|
|
76
|
+
import type { FC } from "react";
|
|
77
|
+
import { ClientComponentExample, ServerComponentExample } from "@components";
|
|
78
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
79
|
+
import { useI18n, IntlayerServerProvider } from "react.intlayer/server";
|
|
80
|
+
import { Locales } from "intlayer";
|
|
81
|
+
|
|
82
|
+
const App: FC<{ locale: Locales }> = ({ locale }) => {
|
|
83
|
+
const t = useI18n("home-page", locale);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<>
|
|
87
|
+
<p>{t("introduction")}</p>
|
|
88
|
+
<IntlayerProvider locale={locale}>
|
|
89
|
+
<ClientComponentExample />
|
|
90
|
+
</IntlayerProvider>
|
|
91
|
+
<IntlayerServerProvider locale={locale}>
|
|
92
|
+
<ServerComponentExample />
|
|
93
|
+
</IntlayerServerProvider>
|
|
94
|
+
</>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```jsx fileName="src/app.jsx" codeFormat="esm"
|
|
100
|
+
import { ClientComponentExample, ServerComponentExample } from "@components";
|
|
101
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
102
|
+
import { IntlayerServerProvider, useI18n } from "react-intlayer/server";
|
|
103
|
+
|
|
104
|
+
const App = ({ locale }) => {
|
|
105
|
+
const t = useI18n("home-page", locale);
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<>
|
|
109
|
+
<p>{t("introduction")}</p>
|
|
110
|
+
<IntlayerProvider locale={locale}>
|
|
111
|
+
<ClientComponentExample />
|
|
112
|
+
</IntlayerProvider>
|
|
113
|
+
<IntlayerServerProvider locale={locale}>
|
|
114
|
+
<ServerComponentExample />
|
|
115
|
+
</IntlayerServerProvider>
|
|
116
|
+
</>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
```jsx fileName="src/app.cjs" codeFormat="commonjs"
|
|
122
|
+
const { IntlayerProvider } = require("react-intlayer");
|
|
123
|
+
const { IntlayerServerProvider, useI18n } = require("react-intlayer/server");
|
|
124
|
+
|
|
125
|
+
const App = ({ locale }) => {
|
|
126
|
+
const t = useI18n("home-page", locale);
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<>
|
|
130
|
+
<p>{t("introduction")}</p>
|
|
131
|
+
<IntlayerProvider locale={locale}>
|
|
132
|
+
<ClientComponentExample />
|
|
133
|
+
</IntlayerProvider>
|
|
134
|
+
<IntlayerServerProvider locale={locale}>
|
|
135
|
+
<ServerComponentExample />
|
|
136
|
+
</IntlayerServerProvider>
|
|
137
|
+
</>
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```tsx fileName="src/components/ComponentExample.tsx" codeFormat="typescript"
|
|
143
|
+
import type { FC } from "react";
|
|
144
|
+
import { useI18n } from "react-intlayer";
|
|
145
|
+
|
|
146
|
+
const ComponentExample: FC = () => {
|
|
147
|
+
const t = useI18n("component-example");
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div>
|
|
151
|
+
<h1>{t("title")}</h1> {/* 제목을 표시합니다 */}
|
|
152
|
+
<p>{t("description")}</p> {/* 설명을 표시합니다 */}
|
|
153
|
+
</div>
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
```jsx fileName="src/components/ComponentExample.jsx" codeFormat="esm"
|
|
159
|
+
import { useI18n } from "react-intlayer";
|
|
160
|
+
|
|
161
|
+
const ComponentExample = () => {
|
|
162
|
+
const t = useI18n("component-example");
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<div>
|
|
166
|
+
<h1>{t("title")}</h1> {/* 제목을 표시합니다 */}
|
|
167
|
+
<p>{t("description")}</p> {/* 설명을 표시합니다 */}
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
```jsx fileName="src/components/ComponentExample.cjs" codeFormat="commonjs"
|
|
174
|
+
const { useI18n } = require("react-intlayer");
|
|
175
|
+
|
|
176
|
+
const ComponentExample = () => {
|
|
177
|
+
const t = useI18n("component-example");
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
<div>
|
|
181
|
+
<h1>{t("title")}</h1> {/* 제목을 표시합니다 */}
|
|
182
|
+
<p>{t("description")}</p> {/* 설명을 표시합니다 */}
|
|
183
|
+
</div>
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
```tsx fileName="src/components/ServerComponentExample.tsx" codeFormat="typescript"
|
|
189
|
+
import { useI18n } from "react-intlayer/server";
|
|
190
|
+
|
|
191
|
+
const ServerComponentExample = () => {
|
|
192
|
+
const t = useI18n("server-component");
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<div>
|
|
196
|
+
<h1>{t("title")}</h1> {/* 제목을 표시합니다 */}
|
|
197
|
+
<p>{t("description")}</p> {/* 설명을 표시합니다 */}
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
```jsx fileName="src/components/ServerComponentExample.jsx" codeFormat="esm"
|
|
204
|
+
import { useI18n } from "react-intlayer/server";
|
|
205
|
+
|
|
206
|
+
const ServerComponentExample = () => {
|
|
207
|
+
const t = useI18n("server-component");
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<div>
|
|
211
|
+
<h1>{t("title")}</h1> {/* 제목을 표시합니다 */}
|
|
212
|
+
<p>{t("description")}</p> {/* 설명을 표시합니다 */}
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
```jsx fileName="src/components/ServerComponentExample.cjs" codeFormat="commonjs"
|
|
219
|
+
const { useI18n } = require("react-intlayer/server");
|
|
220
|
+
|
|
221
|
+
const ServerComponentExample = () => {
|
|
222
|
+
const t = useI18n("server-component");
|
|
223
|
+
|
|
224
|
+
return (
|
|
225
|
+
<div>
|
|
226
|
+
<h1>{t("title")}</h1>
|
|
227
|
+
<p>{t("description")}</p>
|
|
228
|
+
</div>
|
|
229
|
+
);
|
|
230
|
+
};
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## 속성 처리
|
|
234
|
+
|
|
235
|
+
속성을 현지화할 때는 번역 값을 적절히 접근해야 합니다:
|
|
236
|
+
|
|
237
|
+
```jsx
|
|
238
|
+
<!-- 접근성 속성(예: aria-label)의 경우, 순수 문자열이 필요하므로 .value를 사용하세요 -->
|
|
239
|
+
<button aria-label={t("button.ariaLabel").value}>{t("button.text")}</button>
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## 추가 자료
|
|
243
|
+
|
|
244
|
+
- **Intlayer 비주얼 에디터**: 보다 직관적인 콘텐츠 관리 경험을 위해 비주얼 에디터 문서를 [여기](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ko/intlayer_visual_editor.md)에서 참고하세요.
|
|
245
|
+
|
|
246
|
+
이 섹션은 React 애플리케이션에서 `useI18n` 훅의 통합을 구체적으로 다루며, 현지화 과정을 단순화하고 다양한 로케일 간 콘텐츠 일관성을 보장합니다.
|
|
247
|
+
|
|
248
|
+
## 문서 기록
|
|
249
|
+
|
|
250
|
+
- 6.0.0 - 2025-06-29: `useI18n` 훅 문서 초안 작성
|
package/docs/pt/configuration.md
CHANGED
|
@@ -270,10 +270,12 @@ Configurações que controlam o comportamento do middleware, incluindo como a ap
|
|
|
270
270
|
- **prefixDefault**:
|
|
271
271
|
|
|
272
272
|
- _Tipo_: `boolean`
|
|
273
|
-
- _Padrão_: `
|
|
273
|
+
- _Padrão_: `false`
|
|
274
274
|
- _Descrição_: Indica se o idioma padrão deve ser incluído na URL.
|
|
275
|
-
- _Exemplo_: `
|
|
276
|
-
- _Nota_:
|
|
275
|
+
- _Exemplo_: `true`
|
|
276
|
+
- _Nota_:
|
|
277
|
+
- Se `true` e `defaultLocale = 'en'`: path = `/en/dashboard` ou `/fr/dashboard`
|
|
278
|
+
- Se `false` e `defaultLocale = 'en'`: path = `/dashboard` ou `/fr/dashboard`
|
|
277
279
|
|
|
278
280
|
- **basePath**:
|
|
279
281
|
|
|
@@ -281,7 +283,11 @@ Configurações que controlam o comportamento do middleware, incluindo como a ap
|
|
|
281
283
|
- _Padrão_: `''`
|
|
282
284
|
- _Descrição_: O caminho base para as URLs da aplicação.
|
|
283
285
|
- _Exemplo_: `'/my-app'`
|
|
284
|
-
- _Nota_:
|
|
286
|
+
- _Nota_:
|
|
287
|
+
- Se a aplicação está hospedada em `https://example.com/my-app`
|
|
288
|
+
- O caminho base é `'/my-app'`
|
|
289
|
+
- A URL será `https://example.com/my-app/en`
|
|
290
|
+
- Se o caminho base não estiver definido, a URL será `https://example.com/en`
|
|
285
291
|
|
|
286
292
|
- **serverSetCookie**:
|
|
287
293
|
|
|
@@ -293,11 +299,42 @@ Configurações que controlam o comportamento do middleware, incluindo como a ap
|
|
|
293
299
|
- _Nota_: Controla se o cookie de idioma é definido em todas as requisições ou nunca.
|
|
294
300
|
|
|
295
301
|
- **noPrefix**:
|
|
302
|
+
|
|
296
303
|
- _Tipo_: `boolean`
|
|
297
304
|
- _Padrão_: `false`
|
|
298
305
|
- _Descrição_: Indica se o prefixo de idioma deve ser omitido das URLs.
|
|
299
306
|
- _Exemplo_: `true`
|
|
300
|
-
- _Nota_:
|
|
307
|
+
- _Nota_:
|
|
308
|
+
- Se `true`: Sem prefixo na URL
|
|
309
|
+
- Se `false`: Prefixo na URL
|
|
310
|
+
- Exemplo com `basePath = '/my-app'`:
|
|
311
|
+
- Se `noPrefix = false`: A URL será `https://example.com/my-app/en`
|
|
312
|
+
- Se `noPrefix = true`: A URL será `https://example.com`
|
|
313
|
+
|
|
314
|
+
- **detectLocaleOnPrefetchNoPrefix**:
|
|
315
|
+
|
|
316
|
+
- _Tipo_: `boolean`
|
|
317
|
+
- _Padrão_: `false`
|
|
318
|
+
- _Descrição_: Controla se a detecção de idioma ocorre durante as requisições de prefetch do Next.js.
|
|
319
|
+
- _Exemplo_: `true`
|
|
320
|
+
- _Nota_: Esta configuração afeta como o Next.js gerencia o prefetch de idioma:
|
|
321
|
+
- **Cenário de exemplo:**
|
|
322
|
+
- O idioma do navegador do usuário é `'fr'`
|
|
323
|
+
- A página atual é `/fr/about`
|
|
324
|
+
- O link faz prefetch de `/about`
|
|
325
|
+
- **Com `detectLocaleOnPrefetchNoPrefix: true`:**
|
|
326
|
+
- O prefetch detecta o idioma `'fr'` do navegador
|
|
327
|
+
- Redireciona o prefetch para `/fr/about`
|
|
328
|
+
- **Com `detectLocaleOnPrefetchNoPrefix: false` (padrão):**
|
|
329
|
+
- O prefetch usa o idioma padrão
|
|
330
|
+
- Redireciona o prefetch para `/en/about` (assumindo que `'en'` é o padrão)
|
|
331
|
+
- **Quando usar `true`:**
|
|
332
|
+
- Sua aplicação usa links internos não localizados (ex. `<a href="/about">`)
|
|
333
|
+
- Você quer comportamento consistente de detecção de idioma entre requisições normais e de prefetch
|
|
334
|
+
- **Quando usar `false` (padrão):**
|
|
335
|
+
- Sua aplicação usa links com prefixo de idioma (ex. `<a href="/fr/about">`)
|
|
336
|
+
- Você quer otimizar a performance do prefetch
|
|
337
|
+
- Você quer evitar loops de redirecionamento potenciais
|
|
301
338
|
|
|
302
339
|
---
|
|
303
340
|
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2024-08-11
|
|
3
|
+
updatedAt: 2025-06-29
|
|
4
|
+
title: Documentação do Hook useI18n | react-intlayer
|
|
5
|
+
description: Aprenda como usar o hook useI18n no pacote react-intlayer
|
|
6
|
+
keywords:
|
|
7
|
+
- useI18n
|
|
8
|
+
- i18n
|
|
9
|
+
- tradução
|
|
10
|
+
- dicionário
|
|
11
|
+
- Intlayer
|
|
12
|
+
- internacionalização
|
|
13
|
+
- documentação
|
|
14
|
+
- Next.js
|
|
15
|
+
- JavaScript
|
|
16
|
+
- React
|
|
17
|
+
slugs:
|
|
18
|
+
- doc
|
|
19
|
+
- packages
|
|
20
|
+
- react-intlayer
|
|
21
|
+
- useI18n
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
# Integração com React: Documentação do Hook `useI18n`
|
|
25
|
+
|
|
26
|
+
Esta seção fornece orientações detalhadas sobre como usar o hook `useI18n` em aplicações React, permitindo uma localização eficiente de conteúdo.
|
|
27
|
+
|
|
28
|
+
## Importando `useI18n` no React
|
|
29
|
+
|
|
30
|
+
O hook `useI18n` pode ser importado e integrado em aplicações React conforme o contexto, da seguinte forma:
|
|
31
|
+
|
|
32
|
+
- **Componentes Cliente:**
|
|
33
|
+
|
|
34
|
+
```typescript codeFormat="typescript"
|
|
35
|
+
import { useI18n } from "react-intlayer"; // Use em componentes React do lado do cliente
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```javascript codeFormat="esm"
|
|
39
|
+
import { useI18n } from "react-intlayer"; // Use em componentes React do lado do cliente
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```javascript codeFormat="commonjs"
|
|
43
|
+
const { useI18n } = require("react-intlayer"); // Use em componentes React do lado do cliente
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- **Componentes Servidor:**
|
|
47
|
+
|
|
48
|
+
```typescript codeFormat="commonjs"
|
|
49
|
+
import { useI18n } from "react-intlayer/server"; // Use em componentes React do lado do servidor
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```javascript codeFormat="esm"
|
|
53
|
+
import { useI18n } from "react-intlayer/server"; // Use em componentes React do lado do servidor
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```javascript codeFormat="commonjs"
|
|
57
|
+
const { useI18n } = require("react-intlayer/server"); // Use em componentes React do lado do servidor
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Parâmetros
|
|
61
|
+
|
|
62
|
+
Este hook aceita dois parâmetros:
|
|
63
|
+
|
|
64
|
+
1. **`namespace`**: Um namespace de dicionário para delimitar as chaves de tradução.
|
|
65
|
+
2. **`locale`** (opcional): O locale desejado. Se não especificado, o locale do contexto será usado como padrão.
|
|
66
|
+
|
|
67
|
+
## Dicionário
|
|
68
|
+
|
|
69
|
+
Todas as chaves do dicionário devem ser declaradas dentro dos arquivos de declaração de conteúdo para aumentar a segurança de tipos e evitar erros. [Instruções de configuração podem ser encontradas aqui](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/dictionary/get_started.md).
|
|
70
|
+
|
|
71
|
+
## Exemplos de Uso em React
|
|
72
|
+
|
|
73
|
+
Exemplos de uso do hook `useI18n` dentro de componentes React:
|
|
74
|
+
|
|
75
|
+
```tsx fileName="src/App.tsx" codeFormat="typescript"
|
|
76
|
+
import type { FC } from "react";
|
|
77
|
+
import { ClientComponentExample, ServerComponentExample } from "@components";
|
|
78
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
79
|
+
import { useI18n, IntlayerServerProvider } from "react-intlayer/server";
|
|
80
|
+
import { Locales } from "intlayer";
|
|
81
|
+
|
|
82
|
+
const App: FC<{ locale: Locales }> = ({ locale }) => {
|
|
83
|
+
const t = useI18n("home-page", locale);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<>
|
|
87
|
+
<p>{t("introduction")}</p>
|
|
88
|
+
<IntlayerProvider locale={locale}>
|
|
89
|
+
<ClientComponentExample />
|
|
90
|
+
</IntlayerProvider>
|
|
91
|
+
<IntlayerServerProvider locale={locale}>
|
|
92
|
+
<ServerComponentExample />
|
|
93
|
+
</IntlayerServerProvider>
|
|
94
|
+
</>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```jsx fileName="src/app.jsx" codeFormat="esm"
|
|
100
|
+
import { ClientComponentExample, ServerComponentExample } from "@components";
|
|
101
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
102
|
+
import { IntlayerServerProvider, useI18n } from "react-intlayer/server";
|
|
103
|
+
|
|
104
|
+
const App = ({ locale }) => {
|
|
105
|
+
const t = useI18n("home-page", locale);
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<>
|
|
109
|
+
<p>{t("introduction")}</p>
|
|
110
|
+
<IntlayerProvider locale={locale}>
|
|
111
|
+
<ClientComponentExample />
|
|
112
|
+
</IntlayerProvider>
|
|
113
|
+
<IntlayerServerProvider locale={locale}>
|
|
114
|
+
<ServerComponentExample />
|
|
115
|
+
</IntlayerServerProvider>
|
|
116
|
+
</>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
```jsx fileName="src/app.cjs" codeFormat="commonjs"
|
|
122
|
+
const { IntlayerProvider } = require("react-intlayer");
|
|
123
|
+
const { IntlayerServerProvider, useI18n } = require("react-intlayer/server");
|
|
124
|
+
|
|
125
|
+
const App = ({ locale }) => {
|
|
126
|
+
const t = useI18n("home-page", locale);
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<>
|
|
130
|
+
<p>{t("introduction")}</p>
|
|
131
|
+
<IntlayerProvider locale={locale}>
|
|
132
|
+
<ClientComponentExample />
|
|
133
|
+
</IntlayerProvider>
|
|
134
|
+
<IntlayerServerProvider locale={locale}>
|
|
135
|
+
<ServerComponentExample />
|
|
136
|
+
</IntlayerServerProvider>
|
|
137
|
+
</>
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```tsx fileName="src/components/ComponentExample.tsx" codeFormat="typescript"
|
|
143
|
+
import type { FC } from "react";
|
|
144
|
+
import { useI18n } from "react-intlayer";
|
|
145
|
+
|
|
146
|
+
const ComponentExample: FC = () => {
|
|
147
|
+
const t = useI18n("component-example");
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div>
|
|
151
|
+
<h1>{t("title")}</h1> {/* Exibe o título */}
|
|
152
|
+
<p>{t("description")}</p> {/* Exibe a descrição */}
|
|
153
|
+
</div>
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
```jsx fileName="src/components/ComponentExample.jsx" codeFormat="esm"
|
|
159
|
+
import { useI18n } from "react-intlayer";
|
|
160
|
+
|
|
161
|
+
const ComponentExample = () => {
|
|
162
|
+
const t = useI18n("component-example");
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<div>
|
|
166
|
+
<h1>{t("title")}</h1> {/* Exibe o título */}
|
|
167
|
+
<p>{t("description")}</p> {/* Exibe a descrição */}
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
```jsx fileName="src/components/ComponentExample.cjs" codeFormat="commonjs"
|
|
174
|
+
const { useI18n } = require("react-intlayer");
|
|
175
|
+
|
|
176
|
+
const ComponentExample = () => {
|
|
177
|
+
const t = useI18n("component-example");
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
<div>
|
|
181
|
+
<h1>{t("title")}</h1> {/* Exibe o título */}
|
|
182
|
+
<p>{t("description")}</p> {/* Exibe a descrição */}
|
|
183
|
+
</div>
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
```tsx fileName="src/components/ServerComponentExample.tsx" codeFormat="typescript"
|
|
189
|
+
import { useI18n } from "react-intlayer/server";
|
|
190
|
+
|
|
191
|
+
const ServerComponentExample = () => {
|
|
192
|
+
const t = useI18n("server-component");
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<div>
|
|
196
|
+
<h1>{t("title")}</h1> {/* Exibe o título */}
|
|
197
|
+
<p>{t("description")}</p> {/* Exibe a descrição */}
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
```jsx fileName="src/components/ServerComponentExample.jsx" codeFormat="esm"
|
|
204
|
+
import { useI18n } from "react-intlayer/server";
|
|
205
|
+
|
|
206
|
+
const ServerComponentExample = () => {
|
|
207
|
+
const t = useI18n("server-component");
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<div>
|
|
211
|
+
<h1>{t("title")}</h1> {/* Exibe o título */}
|
|
212
|
+
<p>{t("description")}</p> {/* Exibe a descrição */}
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
```jsx fileName="src/components/ServerComponentExample.cjs" codeFormat="commonjs"
|
|
219
|
+
const { useI18n } = require("react-intlayer/server");
|
|
220
|
+
|
|
221
|
+
const ServerComponentExample = () => {
|
|
222
|
+
const t = useI18n("server-component");
|
|
223
|
+
|
|
224
|
+
return (
|
|
225
|
+
<div>
|
|
226
|
+
<h1>{t("title")}</h1>
|
|
227
|
+
<p>{t("description")}</p>
|
|
228
|
+
</div>
|
|
229
|
+
);
|
|
230
|
+
};
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Manipulação de Atributos
|
|
234
|
+
|
|
235
|
+
Ao localizar atributos, acesse os valores de tradução de forma apropriada:
|
|
236
|
+
|
|
237
|
+
```jsx
|
|
238
|
+
<!-- Para atributos de acessibilidade (ex.: aria-label), use .value pois são necessárias strings puras -->
|
|
239
|
+
<button aria-label={t("button.ariaLabel").value}>{t("button.text")}</button>
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Recursos Adicionais
|
|
243
|
+
|
|
244
|
+
- **Editor Visual Intlayer**: Para uma experiência de gerenciamento de conteúdo mais intuitiva, consulte a documentação do editor visual [aqui](https://github.com/aymericzip/intlayer/blob/main/docs/docs/pt/intlayer_visual_editor.md).
|
|
245
|
+
|
|
246
|
+
Esta seção cobre especificamente a integração do hook `useI18n` em aplicações React, simplificando o processo de localização e garantindo a consistência do conteúdo entre diferentes locais.
|
|
247
|
+
|
|
248
|
+
## Histórico da Documentação
|
|
249
|
+
|
|
250
|
+
- 6.0.0 - 2025-06-29: Escrita inicial da documentação do hook `useI18n`
|
package/docs/ru/configuration.md
CHANGED
|
@@ -268,10 +268,12 @@ module.exports = config;
|
|
|
268
268
|
- **prefixDefault**:
|
|
269
269
|
|
|
270
270
|
- _Тип_: `boolean`
|
|
271
|
-
- _По умолчанию_: `
|
|
271
|
+
- _По умолчанию_: `false`
|
|
272
272
|
- _Описание_: Включать ли локаль по умолчанию в URL.
|
|
273
|
-
- _Пример_: `
|
|
274
|
-
- _Примечание_:
|
|
273
|
+
- _Пример_: `true`
|
|
274
|
+
- _Примечание_:
|
|
275
|
+
- Если `true` и `defaultLocale = 'en'`: path = `/en/dashboard` или `/fr/dashboard`
|
|
276
|
+
- Если `false` и `defaultLocale = 'en'`: path = `/dashboard` или `/fr/dashboard`
|
|
275
277
|
|
|
276
278
|
- **basePath**:
|
|
277
279
|
|
|
@@ -279,7 +281,11 @@ module.exports = config;
|
|
|
279
281
|
- _По умолчанию_: `''`
|
|
280
282
|
- _Описание_: Базовый путь для URL приложения.
|
|
281
283
|
- _Пример_: `'/my-app'`
|
|
282
|
-
- _Примечание_:
|
|
284
|
+
- _Примечание_:
|
|
285
|
+
- Если приложение размещено на `https://example.com/my-app`
|
|
286
|
+
- Базовый путь `'/my-app'`
|
|
287
|
+
- URL будет `https://example.com/my-app/en`
|
|
288
|
+
- Если базовый путь не установлен, URL будет `https://example.com/en`
|
|
283
289
|
|
|
284
290
|
- **serverSetCookie**:
|
|
285
291
|
|
|
@@ -291,11 +297,42 @@ module.exports = config;
|
|
|
291
297
|
- _Примечание_: Управляет, устанавливается ли cookie локали при каждом запросе или никогда.
|
|
292
298
|
|
|
293
299
|
- **noPrefix**:
|
|
300
|
+
|
|
294
301
|
- _Тип_: `boolean`
|
|
295
302
|
- _По умолчанию_: `false`
|
|
296
303
|
- _Описание_: Исключать ли префикс локали из URL.
|
|
297
304
|
- _Пример_: `true`
|
|
298
|
-
- _Примечание_:
|
|
305
|
+
- _Примечание_:
|
|
306
|
+
- Если `true`: Без префикса в URL
|
|
307
|
+
- Если `false`: С префиксом в URL
|
|
308
|
+
- Пример с `basePath = '/my-app'`:
|
|
309
|
+
- Если `noPrefix = false`: URL будет `https://example.com/my-app/en`
|
|
310
|
+
- Если `noPrefix = true`: URL будет `https://example.com`
|
|
311
|
+
|
|
312
|
+
- **detectLocaleOnPrefetchNoPrefix**:
|
|
313
|
+
|
|
314
|
+
- _Тип_: `boolean`
|
|
315
|
+
- _По умолчанию_: `false`
|
|
316
|
+
- _Описание_: Управляет, происходит ли обнаружение локали во время запросов предварительной загрузки Next.js.
|
|
317
|
+
- _Пример_: `true`
|
|
318
|
+
- _Примечание_: Эта настройка влияет на то, как Next.js обрабатывает предварительную загрузку локали:
|
|
319
|
+
- **Пример сценария:**
|
|
320
|
+
- Язык браузера пользователя `'fr'`
|
|
321
|
+
- Текущая страница `/fr/about`
|
|
322
|
+
- Ссылка предварительно загружает `/about`
|
|
323
|
+
- **С `detectLocaleOnPrefetchNoPrefix: true`:**
|
|
324
|
+
- Предварительная загрузка обнаруживает локаль `'fr'` из браузера
|
|
325
|
+
- Перенаправляет предварительную загрузку на `/fr/about`
|
|
326
|
+
- **С `detectLocaleOnPrefetchNoPrefix: false` (по умолчанию):**
|
|
327
|
+
- Предварительная загрузка использует локаль по умолчанию
|
|
328
|
+
- Перенаправляет предварительную загрузку на `/en/about` (предполагая, что `'en'` по умолчанию)
|
|
329
|
+
- **Когда использовать `true`:**
|
|
330
|
+
- Ваше приложение использует нелокализованные внутренние ссылки (например, `<a href="/about">`)
|
|
331
|
+
- Вы хотите согласованное поведение обнаружения локали между обычными и предварительными запросами
|
|
332
|
+
- **Когда использовать `false` (по умолчанию):**
|
|
333
|
+
- Ваше приложение использует ссылки с префиксом локали (например, `<a href="/fr/about">`)
|
|
334
|
+
- Вы хотите оптимизировать производительность предварительной загрузки
|
|
335
|
+
- Вы хотите избежать потенциальных циклов перенаправления
|
|
299
336
|
|
|
300
337
|
---
|
|
301
338
|
|