@intlayer/docs 7.3.11 → 7.3.13
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/dist/cjs/generated/docs.entry.cjs +19 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +19 -0
- package/dist/esm/generated/docs.entry.mjs.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/intlayer_with_nuxt.md +294 -438
- package/docs/ar/intlayer_with_react_router_v7.md +33 -4
- package/docs/ar/intlayer_with_react_router_v7_fs_routes.md +516 -0
- package/docs/ar/intlayer_with_tanstack.md +2 -12
- package/docs/ar/intlayer_with_vite+vue.md +1 -0
- package/docs/de/intlayer_with_nuxt.md +284 -410
- package/docs/de/intlayer_with_react_router_v7.md +33 -4
- package/docs/de/intlayer_with_react_router_v7_fs_routes.md +573 -0
- package/docs/de/intlayer_with_tanstack.md +1 -0
- package/docs/de/intlayer_with_vite+vue.md +1 -0
- package/docs/en/intlayer_with_nuxt.md +237 -341
- package/docs/en/intlayer_with_react_router_v7.md +24 -0
- package/docs/en/intlayer_with_react_router_v7_fs_routes.md +570 -0
- package/docs/en/intlayer_with_tanstack.md +2 -12
- package/docs/en/intlayer_with_vite+vue.md +49 -48
- package/docs/en-GB/intlayer_with_nuxt.md +254 -378
- package/docs/en-GB/intlayer_with_react_router_v7.md +33 -4
- package/docs/en-GB/intlayer_with_react_router_v7_fs_routes.md +513 -0
- package/docs/en-GB/intlayer_with_tanstack.md +2 -12
- package/docs/en-GB/intlayer_with_vite+vue.md +1 -0
- package/docs/es/intlayer_with_nuxt.md +271 -390
- package/docs/es/intlayer_with_react_router_v7.md +33 -4
- package/docs/es/intlayer_with_react_router_v7_fs_routes.md +575 -0
- package/docs/es/intlayer_with_tanstack.md +1 -0
- package/docs/es/intlayer_with_vite+vue.md +1 -2
- package/docs/fr/intlayer_with_nuxt.md +278 -405
- package/docs/fr/intlayer_with_react_router_v7.md +34 -5
- package/docs/fr/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/fr/intlayer_with_tanstack.md +1 -0
- package/docs/fr/intlayer_with_vite+vue.md +1 -0
- package/docs/hi/intlayer_with_nuxt.md +303 -447
- package/docs/hi/intlayer_with_react_router_v7.md +33 -4
- package/docs/hi/intlayer_with_react_router_v7_fs_routes.md +518 -0
- package/docs/hi/intlayer_with_tanstack.md +2 -12
- package/docs/hi/intlayer_with_vite+vue.md +1 -0
- package/docs/id/intlayer_with_nuxt.md +266 -395
- package/docs/id/intlayer_with_react_router_v7.md +29 -4
- package/docs/id/intlayer_with_react_router_v7_fs_routes.md +521 -0
- package/docs/id/intlayer_with_tanstack.md +2 -12
- package/docs/id/intlayer_with_vite+vue.md +1 -0
- package/docs/it/intlayer_with_nuxt.md +299 -423
- package/docs/it/intlayer_with_react_router_v7.md +33 -4
- package/docs/it/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/it/intlayer_with_tanstack.md +1 -0
- package/docs/ja/intlayer_with_nuxt.md +309 -432
- package/docs/ja/intlayer_with_react_router_v7.md +33 -4
- package/docs/ja/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/ja/intlayer_with_tanstack.md +2 -12
- package/docs/ja/intlayer_with_vite+vue.md +1 -0
- package/docs/ko/intlayer_with_nuxt.md +295 -422
- package/docs/ko/intlayer_with_react_router_v7.md +33 -4
- package/docs/ko/intlayer_with_react_router_v7_fs_routes.md +515 -0
- package/docs/ko/intlayer_with_tanstack.md +2 -12
- package/docs/ko/intlayer_with_vite+vue.md +1 -0
- package/docs/pl/intlayer_with_nuxt.md +273 -476
- package/docs/pl/intlayer_with_react_router_v7.md +32 -5
- package/docs/pl/intlayer_with_react_router_v7_fs_routes.md +615 -0
- package/docs/pl/intlayer_with_tanstack.md +2 -12
- package/docs/pl/intlayer_with_vite+vue.md +1 -0
- package/docs/pt/intlayer_with_nuxt.md +277 -420
- package/docs/pt/intlayer_with_react_router_v7.md +28 -0
- package/docs/pt/intlayer_with_tanstack.md +1 -0
- package/docs/ru/intlayer_with_nuxt.md +287 -425
- package/docs/ru/intlayer_with_react_router_v7.md +33 -4
- package/docs/ru/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/ru/intlayer_with_tanstack.md +1 -0
- package/docs/ru/intlayer_with_vite+vue.md +1 -0
- package/docs/tr/intlayer_with_nuxt.md +313 -406
- package/docs/tr/intlayer_with_react_router_v7.md +33 -4
- package/docs/tr/intlayer_with_react_router_v7_fs_routes.md +572 -0
- package/docs/tr/intlayer_with_tanstack.md +2 -12
- package/docs/tr/intlayer_with_vite+vue.md +1 -0
- package/docs/vi/intlayer_with_nuxt.md +273 -418
- package/docs/vi/intlayer_with_react_router_v7.md +29 -4
- package/docs/vi/intlayer_with_react_router_v7_fs_routes.md +523 -0
- package/docs/vi/intlayer_with_tanstack.md +2 -12
- package/docs/vi/intlayer_with_vite+vue.md +1 -0
- package/docs/zh/intlayer_with_nuxt.md +300 -461
- package/docs/zh/intlayer_with_react_router_v7.md +33 -4
- package/docs/zh/intlayer_with_react_router_v7_fs_routes.md +516 -0
- package/docs/zh/intlayer_with_tanstack.md +2 -12
- package/docs/zh/intlayer_with_vite+vue.md +1 -0
- package/package.json +10 -11
- package/src/generated/docs.entry.ts +19 -0
|
@@ -18,6 +18,7 @@ slugs:
|
|
|
18
18
|
- vite-and-react
|
|
19
19
|
- react-router-v7
|
|
20
20
|
applicationTemplate: https://github.com/aymericzip/intlayer-react-router-v7-template
|
|
21
|
+
youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
|
|
21
22
|
history:
|
|
22
23
|
- version: 6.1.5
|
|
23
24
|
date: 2025-10-03
|
|
@@ -31,6 +32,10 @@ history:
|
|
|
31
32
|
|
|
32
33
|
このガイドでは、React Router v7プロジェクトにおいて、ロケール対応ルーティング、TypeScriptサポート、最新の開発手法を活用しながら、**Intlayer**を使ったシームレスな国際化の統合方法を説明します。
|
|
33
34
|
|
|
35
|
+
## Table of Contents
|
|
36
|
+
|
|
37
|
+
<TOC/>
|
|
38
|
+
|
|
34
39
|
## Intlayerとは?
|
|
35
40
|
|
|
36
41
|
**Intlayer**は、現代のウェブアプリケーションにおける多言語対応を簡素化するために設計された革新的なオープンソースの国際化(i18n)ライブラリです。
|
|
@@ -74,6 +79,29 @@ pnpm add vite-intlayer --save-dev
|
|
|
74
79
|
|
|
75
80
|
### ステップ 2: プロジェクトの設定
|
|
76
81
|
|
|
82
|
+
## ファイルシステムベースのルートを使用したReact Router v7アプリケーションでIntlayerを設定するためのステップバイステップガイド
|
|
83
|
+
|
|
84
|
+
<Tab defaultTab="video">
|
|
85
|
+
<TabItem label="Video" value="video">
|
|
86
|
+
|
|
87
|
+
<iframe title="How to translate your React Router v7 app using 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?autoplay=0&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
88
|
+
|
|
89
|
+
</TabItem>
|
|
90
|
+
<TabItem label="Code" value="code">
|
|
91
|
+
|
|
92
|
+
<iframe
|
|
93
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-react-router-v7-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
94
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
95
|
+
title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
|
|
96
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
97
|
+
loading="lazy"
|
|
98
|
+
/>
|
|
99
|
+
|
|
100
|
+
</TabItem>
|
|
101
|
+
</Tab>
|
|
102
|
+
|
|
103
|
+
See [Application Template](https://github.com/aymericzip/intlayer-react-router-v7-template) on GitHub.
|
|
104
|
+
|
|
77
105
|
アプリケーションの言語を設定するための設定ファイルを作成します:
|
|
78
106
|
|
|
79
107
|
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
@@ -259,7 +287,7 @@ export const LocalizedLink: FC<LinkProps> = (props) => {
|
|
|
259
287
|
ローカライズされたルートにナビゲートしたい場合は、`useLocalizedNavigate` フックを使用できます。
|
|
260
288
|
|
|
261
289
|
```tsx fileName="app/hooks/useLocalizedNavigate.ts"
|
|
262
|
-
import { useLocale } from "intlayer";
|
|
290
|
+
import { useLocale } from "react-intlayer";
|
|
263
291
|
import { type NavigateOptions, type To, useNavigate } from "react-router";
|
|
264
292
|
|
|
265
293
|
import { locacalizeTo } from "~/components/localized-link";
|
|
@@ -317,6 +345,7 @@ import {
|
|
|
317
345
|
getLocaleName,
|
|
318
346
|
getLocalizedUrl,
|
|
319
347
|
getPathWithoutLocale,
|
|
348
|
+
Locales,
|
|
320
349
|
} from "intlayer";
|
|
321
350
|
import { setLocaleInStorage, useIntlayer, useLocale } from "react-intlayer";
|
|
322
351
|
import { Link, useLocation } from "react-router";
|
|
@@ -410,13 +439,13 @@ export default function RootLayout() {
|
|
|
410
439
|
> `intlayerProxy` を本番環境で使用するには、`vite-intlayer` パッケージを `devDependencies` から `dependencies` に切り替える必要があることに注意してください。
|
|
411
440
|
|
|
412
441
|
```typescript {3,7} fileName="vite.config.ts"
|
|
442
|
+
import { reactRouter } from "@react-router/dev/vite";
|
|
413
443
|
import { defineConfig } from "vite";
|
|
414
|
-
import react from "@vitejs/plugin-react-swc";
|
|
415
444
|
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
445
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
416
446
|
|
|
417
|
-
// https://vitejs.dev/config/
|
|
418
447
|
export default defineConfig({
|
|
419
|
-
plugins: [
|
|
448
|
+
plugins: [reactRouter(), tsconfigPaths(), intlayer(), intlayerProxy()],
|
|
420
449
|
});
|
|
421
450
|
```
|
|
422
451
|
|
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-12-07
|
|
3
|
+
updatedAt: 2025-12-07
|
|
4
|
+
title: React Router v7(fs-routes)アプリを翻訳する方法 – i18nガイド 2025
|
|
5
|
+
description: Intlayerを使用してReact Router v7アプリケーションにファイルシステムベースのルーティングで国際化(i18n)を追加する方法を学びます。ロケール対応ルーティングでアプリを多言語化するための包括的なガイドに従ってください。
|
|
6
|
+
keywords:
|
|
7
|
+
- 国際化
|
|
8
|
+
- ドキュメント
|
|
9
|
+
- Intlayer
|
|
10
|
+
- React Router v7
|
|
11
|
+
- fs-routes
|
|
12
|
+
- ファイルシステムルート
|
|
13
|
+
- React
|
|
14
|
+
- i18n
|
|
15
|
+
- TypeScript
|
|
16
|
+
- ロケールルーティング
|
|
17
|
+
slugs:
|
|
18
|
+
- doc
|
|
19
|
+
- environment
|
|
20
|
+
- vite-and-react
|
|
21
|
+
- react-router-v7-fs-routes
|
|
22
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-react-router-v7-fs-routes-template
|
|
23
|
+
youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
|
|
24
|
+
history:
|
|
25
|
+
- version: 7.3.4
|
|
26
|
+
date: 2025-12-08
|
|
27
|
+
changes: Init history
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
# IntlayerでReact Router v7(fs-routes)を翻訳する | 国際化(i18n)
|
|
31
|
+
|
|
32
|
+
このガイドでは、React Router v7プロジェクトにおいて、**ファイルシステムベースのルーティング**(`@react-router/fs-routes`)を使用して、ロケール対応ルーティング、TypeScriptサポート、最新の開発手法を活用しながら、**Intlayer**を使ったシームレスな国際化の統合方法を説明します。
|
|
33
|
+
|
|
34
|
+
## Table of Contents
|
|
35
|
+
|
|
36
|
+
<TOC/>
|
|
37
|
+
|
|
38
|
+
## Intlayerとは?
|
|
39
|
+
|
|
40
|
+
**Intlayer**は、現代のウェブアプリケーションにおける多言語対応を簡素化するために設計された革新的なオープンソースの国際化(i18n)ライブラリです。
|
|
41
|
+
|
|
42
|
+
Intlayerを使うことで、以下が可能になります:
|
|
43
|
+
|
|
44
|
+
- **コンポーネントレベルで宣言的辞書を使い、翻訳を簡単に管理**できます。
|
|
45
|
+
- **メタデータ、ルート、コンテンツを動的にローカライズ**できます。
|
|
46
|
+
- **自動生成される型情報によりTypeScriptサポートを確保し、オートコンプリートやエラー検出を向上**させます。
|
|
47
|
+
- **動的なロケール検出や切り替えなどの高度な機能**を活用できます。
|
|
48
|
+
- **React Router v7のファイルシステムベースのルーティングシステムを使って、ロケール対応ルーティングを有効化**します。
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## ファイルシステムベースのルートを使用したReact Router v7アプリケーションでIntlayerを設定するためのステップバイステップガイド
|
|
53
|
+
|
|
54
|
+
<Tab defaultTab="video">
|
|
55
|
+
<TabItem label="Video" value="video">
|
|
56
|
+
|
|
57
|
+
<iframe title="How to translate your React Router v7 (File-System Routes) app using 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?autoplay=0&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
58
|
+
|
|
59
|
+
</TabItem>
|
|
60
|
+
<TabItem label="Code" value="code">
|
|
61
|
+
|
|
62
|
+
<iframe
|
|
63
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-react-router-v7-fs-routes-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
64
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
65
|
+
title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
|
|
66
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
67
|
+
loading="lazy"
|
|
68
|
+
/>
|
|
69
|
+
|
|
70
|
+
</TabItem>
|
|
71
|
+
</Tab>
|
|
72
|
+
|
|
73
|
+
See [Application Template](https://github.com/aymericzip/intlayer-react-router-v7-fs-routes-template) on GitHub.
|
|
74
|
+
|
|
75
|
+
### ステップ1: 依存パッケージのインストール
|
|
76
|
+
|
|
77
|
+
お好みのパッケージマネージャーを使って必要なパッケージをインストールします:
|
|
78
|
+
|
|
79
|
+
```bash packageManager="npm"
|
|
80
|
+
npm install intlayer react-intlayer
|
|
81
|
+
npm install vite-intlayer --save-dev
|
|
82
|
+
npm install @react-router/fs-routes --save-dev
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```bash packageManager="pnpm"
|
|
86
|
+
pnpm add intlayer react-intlayer
|
|
87
|
+
pnpm add vite-intlayer --save-dev
|
|
88
|
+
pnpm add @react-router/fs-routes --save-dev
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- **intlayer**
|
|
92
|
+
|
|
93
|
+
- **intlayer**
|
|
94
|
+
設定管理、翻訳、[コンテンツ宣言](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)のための国際化ツールを提供するコアパッケージ。
|
|
95
|
+
|
|
96
|
+
- **react-intlayer**
|
|
97
|
+
IntlayerをReactアプリケーションと統合するパッケージです。Reactの国際化のためのコンテキストプロバイダーとフックを提供します。
|
|
98
|
+
|
|
99
|
+
- **vite-intlayer**
|
|
100
|
+
Intlayerを[Viteバンドラー](https://vite.dev/guide/why.html#why-bundle-for-production)と統合するためのViteプラグイン、およびユーザーの優先ロケール検出、クッキー管理、URLリダイレクト処理のためのミドルウェアを含みます。
|
|
101
|
+
|
|
102
|
+
- **@react-router/fs-routes**
|
|
103
|
+
React Router v7のファイルシステムベースのルーティングを有効にするパッケージ。
|
|
104
|
+
|
|
105
|
+
### ステップ 2: プロジェクトの設定
|
|
106
|
+
|
|
107
|
+
アプリケーションの言語を設定するための設定ファイルを作成します:
|
|
108
|
+
|
|
109
|
+
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
110
|
+
import { type IntlayerConfig, Locales } from "intlayer";
|
|
111
|
+
|
|
112
|
+
const config: IntlayerConfig = {
|
|
113
|
+
internationalization: {
|
|
114
|
+
defaultLocale: Locales.ENGLISH, // デフォルトのロケールを英語に設定
|
|
115
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH], // 利用可能なロケールのリスト
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export default config;
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
123
|
+
import { Locales } from "intlayer";
|
|
124
|
+
|
|
125
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
126
|
+
const config = {
|
|
127
|
+
internationalization: {
|
|
128
|
+
defaultLocale: Locales.ENGLISH, // デフォルトのロケールを英語に設定
|
|
129
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH], // 利用可能なロケールのリスト
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export default config;
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
137
|
+
const { Locales } = require("intlayer");
|
|
138
|
+
|
|
139
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
140
|
+
const config = {
|
|
141
|
+
internationalization: {
|
|
142
|
+
defaultLocale: Locales.ENGLISH,
|
|
143
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
module.exports = config;
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
> この設定ファイルを通じて、ローカライズされたURL、ミドルウェアのリダイレクション、クッキー名、コンテンツ宣言の場所と拡張子、コンソールでのIntlayerログの無効化などを設定できます。利用可能なパラメータの完全なリストについては、[設定ドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/configuration.md)を参照してください。
|
|
151
|
+
|
|
152
|
+
### ステップ3: Vite設定にIntlayerを統合する
|
|
153
|
+
|
|
154
|
+
設定にintlayerプラグインを追加します:
|
|
155
|
+
|
|
156
|
+
```typescript fileName="vite.config.ts"
|
|
157
|
+
import { reactRouter } from "@react-router/dev/vite";
|
|
158
|
+
import { defineConfig } from "vite";
|
|
159
|
+
import { intlayer } from "vite-intlayer";
|
|
160
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
161
|
+
|
|
162
|
+
export default defineConfig({
|
|
163
|
+
plugins: [reactRouter(), tsconfigPaths(), intlayer()],
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
> `intlayer()` Viteプラグインは、IntlayerをViteと統合するために使用されます。これにより、コンテンツ宣言ファイルのビルドが保証され、開発モードで監視されます。また、Viteアプリケーション内でIntlayerの環境変数を定義します。さらに、パフォーマンスを最適化するためのエイリアスも提供します。
|
|
168
|
+
|
|
169
|
+
### ステップ4: React Router v7のファイルシステムルートを設定する
|
|
170
|
+
|
|
171
|
+
`flatRoutes`を使用してファイルシステムベースのルートを使用するようにルーティング設定を行います:
|
|
172
|
+
|
|
173
|
+
```typescript fileName="app/routes.ts"
|
|
174
|
+
import type { RouteConfig } from "@react-router/dev/routes";
|
|
175
|
+
import { flatRoutes } from "@react-router/fs-routes";
|
|
176
|
+
import { configuration } from "intlayer";
|
|
177
|
+
|
|
178
|
+
const routes: RouteConfig = flatRoutes({
|
|
179
|
+
// コンテンツ宣言ファイルをルートとして扱わないように無視する
|
|
180
|
+
ignoredRouteFiles: configuration.content.fileExtensions.map(
|
|
181
|
+
(fileExtension) => `**/*${fileExtension}`
|
|
182
|
+
),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
export default routes;
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
> `@react-router/fs-routes`の`flatRoutes`関数は、`routes/`ディレクトリ内のファイル構造がアプリケーションのルートを決定するファイルシステムベースのルーティングを有効にします。`ignoredRouteFiles`オプションは、Intlayerコンテンツ宣言ファイル(`.content.ts`など)がルートファイルとして扱われないようにします。
|
|
189
|
+
|
|
190
|
+
### ステップ5: ファイルシステム規則でルートファイルを作成する
|
|
191
|
+
|
|
192
|
+
ファイルシステムルーティングでは、ドット(`.`)がパスセグメントを表し、括弧`()`がオプションセグメントを示すフラットな命名規則を使用します。
|
|
193
|
+
|
|
194
|
+
`app/routes/`ディレクトリに次のファイルを作成します:
|
|
195
|
+
|
|
196
|
+
#### ファイル構造
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
app/routes/
|
|
200
|
+
├── ($locale)._layout.tsx # ロケールルートのレイアウトラッパー
|
|
201
|
+
├── ($locale)._index.tsx # ホームページ (/:locale?)
|
|
202
|
+
├── ($locale)._index.content.ts # ホームページのコンテンツ
|
|
203
|
+
├── ($locale).about.tsx # アバウトページ (/:locale?/about)
|
|
204
|
+
└── ($locale).about.content.ts # アバウトページのコンテンツ
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
命名規則:
|
|
208
|
+
|
|
209
|
+
- `($locale)` - ロケールパラメータのオプションの動的セグメント
|
|
210
|
+
- `_layout` - 子ルートをラップするレイアウトルート
|
|
211
|
+
- `_index` - インデックスルート(親パスでレンダリングされる)
|
|
212
|
+
- `.`(ドット) - パスセグメントを区切る(例:`($locale).about` → `/:locale?/about`)
|
|
213
|
+
|
|
214
|
+
#### レイアウトコンポーネント
|
|
215
|
+
|
|
216
|
+
```tsx fileName="app/routes/($locale)._layout.tsx"
|
|
217
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
218
|
+
import { Outlet } from "react-router";
|
|
219
|
+
|
|
220
|
+
import { useI18nHTMLAttributes } from "~/hooks/useI18nHTMLAttributes";
|
|
221
|
+
|
|
222
|
+
import type { Route } from "./+types/($locale)._layout";
|
|
223
|
+
|
|
224
|
+
export default function RootLayout({ params }: Route.ComponentProps) {
|
|
225
|
+
useI18nHTMLAttributes();
|
|
226
|
+
|
|
227
|
+
const { locale } = params;
|
|
228
|
+
|
|
229
|
+
return (
|
|
230
|
+
<IntlayerProvider locale={locale}>
|
|
231
|
+
<Outlet />
|
|
232
|
+
</IntlayerProvider>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
#### インデックスページ
|
|
238
|
+
|
|
239
|
+
```tsx fileName="app/routes/($locale)._index.tsx"
|
|
240
|
+
import { useIntlayer } from "react-intlayer";
|
|
241
|
+
import { LocalizedLink } from "~/components/localized-link";
|
|
242
|
+
|
|
243
|
+
import type { Route } from "./+types/($locale)._index";
|
|
244
|
+
|
|
245
|
+
export default function Page() {
|
|
246
|
+
const { title, description, aboutLink } = useIntlayer("page");
|
|
247
|
+
|
|
248
|
+
return (
|
|
249
|
+
<div>
|
|
250
|
+
<h1>{title}</h1>
|
|
251
|
+
<p>{description}</p>
|
|
252
|
+
<nav>
|
|
253
|
+
<LocalizedLink to="/about">{aboutLink}</LocalizedLink>
|
|
254
|
+
</nav>
|
|
255
|
+
</div>
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
#### アバウトページ
|
|
261
|
+
|
|
262
|
+
```tsx fileName="app/routes/($locale).about.tsx"
|
|
263
|
+
import { useIntlayer } from "react-intlayer";
|
|
264
|
+
import { LocalizedLink } from "~/components/localized-link";
|
|
265
|
+
|
|
266
|
+
import type { Route } from "./+types/($locale).about";
|
|
267
|
+
|
|
268
|
+
export default function AboutPage() {
|
|
269
|
+
const { title, content, homeLink } = useIntlayer("about");
|
|
270
|
+
|
|
271
|
+
return (
|
|
272
|
+
<div>
|
|
273
|
+
<h1>{title}</h1>
|
|
274
|
+
<p>{content}</p>
|
|
275
|
+
<nav>
|
|
276
|
+
<LocalizedLink to="/">{homeLink}</LocalizedLink>
|
|
277
|
+
</nav>
|
|
278
|
+
</div>
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### ステップ 6: コンテンツを宣言する
|
|
284
|
+
|
|
285
|
+
翻訳を格納するためのコンテンツ宣言を作成および管理します。コンテンツファイルをルートファイルの横に配置します:
|
|
286
|
+
|
|
287
|
+
```tsx fileName="app/routes/($locale)._index.content.ts"
|
|
288
|
+
import { t, type Dictionary } from "intlayer";
|
|
289
|
+
|
|
290
|
+
const pageContent = {
|
|
291
|
+
key: "page",
|
|
292
|
+
content: {
|
|
293
|
+
title: t({
|
|
294
|
+
en: "Welcome to React Router v7 + Intlayer",
|
|
295
|
+
es: "Bienvenido a React Router v7 + Intlayer",
|
|
296
|
+
fr: "Bienvenue sur React Router v7 + Intlayer",
|
|
297
|
+
}),
|
|
298
|
+
description: t({
|
|
299
|
+
en: "Build multilingual applications with ease using React Router v7 and Intlayer.",
|
|
300
|
+
es: "Cree aplicaciones multilingües fácilmente usando React Router v7 y Intlayer.",
|
|
301
|
+
fr: "Créez des applications multilingues facilement avec React Router v7 et Intlayer.",
|
|
302
|
+
}),
|
|
303
|
+
aboutLink: t({
|
|
304
|
+
en: "Learn About Us",
|
|
305
|
+
es: "Aprender Sobre Nosotros",
|
|
306
|
+
fr: "En savoir plus sur nous",
|
|
307
|
+
}),
|
|
308
|
+
},
|
|
309
|
+
} satisfies Dictionary;
|
|
310
|
+
|
|
311
|
+
export default pageContent;
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
```tsx fileName="app/routes/($locale).about.content.ts"
|
|
315
|
+
import { t, type Dictionary } from "intlayer";
|
|
316
|
+
|
|
317
|
+
const aboutContent = {
|
|
318
|
+
key: "about",
|
|
319
|
+
content: {
|
|
320
|
+
title: t({
|
|
321
|
+
en: "About Us",
|
|
322
|
+
es: "Sobre Nosotros",
|
|
323
|
+
fr: "À propos de nous",
|
|
324
|
+
}),
|
|
325
|
+
content: t({
|
|
326
|
+
en: "This is the about page content.",
|
|
327
|
+
es: "Este es el contenido de la página de información.",
|
|
328
|
+
fr: "Ceci est le contenu de la page à propos.",
|
|
329
|
+
}),
|
|
330
|
+
homeLink: t({
|
|
331
|
+
en: "Home",
|
|
332
|
+
es: "Inicio",
|
|
333
|
+
fr: "Accueil",
|
|
334
|
+
}),
|
|
335
|
+
},
|
|
336
|
+
} satisfies Dictionary;
|
|
337
|
+
|
|
338
|
+
export default aboutContent;
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
> コンテンツ宣言は、`contentDir` ディレクトリ(デフォルトは `./app`)に含まれている限り、アプリケーションのどこにでも定義できます。また、コンテンツ宣言ファイルの拡張子(デフォルトは `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`)に一致する必要があります。
|
|
342
|
+
|
|
343
|
+
> 詳細については、[コンテンツ宣言ドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/get_started.md)を参照してください。
|
|
344
|
+
|
|
345
|
+
### ステップ7: ロケール対応コンポーネントの作成
|
|
346
|
+
|
|
347
|
+
ロケール対応のナビゲーション用に `LocalizedLink` コンポーネントを作成します:
|
|
348
|
+
|
|
349
|
+
```tsx fileName="app/components/localized-link.tsx"
|
|
350
|
+
import type { FC } from "react";
|
|
351
|
+
|
|
352
|
+
import { getLocalizedUrl, type LocalesValues } from "intlayer";
|
|
353
|
+
import { useLocale } from "react-intlayer";
|
|
354
|
+
import { Link, type LinkProps, type To } from "react-router";
|
|
355
|
+
|
|
356
|
+
// 外部リンクかどうかを判定する関数
|
|
357
|
+
const isExternalLink = (to: string) => /^(https?:)?\/\//.test(to);
|
|
358
|
+
|
|
359
|
+
// 指定されたURLをロケールに応じてローカライズする関数
|
|
360
|
+
export const locacalizeTo = (to: To, locale: LocalesValues): To => {
|
|
361
|
+
if (typeof to === "string") {
|
|
362
|
+
if (isExternalLink(to)) {
|
|
363
|
+
return to;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return getLocalizedUrl(to, locale);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (isExternalLink(to.pathname ?? "")) {
|
|
370
|
+
return to;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return {
|
|
374
|
+
...to,
|
|
375
|
+
pathname: getLocalizedUrl(to.pathname ?? "", locale),
|
|
376
|
+
};
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// ロケール対応のリンクコンポーネント
|
|
380
|
+
export const LocalizedLink: FC<LinkProps> = (props) => {
|
|
381
|
+
const { locale } = useLocale();
|
|
382
|
+
|
|
383
|
+
return <Link {...props} to={locacalizeTo(props.to, locale)} />;
|
|
384
|
+
};
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
ローカライズされたルートにナビゲートしたい場合は、`useLocalizedNavigate` フックを使用できます。
|
|
388
|
+
|
|
389
|
+
```tsx fileName="app/hooks/useLocalizedNavigate.ts"
|
|
390
|
+
import { useLocale } from "react-intlayer";
|
|
391
|
+
import { type NavigateOptions, type To, useNavigate } from "react-router";
|
|
392
|
+
|
|
393
|
+
import { locacalizeTo } from "~/components/localized-link";
|
|
394
|
+
|
|
395
|
+
export const useLocalizedNavigate = () => {
|
|
396
|
+
const navigate = useNavigate();
|
|
397
|
+
const { locale } = useLocale();
|
|
398
|
+
|
|
399
|
+
const localizedNavigate = (to: To, options?: NavigateOptions) => {
|
|
400
|
+
const localedTo = locacalizeTo(to, locale);
|
|
401
|
+
|
|
402
|
+
navigate(localedTo, options);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
return localizedNavigate;
|
|
406
|
+
};
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### ステップ8:ロケールスイッチャーコンポーネントを作成する
|
|
410
|
+
|
|
411
|
+
ユーザーが言語を変更できるコンポーネントを作成します:
|
|
412
|
+
|
|
413
|
+
```tsx fileName="app/components/locale-switcher.tsx"
|
|
414
|
+
import type { FC } from "react";
|
|
415
|
+
|
|
416
|
+
import {
|
|
417
|
+
getHTMLTextDir,
|
|
418
|
+
getLocaleName,
|
|
419
|
+
getLocalizedUrl,
|
|
420
|
+
getPathWithoutLocale,
|
|
421
|
+
Locales,
|
|
422
|
+
} from "intlayer";
|
|
423
|
+
import { useIntlayer, useLocale } from "react-intlayer";
|
|
424
|
+
import { Link, useLocation } from "react-router";
|
|
425
|
+
|
|
426
|
+
export const LocaleSwitcher: FC = () => {
|
|
427
|
+
const { localeSwitcherLabel } = useIntlayer("locale-switcher");
|
|
428
|
+
const { pathname } = useLocation();
|
|
429
|
+
|
|
430
|
+
const { availableLocales, locale } = useLocale();
|
|
431
|
+
|
|
432
|
+
const pathWithoutLocale = getPathWithoutLocale(pathname);
|
|
433
|
+
|
|
434
|
+
return (
|
|
435
|
+
<ol>
|
|
436
|
+
{availableLocales.map((localeItem) => (
|
|
437
|
+
<li key={localeItem}>
|
|
438
|
+
<Link
|
|
439
|
+
aria-current={localeItem === locale ? "page" : undefined}
|
|
440
|
+
aria-label={`${localeSwitcherLabel.value} ${getLocaleName(localeItem)}`}
|
|
441
|
+
reloadDocument // 新しいロケールを適用するためにページを再読み込み
|
|
442
|
+
to={getLocalizedUrl(pathWithoutLocale, localeItem)}
|
|
443
|
+
>
|
|
444
|
+
<span>
|
|
445
|
+
{/* ロケール - 例: FR */}
|
|
446
|
+
{localeItem}
|
|
447
|
+
</span>
|
|
448
|
+
<span>
|
|
449
|
+
{/* 自身のロケールでの言語名 - 例: Français */}
|
|
450
|
+
{getLocaleName(localeItem, locale)}
|
|
451
|
+
</span>
|
|
452
|
+
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
453
|
+
{/* 現在のロケールでの言語名 - 例: 現在のロケールがLocales.SPANISHの場合のFrancés */}
|
|
454
|
+
{getLocaleName(localeItem)}
|
|
455
|
+
</span>
|
|
456
|
+
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
457
|
+
{/* 英語での言語名 - 例: French */}
|
|
458
|
+
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
459
|
+
</span>
|
|
460
|
+
</Link>
|
|
461
|
+
</li>
|
|
462
|
+
))}
|
|
463
|
+
</ol>
|
|
464
|
+
);
|
|
465
|
+
};
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
> `useLocale` フックの詳細については、[ドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/packages/react-intlayer/useLocale.md)を参照してください。
|
|
469
|
+
|
|
470
|
+
### ステップ10: HTML属性の管理を追加(オプション)
|
|
471
|
+
|
|
472
|
+
HTMLのlang属性とdir属性を管理するフックを作成します:
|
|
473
|
+
|
|
474
|
+
```tsx fileName="app/hooks/useI18nHTMLAttributes.tsx"
|
|
475
|
+
import { getHTMLTextDir } from "intlayer";
|
|
476
|
+
import { useEffect } from "react";
|
|
477
|
+
import { useLocale } from "react-intlayer";
|
|
478
|
+
|
|
479
|
+
export const useI18nHTMLAttributes = () => {
|
|
480
|
+
const { locale } = useLocale();
|
|
481
|
+
|
|
482
|
+
useEffect(() => {
|
|
483
|
+
document.documentElement.lang = locale;
|
|
484
|
+
document.documentElement.dir = getHTMLTextDir(locale);
|
|
485
|
+
}, [locale]);
|
|
486
|
+
};
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
このフックは、ステップ5で示したレイアウトコンポーネント(`($locale)._layout.tsx`)で既に使用されています。
|
|
490
|
+
|
|
491
|
+
### ステップ10: ミドルウェアを追加する(オプション)
|
|
492
|
+
|
|
493
|
+
`intlayerProxy` を使用して、アプリケーションにサーバーサイドルーティングを追加することもできます。このプラグインは、URL に基づいて現在のロケールを自動的に検出し、適切なロケールクッキーを設定します。ロケールが指定されていない場合、プラグインはユーザーのブラウザの言語設定に基づいて最も適切なロケールを判断します。ロケールが検出されない場合は、デフォルトのロケールにリダイレクトします。
|
|
494
|
+
|
|
495
|
+
> `intlayerProxy` を本番環境で使用するには、`vite-intlayer` パッケージを `devDependencies` から `dependencies` に切り替える必要があることに注意してください。
|
|
496
|
+
|
|
497
|
+
```typescript {3,7} fileName="vite.config.ts"
|
|
498
|
+
import { reactRouter } from "@react-router/dev/vite";
|
|
499
|
+
import { defineConfig } from "vite";
|
|
500
|
+
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
501
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
502
|
+
|
|
503
|
+
export default defineConfig({
|
|
504
|
+
plugins: [reactRouter(), tsconfigPaths(), intlayer(), intlayerProxy()],
|
|
505
|
+
});
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
---
|
|
509
|
+
|
|
510
|
+
## TypeScriptの設定
|
|
511
|
+
|
|
512
|
+
Intlayerはモジュール拡張を使用して、TypeScriptの利点を活かし、コードベースをより強固にします。
|
|
513
|
+
|
|
514
|
+
TypeScriptの設定に自動生成された型が含まれていることを確認してください。
|
|
515
|
+
|
|
516
|
+
```json5 fileName="tsconfig.json"
|
|
517
|
+
{
|
|
518
|
+
// ... 既存の設定
|
|
519
|
+
include: [
|
|
520
|
+
// ... 既存のinclude
|
|
521
|
+
".intlayer/**/*.ts", // 自動生成された型を含める
|
|
522
|
+
],
|
|
523
|
+
}
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
---
|
|
527
|
+
|
|
528
|
+
## Gitの設定
|
|
529
|
+
|
|
530
|
+
Intlayerによって生成されたファイルは無視することを推奨します。これにより、Gitリポジトリへのコミットを避けることができます。
|
|
531
|
+
|
|
532
|
+
これを行うには、`.gitignore`ファイルに以下の指示を追加してください。
|
|
533
|
+
|
|
534
|
+
```plaintext fileName=".gitignore"
|
|
535
|
+
# Intlayerによって生成されたファイルを無視する
|
|
536
|
+
.intlayer
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
|
|
541
|
+
## VS Code 拡張機能
|
|
542
|
+
|
|
543
|
+
Intlayerでの開発体験を向上させるために、公式の **Intlayer VS Code 拡張機能** をインストールできます。
|
|
544
|
+
|
|
545
|
+
[VS Code Marketplaceからインストール](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
546
|
+
|
|
547
|
+
この拡張機能は以下を提供します:
|
|
548
|
+
|
|
549
|
+
- 翻訳キーの **自動補完**。
|
|
550
|
+
- 翻訳が不足している場合の **リアルタイムエラー検出**。
|
|
551
|
+
- 翻訳内容の **インラインプレビュー**。
|
|
552
|
+
- 翻訳を簡単に作成・更新できる **クイックアクション**。
|
|
553
|
+
|
|
554
|
+
拡張機能の使い方の詳細は、[Intlayer VS Code 拡張機能のドキュメント](https://intlayer.org/doc/vs-code-extension)を参照してください。
|
|
555
|
+
|
|
556
|
+
---
|
|
557
|
+
|
|
558
|
+
## さらに進む
|
|
559
|
+
|
|
560
|
+
さらに進めるために、[ビジュアルエディター](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)を使用してコンテンツを外部化することができます。
|
|
561
|
+
|
|
562
|
+
---
|
|
563
|
+
|
|
564
|
+
## ドキュメント参照
|
|
565
|
+
|
|
566
|
+
- [Intlayer ドキュメント](https://intlayer.org)
|
|
567
|
+
- [React Router v7 ドキュメント](https://reactrouter.com/)
|
|
568
|
+
- [React Router fs-routes ドキュメント](https://reactrouter.com/how-to/file-route-conventions)
|
|
569
|
+
- [useIntlayer フック](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/packages/react-intlayer/useIntlayer.md)
|
|
570
|
+
- [useLocale フック](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/packages/react-intlayer/useLocale.md)
|
|
571
|
+
- [コンテンツ宣言](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/dictionary/get_started.md)
|
|
572
|
+
- [設定](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/configuration.md)
|
|
573
|
+
|
|
574
|
+
この包括的なガイドは、ファイルシステムベースのルーティングを使用してIntlayerをReact Router v7と統合し、ロケール対応のルーティングとTypeScriptサポートを備えた完全に国際化されたアプリケーションを構築するために必要なすべてを提供します。
|
|
@@ -17,6 +17,7 @@ slugs:
|
|
|
17
17
|
- environment
|
|
18
18
|
- tanstack-start
|
|
19
19
|
applicationTemplate: https://github.com/aymericzip/intlayer-tanstack-start-template
|
|
20
|
+
youtubeVideo: https://www.youtube.com/watch?v=_XTdKVWaeqg
|
|
20
21
|
history:
|
|
21
22
|
- version: 7.3.9
|
|
22
23
|
date: 2025-12-05
|
|
@@ -580,19 +581,8 @@ export const getLocaleServer = createServerFn().handler(async () => {
|
|
|
580
581
|
return getCookie(name, cookieString);
|
|
581
582
|
},
|
|
582
583
|
// Get the header from the request (default: 'x-intlayer-locale')
|
|
583
|
-
getHeader: (name) => getRequestHeader(name),
|
|
584
584
|
// Fallback using Accept-Language negotiation
|
|
585
|
-
|
|
586
|
-
const headers = getRequestHeaders();
|
|
587
|
-
const result: Record<string, string> = {};
|
|
588
|
-
|
|
589
|
-
// Convert the TypedHeaders into a plain Record<string, string>
|
|
590
|
-
for (const [key, value] of headers.entries()) {
|
|
591
|
-
result[key] = value;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
return result;
|
|
595
|
-
},
|
|
585
|
+
getHeader: (name) => getRequestHeader(name),
|
|
596
586
|
});
|
|
597
587
|
|
|
598
588
|
// Retrieve some content using getIntlayer()
|