@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.
Files changed (117) hide show
  1. package/blog/ar/intlayer_with_i18next.md +1 -1
  2. package/dist/cjs/common.cjs +0 -1
  3. package/dist/cjs/common.cjs.map +1 -1
  4. package/dist/cjs/generated/docs.entry.cjs +80 -0
  5. package/dist/cjs/generated/docs.entry.cjs.map +1 -1
  6. package/dist/esm/common.mjs +0 -1
  7. package/dist/esm/common.mjs.map +1 -1
  8. package/dist/esm/generated/docs.entry.mjs +80 -0
  9. package/dist/esm/generated/docs.entry.mjs.map +1 -1
  10. package/dist/types/common.d.ts.map +1 -1
  11. package/dist/types/generated/docs.entry.d.ts +1 -0
  12. package/dist/types/generated/docs.entry.d.ts.map +1 -1
  13. package/docs/ar/CI_CD.md +0 -1
  14. package/docs/ar/configuration.md +42 -5
  15. package/docs/ar/dictionary/enumeration.md +0 -1
  16. package/docs/ar/packages/react-intlayer/useI18n.md +250 -0
  17. package/docs/de/CI_CD.md +0 -1
  18. package/docs/de/configuration.md +42 -5
  19. package/docs/de/dictionary/gender.md +3 -3
  20. package/docs/de/packages/react-intlayer/useI18n.md +250 -0
  21. package/docs/en/configuration.md +44 -7
  22. package/docs/en/packages/react-intlayer/useI18n.md +250 -0
  23. package/docs/en-GB/configuration.md +42 -5
  24. package/docs/en-GB/packages/react-intlayer/useI18n.md +254 -0
  25. package/docs/es/configuration.md +42 -5
  26. package/docs/es/dictionary/enumeration.md +1 -2
  27. package/docs/es/dictionary/gender.md +3 -3
  28. package/docs/es/locale_mapper.md +1 -1
  29. package/docs/es/packages/react-intlayer/useI18n.md +250 -0
  30. package/docs/fr/configuration.md +44 -7
  31. package/docs/fr/intlayer_with_nextjs_15.md +0 -1
  32. package/docs/fr/intlayer_with_vite+preact.md +1 -1
  33. package/docs/fr/packages/react-intlayer/useI18n.md +250 -0
  34. package/docs/hi/configuration.md +42 -5
  35. package/docs/hi/dictionary/enumeration.md +0 -2
  36. package/docs/hi/packages/react-intlayer/useI18n.md +259 -0
  37. package/docs/it/configuration.md +42 -5
  38. package/docs/it/dictionary/enumeration.md +0 -1
  39. package/docs/it/packages/react-intlayer/useI18n.md +250 -0
  40. package/docs/it/vs_code_extension.md +0 -1
  41. package/docs/ja/configuration.md +43 -28
  42. package/docs/ja/dictionary/enumeration.md +0 -2
  43. package/docs/ja/packages/react-intlayer/useI18n.md +250 -0
  44. package/docs/ko/configuration.md +42 -5
  45. package/docs/ko/dictionary/enumeration.md +0 -2
  46. package/docs/ko/packages/react-intlayer/useI18n.md +250 -0
  47. package/docs/pt/configuration.md +42 -5
  48. package/docs/pt/packages/react-intlayer/useI18n.md +250 -0
  49. package/docs/ru/configuration.md +42 -5
  50. package/docs/ru/dictionary/enumeration.md +0 -2
  51. package/docs/ru/packages/react-intlayer/useI18n.md +250 -0
  52. package/docs/ru/vs_code_extension.md +0 -1
  53. package/docs/zh/configuration.md +42 -5
  54. package/docs/zh/dictionary/enumeration.md +0 -1
  55. package/docs/zh/packages/react-intlayer/useI18n.md +250 -0
  56. package/frequent_questions/ar/unknown_command.md +1 -1
  57. package/frequent_questions/de/array_as_content_declaration.md +1 -1
  58. package/frequent_questions/de/build_dictionaries.md +1 -1
  59. package/frequent_questions/de/build_error_CI_CD.md +1 -1
  60. package/frequent_questions/de/customized_locale_list.md +1 -1
  61. package/frequent_questions/de/esbuild_error.md +1 -1
  62. package/frequent_questions/de/intlayer_command_undefined.md +1 -1
  63. package/frequent_questions/de/locale_incorect_in_url.md +1 -1
  64. package/frequent_questions/de/static_rendering.md +1 -1
  65. package/frequent_questions/de/translated_path_url.md +1 -1
  66. package/frequent_questions/de/unknown_command.md +1 -1
  67. package/frequent_questions/en-GB/customized_locale_list.md +1 -1
  68. package/frequent_questions/es/array_as_content_declaration.md +1 -1
  69. package/frequent_questions/es/build_dictionaries.md +1 -1
  70. package/frequent_questions/es/customized_locale_list.md +1 -1
  71. package/frequent_questions/es/domain_routing.md +1 -1
  72. package/frequent_questions/es/get_locale_cookie.md +1 -1
  73. package/frequent_questions/es/intlayer_command_undefined.md +1 -1
  74. package/frequent_questions/es/locale_incorect_in_url.md +1 -1
  75. package/frequent_questions/es/static_rendering.md +1 -1
  76. package/frequent_questions/es/translated_path_url.md +1 -1
  77. package/frequent_questions/es/unknown_command.md +1 -1
  78. package/frequent_questions/fr/array_as_content_declaration.md +1 -1
  79. package/frequent_questions/fr/build_dictionaries.md +1 -1
  80. package/frequent_questions/fr/customized_locale_list.md +1 -1
  81. package/frequent_questions/fr/domain_routing.md +1 -1
  82. package/frequent_questions/fr/esbuild_error.md +1 -1
  83. package/frequent_questions/fr/intlayer_command_undefined.md +1 -1
  84. package/frequent_questions/fr/static_rendering.md +1 -1
  85. package/frequent_questions/fr/translated_path_url.md +1 -1
  86. package/frequent_questions/fr/unknown_command.md +1 -1
  87. package/frequent_questions/it/array_as_content_declaration.md +1 -1
  88. package/frequent_questions/it/build_dictionaries.md +1 -1
  89. package/frequent_questions/it/customized_locale_list.md +1 -1
  90. package/frequent_questions/it/esbuild_error.md +1 -1
  91. package/frequent_questions/it/intlayer_command_undefined.md +1 -1
  92. package/frequent_questions/it/locale_incorect_in_url.md +1 -1
  93. package/frequent_questions/it/static_rendering.md +1 -1
  94. package/frequent_questions/it/translated_path_url.md +1 -1
  95. package/frequent_questions/it/unknown_command.md +1 -1
  96. package/frequent_questions/ko/build_dictionaries.md +2 -2
  97. package/frequent_questions/ko/customized_locale_list.md +3 -3
  98. package/frequent_questions/ko/intlayer_command_undefined.md +3 -3
  99. package/frequent_questions/pt/array_as_content_declaration.md +1 -1
  100. package/frequent_questions/pt/build_dictionaries.md +1 -1
  101. package/frequent_questions/pt/build_error_CI_CD.md +1 -1
  102. package/frequent_questions/pt/customized_locale_list.md +1 -1
  103. package/frequent_questions/pt/domain_routing.md +1 -1
  104. package/frequent_questions/pt/esbuild_error.md +1 -1
  105. package/frequent_questions/pt/intlayer_command_undefined.md +1 -1
  106. package/frequent_questions/pt/locale_incorect_in_url.md +1 -1
  107. package/frequent_questions/pt/static_rendering.md +1 -1
  108. package/frequent_questions/pt/translated_path_url.md +1 -1
  109. package/frequent_questions/pt/unknown_command.md +1 -1
  110. package/frequent_questions/zh/build_dictionaries.md +3 -3
  111. package/frequent_questions/zh/customized_locale_list.md +3 -3
  112. package/frequent_questions/zh/esbuild_error.md +3 -3
  113. package/frequent_questions/zh/intlayer_command_undefined.md +3 -3
  114. package/frequent_questions/zh/translated_path_url.md +3 -3
  115. package/package.json +9 -9
  116. package/src/common.ts +0 -1
  117. 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: Documentazione Hook useI18n | react-intlayer
5
+ description: Scopri come utilizzare l'hook useI18n nel pacchetto react-intlayer
6
+ keywords:
7
+ - useI18n
8
+ - i18n
9
+ - traduzione
10
+ - dizionario
11
+ - Intlayer
12
+ - internazionalizzazione
13
+ - documentazione
14
+ - Next.js
15
+ - JavaScript
16
+ - React
17
+ slugs:
18
+ - doc
19
+ - packages
20
+ - react-intlayer
21
+ - useI18n
22
+ ---
23
+
24
+ # Integrazione React: Documentazione Hook `useI18n`
25
+
26
+ Questa sezione fornisce una guida dettagliata su come utilizzare l'hook `useI18n` all'interno delle applicazioni React, permettendo una localizzazione efficiente dei contenuti.
27
+
28
+ ## Importare `useI18n` in React
29
+
30
+ L'hook `useI18n` può essere importato e integrato nelle applicazioni React a seconda del contesto come segue:
31
+
32
+ - **Componenti Client:**
33
+
34
+ ```typescript codeFormat="typescript"
35
+ import { useI18n } from "react-intlayer"; // Usare nei componenti React lato client
36
+ ```
37
+
38
+ ```javascript codeFormat="esm"
39
+ import { useI18n } from "react-intlayer"; // Usare nei componenti React lato client
40
+ ```
41
+
42
+ ```javascript codeFormat="commonjs"
43
+ const { useI18n } = require("react-intlayer"); // Usare nei componenti React lato client
44
+ ```
45
+
46
+ - **Componenti Server:**
47
+
48
+ ```typescript codeFormat="commonjs"
49
+ import { useI18n } from "react-intlayer/server"; // Usare nei componenti React lato server
50
+ ```
51
+
52
+ ```javascript codeFormat="esm"
53
+ import { useI18n } from "react-intlayer/server"; // Usare nei componenti React lato server
54
+ ```
55
+
56
+ ```javascript codeFormat="commonjs"
57
+ const { useI18n } = require("react-intlayer/server"); // Usare nei componenti React lato server
58
+ ```
59
+
60
+ ## Parametri
61
+
62
+ Questo hook accetta due parametri:
63
+
64
+ 1. **`namespace`**: Un namespace del dizionario per delimitare le chiavi di traduzione.
65
+ 2. **`locale`** (opzionale): La locale desiderata. Se non specificata, verrà usata come default la locale del contesto.
66
+
67
+ ## Dizionario
68
+
69
+ Tutte le chiavi del dizionario devono essere dichiarate all'interno dei file di dichiarazione del contenuto per migliorare la sicurezza dei tipi e prevenire errori. [Le istruzioni di configurazione si trovano qui](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/dictionary/get_started.md).
70
+
71
+ ## Esempi di utilizzo in React
72
+
73
+ Esempi di utilizzo dell'hook `useI18n` all'interno di componenti 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("introduzione")}</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("introduzione")}</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> {/* Mostra il titolo */}
152
+ <p>{t("description")}</p> {/* Mostra la descrizione */}
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> {/* Mostra il titolo */}
167
+ <p>{t("description")}</p> {/* Mostra la descrizione */}
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> {/* Mostra il titolo */}
182
+ <p>{t("description")}</p> {/* Mostra la descrizione */}
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> {/* Mostra il titolo */}
197
+ <p>{t("description")}</p> {/* Mostra la descrizione */}
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> {/* Mostra il titolo */}
212
+ <p>{t("description")}</p> {/* Mostra la descrizione */}
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
+ ## Gestione degli Attributi
234
+
235
+ Quando si localizzano gli attributi, accedere correttamente ai valori di traduzione:
236
+
237
+ ```jsx
238
+ <!-- Per gli attributi di accessibilità (es. aria-label), usare .value poiché sono richieste stringhe pure -->
239
+ <button aria-label={t("button.ariaLabel").value}>{t("button.text")}</button>
240
+ ```
241
+
242
+ ## Risorse Aggiuntive
243
+
244
+ - **Intlayer Visual Editor**: Per un'esperienza di gestione dei contenuti più intuitiva, fare riferimento alla documentazione dell'editor visuale [qui](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/intlayer_visual_editor.md).
245
+
246
+ Questa sezione copre specificamente l'integrazione del hook `useI18n` nelle applicazioni React, semplificando il processo di localizzazione e garantendo la coerenza dei contenuti tra le diverse localizzazioni.
247
+
248
+ ## Cronologia della Documentazione
249
+
250
+ - 6.0.0 - 2025-06-29: Scrittura iniziale della documentazione dell'hook `useI18n`
@@ -14,7 +14,6 @@ keywords:
14
14
  - TypeScript
15
15
  slugs:
16
16
  - doc
17
- - it
18
17
  - vs-code-extension
19
18
  ---
20
19
 
@@ -268,10 +268,12 @@ module.exports = config;
268
268
  - **prefixDefault**:
269
269
 
270
270
  - _型_: `boolean`
271
- - _デフォルト_: `true`
271
+ - _デフォルト_: `false`
272
272
  - _説明_: デフォルトのロケールをURLに含めるかどうか。
273
- - _例_: `false`
274
- - _注意_: `false`の場合、デフォルトロケールのURLにはロケールプレフィックスが付きません。
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
- - _注意_: これはアプリケーションのURL構築に影響します。
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
  - _注意_: ロケールクッキーをすべてのリクエストで設定するか、まったく設定しないかを制御します。
292
298
 
293
299
  - **noPrefix**:
300
+
294
301
  - _型_: `boolean`
295
302
  - _デフォルト_: `false`
296
303
  - _説明_: URLからロケールプレフィックスを省略するかどうか。
297
304
  - _例_: `true`
298
- - _注意_: `true`の場合、URLにはロケール情報が含まれません。
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
 
@@ -505,26 +542,4 @@ Intlayerがアプリケーションの国際化をどのように最適化しビ
505
542
  - _説明_: 辞書がどのようにインポートされるかを制御します。
506
543
  - _例_: `'dynamic'`
507
544
  - _注意_: 利用可能なモード:
508
- - "static": 辞書が静的にインポートされます。`useIntlayer`を`useDictionary`に置き換えます。
509
- - "dynamic": 辞書がSuspenseを使用して動的にインポートされます。`useIntlayer`を`useDictionaryDynamic`に置き換えます。
510
- - "async": 辞書が非同期で動的にインポートされます。`useIntlayer`を`await useDictionaryAsync`に置き換えます。
511
- - _注意_: 動的インポートはSuspenseに依存し、レンダリングパフォーマンスに若干の影響を与える可能性があります。
512
- - _注意_: 無効にすると、使用されていない場合でもすべてのロケールが一度に読み込まれます。
513
- - _注意_: このオプションは`@intlayer/babel`および`@intlayer/swc`プラグインに依存します。
514
- - _注意_: すべてのキーが`useIntlayer`呼び出しで静的に宣言されていることを確認してください。例:`useIntlayer('navbar')`。
515
- - _注意_: このオプションは`optimize`が無効の場合は無視されます。
516
- - _注意_: ほとんどの場合、Reactアプリケーションには`"dynamic"`が、Vue.jsアプリケーションには`"async"`が使用されます。
517
- - _注意_: このオプションは`getIntlayer`、`getDictionary`、`useDictionary`、`useDictionaryAsync`、`useDictionaryDynamic`関数に影響しません。
518
-
519
- - **traversePattern**:
520
- - _型_: `string[]`
521
- - _デフォルト_: `['**/*.{js,ts,mjs,cjs,jsx,tsx,mjx,cjx}', '!**/node_modules/**']`
522
- - _説明_: 最適化中にトラバースするファイルを定義するパターン。
523
- - _例_: `['src/**/*.{ts,tsx}', '../ui-library/**/*.{ts,tsx}', '!**/node_modules/**']`
524
- - _注意_: 関連するコードファイルに最適化を制限し、ビルドパフォーマンスを向上させるために使用します。
525
- - _注意_: このオプションは`optimize`が無効の場合は無視されます。
526
- - _注意_: globパターンを使用します。
527
-
528
- ## ドキュメント履歴
529
-
530
- - 5.5.11 - 2025-06-29: `docs`コマンドを追加
545
+ - "static": 辞書が静的にインポートされます。`useIntlayer`を`useDictionary`
@@ -15,8 +15,6 @@ slugs:
15
15
  - doc
16
16
  - concept
17
17
  - content
18
- - ja
19
- - dictionary
20
18
  - enumeration
21
19
  ---
22
20
 
@@ -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
+ - JavaScript
16
+ - React
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
+ このフックは2つのパラメータを受け取ります:
63
+
64
+ 1. **`namespace`**:翻訳キーのスコープを指定する辞書の名前空間。
65
+ 2. **`locale`**(オプション):希望するロケール。指定しない場合は、コンテキストのロケールがデフォルトで使用されます。
66
+
67
+ ## 辞書
68
+
69
+ すべての辞書キーは、型安全性を高めエラーを防ぐためにコンテンツ宣言ファイル内で宣言する必要があります。[設定手順はこちら](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/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/ja/intlayer_visual_editor.md)をご参照ください。
245
+
246
+ このセクションでは、Reactアプリケーションにおける `useI18n` フックの統合について具体的に説明しており、ローカライズプロセスを簡素化し、異なるロケール間でのコンテンツの一貫性を確保します。
247
+
248
+ ## ドキュメント履歴
249
+
250
+ - 6.0.0 - 2025-06-29: `useI18n` フックのドキュメント初版作成
@@ -268,10 +268,12 @@ module.exports = config;
268
268
  - **prefixDefault**:
269
269
 
270
270
  - _유형_: `boolean`
271
- - _기본값_: `true`
271
+ - _기본값_: `false`
272
272
  - _설명_: 기본 로케일을 URL에 포함할지 여부입니다.
273
- - _예시_: `false`
274
- - _참고_: `false`로 설정하면 기본 로케일의 URL에는 로케일 접두사가 포함되지 않습니다.
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
- - _참고_: 이 설정은 애플리케이션의 URL 구성 방식에 영향을 미칩니다.
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
  - _참고_: 로케일 쿠키를 모든 요청에서 설정할지 또는 설정하지 않을지를 제어합니다.
292
298
 
293
299
  - **noPrefix**:
300
+
294
301
  - _유형_: `boolean`
295
302
  - _기본값_: `false`
296
303
  - _설명_: URL에서 로케일 접두사를 생략할지 여부를 나타냅니다.
297
304
  - _예시_: `true`
298
- - _참고_: `true`로 설정하면 URL에 로케일 정보가 포함되지 않습니다.
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