@intlayer/docs 7.3.14 → 7.3.15

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 (159) hide show
  1. package/blog/ar/intlayer_with_i18next.md +3 -0
  2. package/blog/ar/intlayer_with_next-i18next.md +3 -0
  3. package/blog/ar/intlayer_with_next-intl.md +3 -0
  4. package/blog/ar/intlayer_with_react-i18next.md +3 -0
  5. package/blog/ar/intlayer_with_react-intl.md +3 -0
  6. package/blog/ar/intlayer_with_vue-i18n.md +3 -0
  7. package/blog/de/intlayer_with_i18next.md +3 -0
  8. package/blog/de/intlayer_with_next-i18next.md +3 -0
  9. package/blog/de/intlayer_with_next-intl.md +3 -0
  10. package/blog/de/intlayer_with_react-i18next.md +3 -0
  11. package/blog/de/intlayer_with_react-intl.md +3 -0
  12. package/blog/de/intlayer_with_vue-i18n.md +3 -0
  13. package/blog/en/intlayer_with_i18next.md +7 -0
  14. package/blog/en/intlayer_with_next-i18next.md +3 -0
  15. package/blog/en/intlayer_with_next-intl.md +7 -0
  16. package/blog/en/intlayer_with_react-i18next.md +3 -0
  17. package/blog/en/intlayer_with_react-intl.md +3 -0
  18. package/blog/en/intlayer_with_vue-i18n.md +3 -0
  19. package/blog/en-GB/intlayer_with_i18next.md +3 -0
  20. package/blog/en-GB/intlayer_with_next-i18next.md +3 -0
  21. package/blog/en-GB/intlayer_with_next-intl.md +3 -0
  22. package/blog/en-GB/intlayer_with_react-i18next.md +3 -0
  23. package/blog/en-GB/intlayer_with_react-intl.md +3 -0
  24. package/blog/en-GB/intlayer_with_vue-i18n.md +3 -0
  25. package/blog/es/intlayer_with_i18next.md +3 -0
  26. package/blog/es/intlayer_with_next-i18next.md +3 -0
  27. package/blog/es/intlayer_with_next-intl.md +3 -0
  28. package/blog/es/intlayer_with_react-i18next.md +3 -0
  29. package/blog/es/intlayer_with_react-intl.md +3 -0
  30. package/blog/es/intlayer_with_vue-i18n.md +3 -0
  31. package/blog/fr/intlayer_with_i18next.md +3 -0
  32. package/blog/fr/intlayer_with_next-i18next.md +3 -0
  33. package/blog/fr/intlayer_with_next-intl.md +3 -0
  34. package/blog/fr/intlayer_with_react-i18next.md +3 -0
  35. package/blog/fr/intlayer_with_react-intl.md +3 -0
  36. package/blog/fr/intlayer_with_vue-i18n.md +3 -0
  37. package/blog/hi/intlayer_with_i18next.md +3 -0
  38. package/blog/hi/intlayer_with_next-i18next.md +3 -0
  39. package/blog/hi/intlayer_with_next-intl.md +3 -0
  40. package/blog/hi/intlayer_with_react-i18next.md +3 -0
  41. package/blog/hi/intlayer_with_react-intl.md +3 -0
  42. package/blog/hi/intlayer_with_vue-i18n.md +3 -0
  43. package/blog/id/intlayer_with_i18next.md +3 -0
  44. package/blog/id/intlayer_with_next-i18next.md +3 -0
  45. package/blog/id/intlayer_with_next-intl.md +3 -0
  46. package/blog/id/intlayer_with_react-i18next.md +3 -0
  47. package/blog/id/intlayer_with_react-intl.md +3 -0
  48. package/blog/id/intlayer_with_vue-i18n.md +3 -0
  49. package/blog/it/intlayer_with_i18next.md +3 -0
  50. package/blog/it/intlayer_with_next-i18next.md +3 -0
  51. package/blog/it/intlayer_with_next-intl.md +3 -0
  52. package/blog/it/intlayer_with_react-i18next.md +3 -0
  53. package/blog/it/intlayer_with_react-intl.md +3 -0
  54. package/blog/it/intlayer_with_vue-i18n.md +3 -0
  55. package/blog/ja/intlayer_with_i18next.md +3 -0
  56. package/blog/ja/intlayer_with_next-i18next.md +3 -0
  57. package/blog/ja/intlayer_with_next-intl.md +3 -0
  58. package/blog/ja/intlayer_with_react-i18next.md +3 -0
  59. package/blog/ja/intlayer_with_react-intl.md +3 -0
  60. package/blog/ja/intlayer_with_vue-i18n.md +3 -0
  61. package/blog/ko/intlayer_with_i18next.md +3 -0
  62. package/blog/ko/intlayer_with_next-i18next.md +3 -0
  63. package/blog/ko/intlayer_with_next-intl.md +3 -0
  64. package/blog/ko/intlayer_with_react-i18next.md +3 -0
  65. package/blog/ko/intlayer_with_react-intl.md +3 -0
  66. package/blog/ko/intlayer_with_vue-i18n.md +3 -0
  67. package/blog/pl/intlayer_with_i18next.md +3 -0
  68. package/blog/pl/intlayer_with_next-i18next.md +3 -0
  69. package/blog/pl/intlayer_with_next-intl.md +3 -0
  70. package/blog/pl/intlayer_with_react-i18next.md +3 -0
  71. package/blog/pl/intlayer_with_react-intl.md +3 -0
  72. package/blog/pl/intlayer_with_vue-i18n.md +3 -0
  73. package/blog/pt/intlayer_with_i18next.md +3 -0
  74. package/blog/pt/intlayer_with_next-i18next.md +3 -0
  75. package/blog/pt/intlayer_with_next-intl.md +3 -0
  76. package/blog/pt/intlayer_with_react-i18next.md +3 -0
  77. package/blog/pt/intlayer_with_react-intl.md +3 -0
  78. package/blog/pt/intlayer_with_vue-i18n.md +3 -0
  79. package/blog/ru/intlayer_with_i18next.md +3 -0
  80. package/blog/ru/intlayer_with_next-i18next.md +3 -0
  81. package/blog/ru/intlayer_with_next-intl.md +3 -0
  82. package/blog/ru/intlayer_with_react-i18next.md +3 -0
  83. package/blog/ru/intlayer_with_react-intl.md +3 -0
  84. package/blog/ru/intlayer_with_vue-i18n.md +3 -0
  85. package/blog/tr/intlayer_with_i18next.md +3 -0
  86. package/blog/tr/intlayer_with_next-i18next.md +3 -0
  87. package/blog/tr/intlayer_with_next-intl.md +3 -0
  88. package/blog/tr/intlayer_with_react-i18next.md +3 -0
  89. package/blog/tr/intlayer_with_vue-i18n.md +3 -0
  90. package/blog/vi/intlayer_with_i18next.md +3 -0
  91. package/blog/vi/intlayer_with_next-i18next.md +3 -0
  92. package/blog/vi/intlayer_with_next-intl.md +3 -0
  93. package/blog/vi/intlayer_with_react-i18next.md +3 -0
  94. package/blog/vi/intlayer_with_react-intl.md +3 -0
  95. package/blog/vi/intlayer_with_vue-i18n.md +3 -0
  96. package/blog/zh/intlayer_with_i18next.md +3 -0
  97. package/blog/zh/intlayer_with_next-i18next.md +3 -0
  98. package/blog/zh/intlayer_with_next-intl.md +3 -0
  99. package/blog/zh/intlayer_with_react-i18next.md +3 -0
  100. package/blog/zh/intlayer_with_react-intl.md +3 -0
  101. package/blog/zh/intlayer_with_vue-i18n.md +3 -0
  102. package/docs/ar/intlayer_with_lynx+react.md +1 -1
  103. package/docs/ar/intlayer_with_vite+react.md +99 -331
  104. package/docs/ar/plugins/sync-json.md +3 -0
  105. package/docs/de/intlayer_with_lynx+react.md +1 -1
  106. package/docs/de/intlayer_with_vite+react.md +116 -380
  107. package/docs/de/plugins/sync-json.md +3 -0
  108. package/docs/en/intlayer_with_vite+react.md +6 -10
  109. package/docs/en/plugins/sync-json.md +3 -0
  110. package/docs/en-GB/intlayer_with_vite+react.md +62 -74
  111. package/docs/en-GB/plugins/sync-json.md +3 -0
  112. package/docs/es/intlayer_with_vite+react.md +101 -333
  113. package/docs/es/plugins/sync-json.md +3 -0
  114. package/docs/fr/intlayer_with_vite+react.md +101 -357
  115. package/docs/fr/plugins/sync-json.md +3 -0
  116. package/docs/hi/intlayer_with_vite+react.md +120 -333
  117. package/docs/hi/plugins/sync-json.md +3 -0
  118. package/docs/id/intlayer_with_vite+react.md +7 -13
  119. package/docs/id/plugins/sync-json.md +3 -0
  120. package/docs/it/intlayer_with_lynx+react.md +1 -1
  121. package/docs/it/intlayer_with_vite+react.md +121 -393
  122. package/docs/it/plugins/sync-json.md +3 -0
  123. package/docs/ja/intlayer_with_vite+react.md +106 -378
  124. package/docs/ja/plugins/sync-json.md +3 -0
  125. package/docs/ko/intlayer_with_lynx+react.md +1 -1
  126. package/docs/ko/intlayer_with_vite+react.md +90 -322
  127. package/docs/ko/plugins/sync-json.md +3 -0
  128. package/docs/pl/intlayer_with_vite+react.md +25 -21
  129. package/docs/pl/plugins/sync-json.md +3 -0
  130. package/docs/pt/intlayer_with_vite+react.md +96 -328
  131. package/docs/pt/plugins/sync-json.md +3 -0
  132. package/docs/ru/intlayer_with_lynx+react.md +1 -1
  133. package/docs/ru/intlayer_with_vite+react.md +109 -362
  134. package/docs/ru/plugins/sync-json.md +3 -0
  135. package/docs/tr/intlayer_with_vite+react.md +132 -366
  136. package/docs/tr/plugins/sync-json.md +3 -0
  137. package/docs/vi/intlayer_with_vite+react.md +16 -19
  138. package/docs/vi/plugins/sync-json.md +3 -0
  139. package/docs/zh/intlayer_with_tanstack.md +1 -1
  140. package/docs/zh/intlayer_with_vite+react.md +91 -374
  141. package/docs/zh/plugins/sync-json.md +3 -0
  142. package/frequent_questions/ar/customized_locale_list.md +1 -1
  143. package/frequent_questions/de/customized_locale_list.md +1 -1
  144. package/frequent_questions/en/customized_locale_list.md +1 -1
  145. package/frequent_questions/en-GB/customized_locale_list.md +1 -1
  146. package/frequent_questions/es/customized_locale_list.md +1 -1
  147. package/frequent_questions/fr/customized_locale_list.md +1 -1
  148. package/frequent_questions/hi/customized_locale_list.md +1 -1
  149. package/frequent_questions/id/customized_locale_list.md +1 -1
  150. package/frequent_questions/it/customized_locale_list.md +1 -1
  151. package/frequent_questions/ja/customized_locale_list.md +1 -1
  152. package/frequent_questions/ko/customized_locale_list.md +1 -1
  153. package/frequent_questions/pl/customized_locale_list.md +1 -1
  154. package/frequent_questions/pt/customized_locale_list.md +1 -1
  155. package/frequent_questions/ru/customized_locale_list.md +1 -1
  156. package/frequent_questions/tr/customized_locale_list.md +1 -1
  157. package/frequent_questions/vi/customized_locale_list.md +1 -1
  158. package/frequent_questions/zh/customized_locale_list.md +1 -1
  159. package/package.json +6 -6
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  createdAt: 2024-03-07
3
- updatedAt: 2024-03-07
4
- title: Vite and Reactアプリを翻訳する方法 – i18nガイド 2025
3
+ updatedAt: 2025-12-10
4
+ title: ViteReactアプリを翻訳する方法 – i18nガイド 2025
5
5
  description: Intlayerを使ってViteとReactアプリケーションに国際化(i18n)を追加する方法を学びます。このガイドに従ってアプリを多言語対応にしましょう。
6
6
  keywords:
7
7
  - 国際化
@@ -16,26 +16,22 @@ slugs:
16
16
  - environment
17
17
  - vite-and-react
18
18
  applicationTemplate: https://github.com/aymericzip/intlayer-vite-react-template
19
- youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4---
19
+ youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
20
20
  history:
21
21
  - version: 5.5.10
22
22
  date: 2025-06-29
23
23
  changes: 履歴の初期化
24
24
  ---
25
25
 
26
- # IntlayerViteとReactで始める国際化(i18n)
26
+ # Intlayerを使ってViteとReactのウェブサイトを翻訳する | 国際化(i18n)
27
27
 
28
28
  ## 目次
29
29
 
30
30
  <TOC/>
31
31
 
32
- <iframe title="The best i18n solution for Vite and React? Discover Intlayer" class="m-auto aspect-[16/9] w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/dS9L7uJeak4?si=VaKmrYMmXjo3xpk2"/>
33
-
34
- GitHubの[アプリケーションテンプレート](https://github.com/aymericzip/intlayer-vite-react-template)を参照してください。
35
-
36
32
  ## Intlayerとは?
37
33
 
38
- **Intlayer**は、最新のウェブアプリケーションでの多言語対応を簡素化するために設計された革新的なオープンソースの国際化(i18n)ライブラリです。
34
+ **Intlayer**は、最新のウェブアプリケーションにおける多言語対応を簡素化するために設計された革新的なオープンソースの国際化(i18n)ライブラリです。
39
35
 
40
36
  Intlayerを使うと、以下が可能です:
41
37
 
@@ -48,6 +44,27 @@ Intlayerを使うと、以下が可能です:
48
44
 
49
45
  ## ViteとReactアプリケーションでIntlayerをセットアップするステップバイステップガイド
50
46
 
47
+ <Tab defaultTab="video">
48
+ <TabItem label="ビデオ" value="video">
49
+
50
+ <iframe title="ViteとReactに最適なi18nソリューション?Intlayerを発見" class="m-auto aspect-[16/9] w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/dS9L7uJeak4?si=VaKmrYMmXjo3xpk2"/>
51
+
52
+ </TabItem>
53
+ <TabItem label="コード" value="code">
54
+
55
+ <iframe
56
+ src="https://stackblitz.com/github/aymericzip/intlayer-vite-react-template?embed=1&ctl=1&file=intlayer.config.ts"
57
+ className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
58
+ title="Demo CodeSandbox - Intlayerを使ってアプリケーションを国際化する方法"
59
+ sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
60
+ loading="lazy"
61
+ />
62
+
63
+ </TabItem>
64
+ </Tab>
65
+
66
+ GitHubの[Application Template](https://github.com/aymericzip/intlayer-vite-react-template)を参照してください。
67
+
51
68
  ### ステップ1: 依存関係のインストール
52
69
 
53
70
  npmを使って必要なパッケージをインストールします:
@@ -69,7 +86,7 @@ yarn add vite-intlayer --save-dev
69
86
 
70
87
  - **intlayer**
71
88
 
72
- 設定管理、翻訳、[コンテンツ宣言](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/get_started.md)、トランスパイル、および[CLIコマンド](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/intlayer_cli.md)のための国際化ツールを提供するコアパッケージです。
89
+ 設定管理、翻訳、[コンテンツ宣言](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/content_file.md)、トランスパイル、および[CLIコマンド](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/cli/index.md)のための国際化ツールを提供するコアパッケージです。
73
90
 
74
91
  - **react-intlayer**
75
92
  IntlayerをReactアプリケーションと統合するパッケージです。Reactの国際化のためのコンテキストプロバイダーとフックを提供します。
@@ -137,7 +154,7 @@ const config = {
137
154
  module.exports = config;
138
155
  ```
139
156
 
140
- > この設定ファイルを通じて、ローカライズされたURL、ミドルウェアのリダイレクション、クッキー名、コンテンツ宣言の場所と拡張子、コンソールでのIntlayerログの無効化などを設定できます。利用可能なパラメータの完全なリストについては、[設定ドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/configuration.md)を参照してください。
157
+ この設定ファイルを通じて、ローカライズされたURL、ミドルウェアのリダイレクション、クッキー名、コンテンツ宣言の場所と拡張子、コンソールでのIntlayerログの無効化などを設定できます。利用可能なパラメータの完全なリストについては、[設定ドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/configuration.md)を参照してください。
141
158
 
142
159
  ### ステップ3: Vite設定にIntlayerを統合する
143
160
 
@@ -176,7 +193,7 @@ module.exports = defineConfig({
176
193
  });
177
194
  ```
178
195
 
179
- > `intlayer()` Viteプラグインは、IntlayerをViteと統合するために使用されます。これにより、コンテンツ宣言ファイルのビルドが保証され、開発モードで監視されます。また、Viteアプリケーション内でIntlayerの環境変数を定義します。さらに、パフォーマンスを最適化するためのエイリアスも提供します。
196
+ `intlayer()` Viteプラグインは、IntlayerをViteと統合するために使用されます。これにより、コンテンツ宣言ファイルのビルドが保証され、開発モードで監視されます。また、Viteアプリケーション内でIntlayerの環境変数を定義します。さらに、パフォーマンスを最適化するためのエイリアスも提供します。
180
197
 
181
198
  ### ステップ4: コンテンツを宣言する
182
199
 
@@ -248,11 +265,13 @@ const appContent = {
248
265
  en: "Vite logo",
249
266
  fr: "Logo Vite",
250
267
  es: "Logo Vite",
268
+ ja: "Vite ロゴ",
251
269
  }),
252
270
  reactLogo: t({
253
271
  en: "React logo",
254
272
  fr: "Logo React",
255
273
  es: "Logo React",
274
+ ja: "React ロゴ",
256
275
  }),
257
276
 
258
277
  title: "Vite + React",
@@ -261,6 +280,7 @@ const appContent = {
261
280
  en: "count is ",
262
281
  fr: "le compte est ",
263
282
  es: "el recuento es ",
283
+ ja: "カウントは ",
264
284
  }),
265
285
 
266
286
  edit:
@@ -270,8 +290,7 @@ const appContent = {
270
290
  // コンテンツ内でReactノードを使用する場合はReactをインポートすることを忘れないでください
271
291
  en: (
272
292
  <>
273
- Edit <code>src/App.tsx</code>{" "}
274
- を編集して保存し、HMRをテストしてください
293
+ Edit <code>src/App.tsx</code> and save to test HMR
275
294
  </>
276
295
  ),
277
296
  fr: (
@@ -284,12 +303,18 @@ const appContent = {
284
303
  Edita <code>src/App.tsx</code> y guarda para probar HMR
285
304
  </>
286
305
  ),
306
+ ja: (
307
+ <>
308
+ <code>src/App.tsx</code> を編集して保存し、HMRをテストしてください
309
+ </>
310
+ ),
287
311
  },
288
312
 
289
313
  readTheDocs: t({
290
- en: "ViteReactのロゴをクリックして詳細を確認してください",
314
+ en: "Click on the Vite and React logos to learn more",
291
315
  fr: "Cliquez sur les logos Vite et React pour en savoir plus",
292
316
  es: "Haga clic en los logotipos de Vite y React para obtener más información",
317
+ ja: "ViteとReactのロゴをクリックして詳細を確認してください",
293
318
  }),
294
319
  },
295
320
  };
@@ -422,9 +447,9 @@ module.exports = appContent;
422
447
 
423
448
  > あなたのコンテンツ宣言は、`contentDir`ディレクトリ(デフォルトは`./src`)に含まれた時点で、アプリケーションのどこにでも定義できます。そして、コンテンツ宣言ファイルの拡張子(デフォルトは`.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`)に一致する必要があります。
424
449
 
425
- > 詳細については、[コンテンツ宣言のドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/get_started.md)を参照してください。
450
+ > 詳細については、[コンテンツ宣言のドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/content_file.md)を参照してください。
426
451
 
427
- > コンテンツファイルにTSXコードが含まれている場合は、`import React from "react";`をコンテンツファイルにインポートすることを検討してください。
452
+ コンテンツファイルにTSXコードが含まれている場合は、`import React from "react";`をコンテンツファイルにインポートすることを検討してください。
428
453
 
429
454
  ### ステップ5: コード内でIntlayerを利用する
430
455
 
@@ -641,82 +666,10 @@ const LocaleSwitcher = () => {
641
666
  アプリケーションにローカライズされたルーティングを追加するには、アプリケーションのルートをラップし、ロケールベースのルーティングを処理する `LocaleRouter` コンポーネントを作成できます。以下は [React Router](https://reactrouter.com/home) を使用した例です。
642
667
 
643
668
  ```tsx fileName="src/components/LocaleRouter.tsx" codeFormat="typescript"
644
- // 必要な依存関係と関数のインポート
645
- import { type Locales, configuration, getPathWithoutLocale } from "intlayer"; // 'intlayer'からのユーティリティ関数と型
669
+ import { localeMap } from "intlayer"; // 'intlayer'からのユーティリティ関数と型
646
670
  import type { FC, PropsWithChildren } from "react"; // 関数コンポーネントとプロパティのReact型
647
671
  import { IntlayerProvider } from "react-intlayer"; // 国際化コンテキストのプロバイダー
648
- import {
649
- BrowserRouter,
650
- Routes,
651
- Route,
652
- Navigate,
653
- useLocation,
654
- } from "react-router-dom"; // ナビゲーション管理用のルーターコンポーネント
655
-
656
- // Intlayerから設定を分割代入
657
- const { internationalization, middleware } = configuration;
658
- const { locales, defaultLocale } = internationalization;
659
-
660
- /**
661
- * ローカリゼーションを処理し、子要素を適切なロケールコンテキストでラップするコンポーネント。
662
- * URLベースのロケール検出と検証を管理します。
663
- */
664
- const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({
665
- children,
666
- locale,
667
- }) => {
668
- const { pathname, search } = useLocation(); // 現在のURLパスを取得
669
-
670
- // 現在のロケールを決定し、指定がなければデフォルトロケールを使用
671
- const currentLocale = locale ?? defaultLocale;
672
-
673
- // パスからロケールのプレフィックスを取り除き、ベースパスを構築
674
- const pathWithoutLocale = getPathWithoutLocale(
675
- pathname // 現在のURLパス
676
- );
677
-
678
- /**
679
- * middleware.prefixDefaultがtrueの場合、デフォルトロケールには常にプレフィックスを付ける必要があります。
680
- */
681
- if (middleware.prefixDefault) {
682
- // ロケールの検証
683
- if (!locale || !locales.includes(locale)) {
684
- // 更新されたパスでデフォルトロケールへリダイレクト
685
- return (
686
- <Navigate
687
- to={`/${defaultLocale}/${pathWithoutLocale}${search}`}
688
- replace // 現在の履歴エントリを新しいものに置き換える
689
- />
690
- );
691
- }
692
-
693
- // IntlayerProviderで子要素をラップし、現在のロケールを設定する
694
- return (
695
- <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
696
- );
697
- } else {
698
- /**
699
- * middleware.prefixDefaultがfalseの場合、デフォルトロケールはプレフィックスされません。
700
- * 現在のロケールが有効であり、デフォルトロケールでないことを確認します。
701
- */
702
- if (
703
- currentLocale.toString() !== defaultLocale.toString() &&
704
- !locales
705
- .filter(
706
- (locale) => locale.toString() !== defaultLocale.toString() // デフォルトロケールを除外
707
- )
708
- .includes(currentLocale) // 現在のロケールが有効なロケールのリストに含まれているかをチェック
709
- ) {
710
- // ロケールのプレフィックスなしのパスへリダイレクト
711
- return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
712
- }
713
-
714
- // IntlayerProviderで子要素をラップし、現在のロケールを設定
715
- return (
716
- <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
717
- );
718
- }
719
- };
672
+ import { BrowserRouter, Route, Routes } from "react-router-dom"; // ナビゲーション管理用のルーターコンポーネント
720
673
 
721
674
  /**
722
675
  * ロケール固有のルートを設定するルーターコンポーネント。
@@ -725,258 +678,82 @@ const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({
725
678
  export const LocaleRouter: FC<PropsWithChildren> = ({ children }) => (
726
679
  <BrowserRouter>
727
680
  <Routes>
728
- {locales
729
- .filter(
730
- (locale) => middleware.prefixDefault || locale !== defaultLocale
731
- )
732
- .map((locale) => (
733
- <Route
734
- // ロケールをキャプチャするルートパターン(例: /en/, /fr/)およびそれに続くすべてのパスにマッチ
735
- path={`/${locale}/*`}
736
- key={locale}
737
- element={<AppLocalized locale={locale}>{children}</AppLocalized>} // ロケール管理で子要素をラップ
738
- />
739
- ))}
740
-
741
- {
742
- // デフォルトロケールのプレフィックスが無効の場合、ルートパスで直接子要素をレンダリング
743
- !middleware.prefixDefault && (
744
- <Route
745
- path="*"
746
- element={
747
- <AppLocalized locale={defaultLocale}>{children}</AppLocalized>
748
- } // ロケール管理で子要素をラップ
749
- />
750
- )
751
- }
681
+ {localeMap(({ locale, urlPrefix }) => (
682
+ <Route
683
+ // ロケールをキャプチャするルートパターン(例: /en/, /fr/)およびそれに続くすべてのパスにマッチ
684
+ path={`${urlPrefix}/*`}
685
+ key={locale}
686
+ element={
687
+ <IntlayerProvider locale={locale}>{children}</IntlayerProvider>
688
+ } // ロケール管理で子要素をラップ
689
+ />
690
+ ))}
752
691
  </Routes>
753
692
  </BrowserRouter>
754
693
  );
755
694
  ```
756
695
 
757
696
  ```jsx fileName="src/components/LocaleRouter.mjx" codeFormat="esm"
758
- // 必要な依存関係と関数のインポート
759
- import { configuration, getPathWithoutLocale } from "intlayer"; // 'intlayer'からのユーティリティ関数と型
760
- // 'intlayer'からのユーティリティ関数と型
761
- import { IntlayerProvider } from "react-intlayer"; // 国際化コンテキストのプロバイダー
762
- import {
763
- BrowserRouter,
764
- Routes,
765
- Route,
766
- Navigate,
767
- useLocation,
768
- } from "react-router-dom"; // ナビゲーション管理のためのルーターコンポーネント
769
-
770
- // Intlayerからの設定の分割代入
771
- const { internationalization, middleware } = configuration;
772
- const { locales, defaultLocale } = internationalization;
773
-
774
- /**
775
- * ローカリゼーションを処理し、適切なロケールコンテキストで子要素をラップするコンポーネント。
776
- /**
777
- * URLベースのロケール検出と検証を管理します。
778
- */
779
- const AppLocalized = ({ children, locale }) => {
780
- const { pathname, search } = useLocation(); // 現在のURLパスを取得
781
-
782
- // 現在のロケールを決定し、指定がなければデフォルトにフォールバック
783
- const currentLocale = locale ?? defaultLocale;
784
-
785
- // パスからロケールのプレフィックスを削除してベースパスを構築
786
- const pathWithoutLocale = getPathWithoutLocale(
787
- pathname // 現在のURLパス
788
- );
789
-
790
- /**
791
- * middleware.prefixDefaultがtrueの場合、デフォルトロケールは常にプレフィックスされるべきです。
792
- */
793
- if (middleware.prefixDefault) {
794
- // ロケールの検証
795
- if (!locale || !locales.includes(locale)) {
796
- // 更新されたパスでデフォルトロケールへリダイレクト
797
- return (
798
- <Navigate
799
- to={`/${defaultLocale}/${pathWithoutLocale}${search}`}
800
- replace // 現在の履歴エントリを新しいものに置き換えます
801
- />
802
- );
803
- }
804
-
805
- // IntlayerProviderで子要素をラップし、現在のロケールを設定します
806
- return (
807
- <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
808
- );
809
- } else {
810
- /**
811
- * middleware.prefixDefaultがfalseの場合、デフォルトロケールはプレフィックスされません。
812
- * 現在のロケールが有効であり、デフォルトロケールでないことを確認します。
813
- */
814
- if (
815
- currentLocale.toString() !== defaultLocale.toString() &&
816
- !locales
817
- .filter(
818
- (locale) => locale.toString() !== defaultLocale.toString() // デフォルトロケールを除外
819
- )
820
- .includes(currentLocale) // 現在のロケールが有効なロケールのリストに含まれているかをチェック
821
- ) {
822
- // ロケールのプレフィックスなしのパスにリダイレクト
823
- return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
824
- }
825
-
826
- // IntlayerProviderで子要素をラップし、現在のロケールを設定
827
- return (
828
- <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
829
- );
830
- }
831
- };
697
+ import { localeMap } from 'intlayer'; // 'intlayer'からのユーティリティ関数と型
698
+ import type { FC, PropsWithChildren } from 'react'; // 関数コンポーネントとプロパティ用のReact型
699
+ import { IntlayerProvider } from 'react-intlayer'; // 国際化コンテキストのプロバイダー
700
+ import { BrowserRouter, Route, Routes } from 'react-router-dom'; // ナビゲーション管理用のルーターコンポーネント
832
701
 
833
702
  /**
834
703
  * ロケール固有のルートを設定するルーターコンポーネント。
835
704
  * React Routerを使用してナビゲーションを管理し、ローカライズされたコンポーネントをレンダリングします。
836
705
  */
837
- export const LocaleRouter = ({ children }) => (
706
+ export const LocaleRouter: FC<PropsWithChildren> = ({ children }) => (
838
707
  <BrowserRouter>
839
708
  <Routes>
840
- {locales
841
- .filter(
842
- (locale) => middleware.prefixDefault || locale !== defaultLocale
843
- )
844
- .map((locale) => (
845
- <Route
846
- // ロケールをキャプチャするルートパターン(例:/en/、/fr/)およびその後のすべてのパスにマッチ
847
- path={`/${locale}/*`}
848
- key={locale}
849
- element={<AppLocalized locale={locale}>{children}</AppLocalized>} // ロケール管理で子要素をラップ
850
- />
851
- ))}
852
-
853
- {
854
- // デフォルトロケールのプレフィックスが無効の場合、ルートパスで直接子要素をレンダリング
855
- !middleware.prefixDefault && (
856
- <Route
857
- path="*"
858
- element={
859
- <AppLocalized locale={defaultLocale}>{children}</AppLocalized>
860
- } // ロケール管理で子要素をラップ
861
- />
862
- )
863
- }
709
+ {localeMap(({ locale, urlPrefix }) => (
710
+ <Route
711
+ // ロケールをキャプチャするルートパターン(例:/en/、/fr/)およびその後のすべてのパスにマッチ
712
+ path={`${urlPrefix}/*`}
713
+ key={locale}
714
+ element={
715
+ <IntlayerProvider locale={locale}>{children}</IntlayerProvider>
716
+ } // ロケール管理で子要素をラップ
717
+ />
718
+ ))}
864
719
  </Routes>
865
720
  </BrowserRouter>
866
721
  );
867
722
  ```
868
723
 
869
724
  ```jsx fileName="src/components/LocaleRouter.cjx" codeFormat="commonjs"
870
- // 必要な依存関係と関数のインポート
871
- const { configuration, getPathWithoutLocale } = require("intlayer"); // 'intlayer'からのユーティリティ関数と型
872
- const { IntlayerProvider, useLocale } = require("react-intlayer"); // 国際化コンテキストのプロバイダー
873
- const {
874
- BrowserRouter,
875
- Routes,
876
- Route,
877
- Navigate,
878
- useLocation,
879
- } = require("react-router-dom"); // ナビゲーション管理のためのルーターコンポーネント
880
-
881
- // Intlayerからの設定の分割代入
882
- const { internationalization, middleware } = configuration;
883
- const { locales, defaultLocale } = internationalization;
884
-
885
- /**
886
- * ローカリゼーションを処理し、子要素を適切なロケールコンテキストでラップするコンポーネント。
887
- * URLベースのロケール検出と検証を管理する。
888
- */
889
- const AppLocalized = ({ children, locale }) => {
890
- const { pathname, search } = useLocation(); // 現在のURLパスを取得
891
-
892
- // 現在のロケールを決定。指定がなければデフォルトロケールを使用
893
- const currentLocale = locale ?? defaultLocale;
894
-
895
- // パスからロケールのプレフィックスを取り除き、ベースパスを作成
896
- const pathWithoutLocale = getPathWithoutLocale(
897
- pathname // 現在のURLパス
898
- );
899
-
900
- /**
901
- * middleware.prefixDefaultがtrueの場合、デフォルトロケールは常にプレフィックスされるべき
902
- */
903
- if (middleware.prefixDefault) {
904
- // ロケールの検証
905
- if (!locale || !locales.includes(locale)) {
906
- // 更新されたパスでデフォルトロケールへリダイレクト
907
- return (
908
- <Navigate
909
- to={`/${defaultLocale}/${pathWithoutLocale}${search}`}
910
- replace // 現在の履歴エントリを新しいものに置き換えます
911
- />
912
- );
913
- }
914
-
915
- // IntlayerProviderで子要素をラップし、現在のロケールを設定します
916
- return (
917
- <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
918
- );
919
- } else {
920
- /**
921
- * middleware.prefixDefaultがfalseの場合、デフォルトのロケールはプレフィックスされません。
922
- * 現在のロケールが有効であり、デフォルトのロケールでないことを確認します。
923
- */
924
- if (
925
- currentLocale.toString() !== defaultLocale.toString() &&
926
- !locales
927
- .filter(
928
- (locale) => locale.toString() !== defaultLocale.toString() // デフォルトのロケールを除外
929
- )
930
- .includes(currentLocale) // 現在のロケールが有効なロケールのリストに含まれているか確認
931
- ) {
932
- // ロケールプレフィックスなしのパスにリダイレクト
933
- return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
934
- }
935
-
936
- // IntlayerProviderで子要素をラップし、現在のロケールを設定
937
- return (
938
- <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
939
- );
940
- }
941
- };
725
+ const { localeMap } = require("intlayer"); // 'intlayer'からのユーティリティ関数と型
726
+ const React = require("react"); // Reactのインポート
727
+ const { IntlayerProvider } = require("react-intlayer"); // 国際化コンテキストのプロバイダー
728
+ const { BrowserRouter, Route, Routes } = require("react-router-dom"); // ナビゲーション管理のためのルーターコンポーネント
942
729
 
943
730
  /**
944
731
  * ロケール固有のルートを設定するルーターコンポーネント。
945
732
  * React Routerを使用してナビゲーションを管理し、ローカライズされたコンポーネントをレンダリングします。
946
733
  */
947
- const LocaleRouter = ({ children }) => (
948
- <BrowserRouter>
949
- <Routes>
950
- {locales
951
- .filter(
952
- (locale) => middleware.prefixDefault || locale !== defaultLocale
953
- )
954
- .map((locale) => (
955
- <Route
956
- // ロケールをキャプチャするルートパターン(例: /en/, /fr/)およびそれに続くすべてのパスにマッチ
957
- path={`/${locale}/*`}
958
- key={locale}
959
- element={<AppLocalized locale={locale}>{children}</AppLocalized>} // 子コンポーネントをロケール管理でラップします
960
- />
961
- ))}
734
+ const LocaleRouter = ({ children }) =>
735
+ React.createElement(
736
+ BrowserRouter,
737
+ {},
738
+ React.createElement(
739
+ Routes,
740
+ {},
741
+ localeMap(({ locale, urlPrefix }) =>
742
+ React.createElement(Route, {
743
+ path: `${urlPrefix}/*`,
744
+ key: locale,
745
+ element: React.createElement(IntlayerProvider, { locale }, children),
746
+ })
747
+ )
748
+ )
749
+ );
962
750
 
963
- {
964
- // デフォルトロケールのプレフィックスが無効の場合、ルートパスで直接子コンポーネントをレンダリングします
965
- !middleware.prefixDefault && (
966
- <Route
967
- path="*"
968
- element={
969
- <AppLocalized locale={defaultLocale}>{children}</AppLocalized>
970
- } // 子コンポーネントをロケール管理でラップします
971
- />
972
- )
973
- }
974
- </Routes>
975
- </BrowserRouter>
976
- );
751
+ exports.LocaleRouter = LocaleRouter;
977
752
  ```
978
753
 
979
- 次に、アプリケーションで `LocaleRouter` コンポーネントを使用できます:
754
+ > 注意: `routing.mode: 'no-prefix' | 'search-params'` を使用している場合、`localeMap` 関数を使用する必要はおそらくありません。
755
+
756
+ 次に、アプリケーションで `LocaleRouter` コンポーネントを使用できます:
980
757
 
981
758
  ```tsx fileName="src/App.tsx" codeFormat="typescript"
982
759
  import { LocaleRouter } from "./components/LocaleRouter";
@@ -1017,6 +794,8 @@ const App = () => (
1017
794
 
1018
795
  並行して、`intlayerProxy` を使用してアプリケーションにサーバーサイドルーティングを追加することもできます。このプラグインは、URL に基づいて現在のロケールを自動的に検出し、適切なロケールクッキーを設定します。ロケールが指定されていない場合、プラグインはユーザーのブラウザの言語設定に基づいて最も適切なロケールを判断します。ロケールが検出されない場合は、デフォルトのロケールにリダイレクトします。
1019
796
 
797
+ > `intlayerProxy`を本番環境で使用するには、`vite-intlayer`パッケージを`devDependencies`から`dependencies`に切り替える必要があることに注意してください。
798
+
1020
799
  ```typescript {3,7} fileName="vite.config.ts" codeFormat="typescript"
1021
800
  import { defineConfig } from "vite";
1022
801
  import react from "@vitejs/plugin-react-swc";
@@ -1062,7 +841,7 @@ import {
1062
841
  getLocaleName,
1063
842
  getLocalizedUrl,
1064
843
  } from "intlayer";
1065
- import { useLocale } from "react-intlayer";
844
+ import { useLocale } from "intlayer";
1066
845
  import { type FC } from "react";
1067
846
 
1068
847
  const LocaleSwitcher: FC = () => {
@@ -1258,7 +1037,7 @@ const LocaleSwitcher = () => {
1258
1037
  > - [`dir` 属性](https://developer.mozilla.org/ja/docs/Web/HTML/Global_attributes/dir)
1259
1038
  > - [`aria-current` 属性](https://developer.mozilla.org/ja/docs/Web/Accessibility/ARIA/Attributes/aria-current)
1260
1039
 
1261
- 以下は、説明を追加しコード例を洗練させた更新版の**ステップ9**です。
1040
+ 以下は、説明を追加しコード例を洗練させた更新版の**ステップ9**です:
1262
1041
 
1263
1042
  ---
1264
1043
 
@@ -1353,32 +1132,6 @@ const useI18nHTMLAttributes = () => {
1353
1132
  module.exports = { useI18nHTMLAttributes };
1354
1133
  ```
1355
1134
 
1356
- #### アプリケーションでのフックの使用方法
1357
-
1358
- ロケールが変更されるたびにHTML属性が更新されるように、メインコンポーネントにフックを統合します:
1359
-
1360
- ```tsx fileName="src/App.tsx" codeFormat="typescript"
1361
- import type { FC } from "react";
1362
- import { IntlayerProvider, useIntlayer } from "react-intlayer";
1363
- import { useI18nHTMLAttributes } from "./hooks/useI18nHTMLAttributes";
1364
- import "./App.css";
1365
-
1366
- const AppContent: FC = () => {
1367
- // ロケールに基づいて<html>タグのlangとdir属性を更新するためにフックを適用します。
1368
- useI18nHTMLAttributes();
1369
-
1370
- // ... コンポーネントの残りの部分
1371
- };
1372
-
1373
- const App: FC = () => (
1374
- <IntlayerProvider>
1375
- <AppContent />
1376
- </IntlayerProvider>
1377
- );
1378
-
1379
- export default App;
1380
- ```
1381
-
1382
1135
  #### アプリケーションでのフックの使用
1383
1136
 
1384
1137
  フックをメインコンポーネントに統合し、ロケールが変更されるたびにHTML属性が更新されるようにします:
@@ -1450,14 +1203,6 @@ module.exports = App;
1450
1203
 
1451
1204
  これらの変更を適用することで、アプリケーションは以下を実現します:
1452
1205
 
1453
- - 現在のロケールを正確に反映する**言語**(`lang`)属性を確実に設定し、SEOやブラウザの動作に重要な役割を果たします。
1454
- - ロケールに応じて**テキストの方向**(`dir`)を調整し、異なる読み順の言語に対して読みやすさと使いやすさを向上させます。
1455
- - これらの属性に依存する支援技術のために、より**アクセシブル**な体験を提供します。
1456
-
1457
- ### (オプション)ステップ10:ローカライズされたリンクコンポーネントの作成
1458
-
1459
- これらの変更を適用することで、アプリケーションは以下を実現します:
1460
-
1461
1206
  - **言語**(`lang`)属性が現在のロケールを正確に反映し、SEOやブラウザの動作に重要な役割を果たします。
1462
1207
  - ロケールに応じて**テキストの方向**(`dir`)を調整し、異なる読み方向の言語に対して読みやすさと使いやすさを向上させます。
1463
1208
  - 支援技術がこれらの属性に依存して最適に機能するため、より**アクセシブル**な体験を提供します。
@@ -1470,7 +1215,7 @@ module.exports = App;
1470
1215
 
1471
1216
  - **SEOとユーザー体験**:ローカライズされたURLは、検索エンジンが言語別のページを正しくインデックスし、ユーザーに好みの言語でコンテンツを提供するのに役立ちます。
1472
1217
  - **一貫性**:アプリケーション全体でローカライズされたリンクを使用することで、ナビゲーションが現在のロケール内に留まり、予期しない言語の切り替えを防ぎます。
1473
- - **保守性**: ローカリゼーションのロジックを単一のコンポーネントに集約することで、URLの管理が簡素化され、アプリケーションの成長に伴いコードベースの保守や拡張が容易になります。
1218
+ - **保守性**:ローカリゼーションのロジックを単一のコンポーネントに集約することで、URLの管理が簡素化され、アプリケーションの成長に伴いコードベースの保守や拡張が容易になります。
1474
1219
 
1475
1220
  以下は、TypeScriptで実装されたローカライズされた `Link` コンポーネントの例です。
1476
1221
 
@@ -1483,11 +1228,10 @@ import {
1483
1228
  } from "react";
1484
1229
  import { useLocale } from "react-intlayer";
1485
1230
 
1486
- export interface LinkProps
1487
- extends DetailedHTMLProps<
1488
- AnchorHTMLAttributes<HTMLAnchorElement>,
1489
- HTMLAnchorElement
1490
- > {}
1231
+ export interface LinkProps extends DetailedHTMLProps<
1232
+ AnchorHTMLAttributes<HTMLAnchorElement>,
1233
+ HTMLAnchorElement
1234
+ > {}
1491
1235
 
1492
1236
  /**
1493
1237
  * 指定されたURLが外部リンクかどうかを判定するユーティリティ関数。
@@ -1612,21 +1356,7 @@ Link.displayName = "Link";
1612
1356
 
1613
1357
  ### TypeScript の設定
1614
1358
 
1615
- Intlayer はモジュール拡張を利用して TypeScript の利点を活かし、コードベースをより強固にします。
1616
-
1617
- ![Autocompletion](https://github.com/aymericzip/intlayer/blob/main/docs/assets/autocompletion.png?raw=true)
1618
-
1619
- ![Translation error](https://github.com/aymericzip/intlayer/blob/main/docs/assets/translation_error.png?raw=true)
1620
-
1621
- TypeScript の設定に自動生成された型が含まれていることを確認してください。
1622
-
1623
- コンポーネントはローカライズされたURLを持つ`<a>`要素を返し、ナビゲーションがロケールに沿って一貫して行われることを保証します。
1624
-
1625
- この`Link`コンポーネントをアプリケーション全体に統合することで、一貫性のある言語対応のユーザー体験を維持しつつ、SEOや使いやすさの向上も期待できます。
1626
-
1627
- ### TypeScriptの設定
1628
-
1629
- Intlayerはモジュール拡張を利用してTypeScriptの利点を活かし、コードベースをより堅牢にします。
1359
+ Intlayerはモジュール拡張を利用してTypeScriptの利点を活かし、コードベースをより強固にします。
1630
1360
 
1631
1361
  ![Autocompletion](https://github.com/aymericzip/intlayer/blob/main/docs/assets/autocompletion.png?raw=true)
1632
1362
 
@@ -1646,12 +1376,12 @@ TypeScriptの設定に自動生成された型を含めることを確認して
1646
1376
 
1647
1377
  ### Gitの設定
1648
1378
 
1649
- Intlayerによって生成されたファイルはGitリポジトリにコミットしないように無視することを推奨します。
1379
+ Intlayerによって生成されたファイルは無視することを推奨します。これにより、それらをGitリポジトリにコミットするのを避けることができます。
1650
1380
 
1651
1381
  これを行うには、`.gitignore`ファイルに以下の指示を追加してください。
1652
1382
 
1653
- ```plaintext
1654
- # IntlayerでVite and Reactを翻訳する | 国際化(i18n)
1383
+ ```plaintext fileName=".gitignore"
1384
+ # Intlayerによって生成されたファイルを無視する
1655
1385
  .intlayer
1656
1386
  ```
1657
1387
 
@@ -1675,5 +1405,3 @@ Intlayerでの開発体験を向上させるために、公式の**Intlayer VS C
1675
1405
  ### さらに進むために
1676
1406
 
1677
1407
  さらに進むには、[ビジュアルエディター](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/intlayer_visual_editor.md)を実装するか、[CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/intlayer_CMS.md)を使用してコンテンツを外部化することができます。
1678
-
1679
- ---