@intlayer/docs 7.0.3 → 7.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blog/ar/intlayer_with_i18next.md +68 -106
- package/blog/ar/intlayer_with_next-i18next.md +84 -288
- package/blog/ar/intlayer_with_next-intl.md +58 -337
- package/blog/ar/intlayer_with_react-i18next.md +68 -290
- package/blog/ar/intlayer_with_react-intl.md +63 -266
- package/blog/de/intlayer_with_i18next.md +77 -97
- package/blog/de/intlayer_with_next-i18next.md +69 -296
- package/blog/de/intlayer_with_next-intl.md +59 -340
- package/blog/de/intlayer_with_react-i18next.md +68 -290
- package/blog/de/intlayer_with_react-intl.md +62 -264
- package/blog/en/intlayer_with_i18next.md +67 -103
- package/blog/en/intlayer_with_next-i18next.md +69 -294
- package/blog/en/intlayer_with_next-intl.md +48 -300
- package/blog/en/intlayer_with_react-i18next.md +61 -289
- package/blog/en/intlayer_with_react-intl.md +61 -284
- package/blog/en/next-i18next_vs_next-intl_vs_intlayer.md +1 -1
- package/blog/en-GB/intlayer_with_i18next.md +67 -103
- package/blog/en-GB/intlayer_with_next-i18next.md +71 -292
- package/blog/en-GB/intlayer_with_next-intl.md +58 -337
- package/blog/en-GB/intlayer_with_react-i18next.md +67 -289
- package/blog/en-GB/intlayer_with_react-intl.md +61 -264
- package/blog/es/intlayer_with_i18next.md +67 -103
- package/blog/es/intlayer_with_next-i18next.md +71 -296
- package/blog/es/intlayer_with_next-intl.md +57 -338
- package/blog/es/intlayer_with_react-i18next.md +68 -290
- package/blog/es/intlayer_with_react-intl.md +62 -265
- package/blog/fr/intlayer_with_i18next.md +66 -104
- package/blog/fr/intlayer_with_next-i18next.md +82 -285
- package/blog/fr/intlayer_with_next-intl.md +57 -338
- package/blog/fr/intlayer_with_react-i18next.md +67 -289
- package/blog/fr/intlayer_with_react-intl.md +61 -264
- package/blog/hi/intlayer_with_i18next.md +68 -104
- package/blog/hi/intlayer_with_next-i18next.md +74 -299
- package/blog/hi/intlayer_with_next-intl.md +57 -239
- package/blog/hi/intlayer_with_react-i18next.md +69 -291
- package/blog/hi/intlayer_with_react-intl.md +65 -268
- package/blog/id/intlayer_with_i18next.md +126 -0
- package/blog/id/intlayer_with_next-i18next.md +142 -0
- package/blog/id/intlayer_with_next-intl.md +113 -0
- package/blog/id/intlayer_with_react-i18next.md +124 -0
- package/blog/id/intlayer_with_react-intl.md +122 -0
- package/blog/it/intlayer_with_i18next.md +67 -103
- package/blog/it/intlayer_with_next-i18next.md +71 -296
- package/blog/it/intlayer_with_next-intl.md +57 -338
- package/blog/it/intlayer_with_react-i18next.md +68 -290
- package/blog/it/intlayer_with_react-intl.md +62 -265
- package/blog/ja/intlayer_with_i18next.md +68 -103
- package/blog/ja/intlayer_with_next-i18next.md +85 -283
- package/blog/ja/intlayer_with_next-intl.md +58 -336
- package/blog/ja/intlayer_with_react-i18next.md +68 -290
- package/blog/ja/intlayer_with_react-intl.md +62 -264
- package/blog/ko/intlayer_with_i18next.md +80 -96
- package/blog/ko/intlayer_with_next-i18next.md +85 -287
- package/blog/ko/intlayer_with_next-intl.md +68 -327
- package/blog/ko/intlayer_with_react-i18next.md +68 -290
- package/blog/ko/intlayer_with_react-intl.md +64 -266
- package/blog/pl/intlayer_with_i18next.md +126 -0
- package/blog/pl/intlayer_with_next-i18next.md +142 -0
- package/blog/pl/intlayer_with_next-intl.md +111 -0
- package/blog/pl/intlayer_with_react-i18next.md +124 -0
- package/blog/pl/intlayer_with_react-intl.md +122 -0
- package/blog/pt/intlayer_with_i18next.md +67 -103
- package/blog/pt/intlayer_with_next-i18next.md +72 -293
- package/blog/pt/intlayer_with_next-intl.md +57 -256
- package/blog/pt/intlayer_with_react-i18next.md +104 -78
- package/blog/pt/intlayer_with_react-intl.md +62 -266
- package/blog/ru/intlayer_with_i18next.md +66 -104
- package/blog/ru/intlayer_with_next-i18next.md +71 -296
- package/blog/ru/intlayer_with_next-intl.md +58 -337
- package/blog/ru/intlayer_with_react-i18next.md +68 -290
- package/blog/ru/intlayer_with_react-intl.md +62 -265
- package/blog/tr/intlayer_with_i18next.md +71 -107
- package/blog/tr/intlayer_with_next-i18next.md +72 -297
- package/blog/tr/intlayer_with_next-intl.md +58 -339
- package/blog/tr/intlayer_with_react-i18next.md +69 -291
- package/blog/tr/intlayer_with_react-intl.md +63 -285
- package/blog/vi/intlayer_with_i18next.md +126 -0
- package/blog/vi/intlayer_with_next-i18next.md +142 -0
- package/blog/vi/intlayer_with_next-intl.md +111 -0
- package/blog/vi/intlayer_with_react-i18next.md +124 -0
- package/blog/vi/intlayer_with_react-intl.md +122 -0
- package/blog/zh/intlayer_with_i18next.md +67 -102
- package/blog/zh/intlayer_with_next-i18next.md +72 -296
- package/blog/zh/intlayer_with_next-intl.md +58 -336
- package/blog/zh/intlayer_with_react-i18next.md +68 -290
- package/blog/zh/intlayer_with_react-intl.md +63 -106
- package/dist/cjs/generated/blog.entry.cjs +13 -1
- package/dist/cjs/generated/blog.entry.cjs.map +1 -1
- package/dist/cjs/generated/docs.entry.cjs +13 -1
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/cjs/generated/frequentQuestions.entry.cjs +13 -1
- package/dist/cjs/generated/frequentQuestions.entry.cjs.map +1 -1
- package/dist/cjs/generated/legal.entry.cjs +13 -1
- package/dist/cjs/generated/legal.entry.cjs.map +1 -1
- package/dist/esm/generated/blog.entry.mjs +13 -2
- package/dist/esm/generated/blog.entry.mjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +13 -2
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/esm/generated/frequentQuestions.entry.mjs +13 -2
- package/dist/esm/generated/frequentQuestions.entry.mjs.map +1 -1
- package/dist/esm/generated/legal.entry.mjs +13 -2
- package/dist/esm/generated/legal.entry.mjs.map +1 -1
- package/dist/types/generated/blog.entry.d.ts.map +1 -1
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/dist/types/generated/frequentQuestions.entry.d.ts.map +1 -1
- package/dist/types/generated/legal.entry.d.ts.map +1 -1
- package/docs/ar/plugins/sync-json.md +244 -0
- package/docs/de/plugins/sync-json.md +244 -0
- package/docs/de/releases/v7.md +1 -18
- package/docs/en/CI_CD.md +1 -1
- package/docs/en/configuration.md +1 -1
- package/docs/en/formatters.md +1 -1
- package/docs/en/how_works_intlayer.md +1 -1
- package/docs/en/intlayer_CMS.md +1 -1
- package/docs/en/intlayer_cli.md +26 -1
- package/docs/en/intlayer_with_nextjs_14.md +3 -1
- package/docs/en/intlayer_with_nextjs_15.md +3 -1
- package/docs/en/intlayer_with_nextjs_16.md +3 -1
- package/docs/en/intlayer_with_nextjs_page_router.md +1 -1
- package/docs/en/intlayer_with_nuxt.md +1 -1
- package/docs/en/intlayer_with_react_native+expo.md +1 -1
- package/docs/en/intlayer_with_react_router_v7.md +1 -1
- package/docs/en/intlayer_with_tanstack.md +1 -1
- package/docs/en/intlayer_with_vite+preact.md +1 -1
- package/docs/en/intlayer_with_vite+react.md +1 -1
- package/docs/en/intlayer_with_vite+solid.md +1 -1
- package/docs/en/intlayer_with_vite+svelte.md +1 -1
- package/docs/en/intlayer_with_vite+vue.md +1 -1
- package/docs/en/plugins/sync-json.md +1 -1
- package/docs/en/roadmap.md +1 -1
- package/docs/en-GB/plugins/sync-json.md +244 -0
- package/docs/es/plugins/sync-json.md +244 -0
- package/docs/es/releases/v7.md +1 -18
- package/docs/fr/intlayer_with_nextjs_16.md +2 -51
- package/docs/fr/plugins/sync-json.md +244 -0
- package/docs/fr/releases/v7.md +1 -18
- package/docs/hi/intlayer_with_nextjs_16.md +3 -2
- package/docs/hi/plugins/sync-json.md +244 -0
- package/docs/id/plugins/sync-json.md +244 -0
- package/docs/id/releases/v7.md +1 -18
- package/docs/it/plugins/sync-json.md +244 -0
- package/docs/it/releases/v7.md +1 -18
- package/docs/ja/intlayer_with_nextjs_16.md +44 -205
- package/docs/ja/plugins/sync-json.md +244 -0
- package/docs/ja/releases/v7.md +1 -18
- package/docs/ko/plugins/sync-json.md +244 -0
- package/docs/ko/releases/v7.md +1 -18
- package/docs/pl/plugins/sync-json.md +244 -0
- package/docs/pt/intlayer_with_nextjs_16.md +1 -52
- package/docs/pt/plugins/sync-json.md +244 -0
- package/docs/ru/plugins/sync-json.md +244 -0
- package/docs/tr/plugins/sync-json.md +245 -0
- package/docs/vi/plugins/sync-json.md +244 -0
- package/docs/zh/plugins/sync-json.md +244 -0
- package/package.json +14 -14
- package/src/generated/blog.entry.ts +26 -3
- package/src/generated/docs.entry.ts +26 -3
- package/src/generated/frequentQuestions.entry.ts +26 -3
- package/src/generated/legal.entry.ts +26 -3
|
@@ -1,346 +1,124 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-01-02
|
|
3
|
-
updatedAt: 2025-
|
|
4
|
-
title: Intlayer
|
|
5
|
-
description: React
|
|
3
|
+
updatedAt: 2025-10-29
|
|
4
|
+
title: Intlayerを使ったreact-i18nextのJSON翻訳の自動化方法
|
|
5
|
+
description: Reactアプリケーションの国際化を強化するために、Intlayerとreact-i18nextを使ってJSON翻訳を自動化する方法。
|
|
6
6
|
keywords:
|
|
7
7
|
- react-i18next
|
|
8
8
|
- i18next
|
|
9
9
|
- Intlayer
|
|
10
10
|
- 国際化
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- JavaScript
|
|
11
|
+
- i18n
|
|
12
|
+
- ブログ
|
|
14
13
|
- React
|
|
14
|
+
- JavaScript
|
|
15
|
+
- TypeScript
|
|
16
|
+
- コンテンツ管理
|
|
15
17
|
slugs:
|
|
16
18
|
- blog
|
|
17
19
|
- intlayer-with-react-i18next
|
|
20
|
+
history:
|
|
21
|
+
- version: 7.0.0
|
|
22
|
+
date: 2025-10-29
|
|
23
|
+
changes: syncJSONプラグインへの変更
|
|
18
24
|
---
|
|
19
25
|
|
|
20
|
-
#
|
|
21
|
-
|
|
22
|
-
## 概要
|
|
23
|
-
|
|
24
|
-
- **Intlayer** は、**コンポーネントレベル**のコンテンツ宣言ファイルを介して翻訳を管理するのに役立ちます。
|
|
25
|
-
- **react-i18next** は、コンポーネント内でローカライズされた文字列を取得するための `useTranslation` のようなフックを提供する、**i18next** のための人気のある React 統合です。
|
|
26
|
-
|
|
27
|
-
組み合わせることで、Intlayer は **i18next 互換の JSON** 形式の辞書を **エクスポート** できるため、react-i18next はそれらをランタイムで **利用** できます。
|
|
28
|
-
|
|
29
|
-
## なぜ Intlayerを react-i18next と共に使用するのか?
|
|
30
|
-
|
|
31
|
-
**Intlayer** のコンテンツ宣言ファイルは、開発者体験を向上させるための以下の特長があります。
|
|
32
|
-
|
|
33
|
-
1. **ファイル配置の柔軟性**
|
|
34
|
-
各コンテンツ宣言ファイルを必要なコンポーネントのすぐ隣に配置します。この構造により、翻訳を共に維持し、コンポーネントが移動したり削除された場合に孤立した翻訳を防ぐことができます。
|
|
35
|
-
|
|
36
|
-
```bash codeFormat="typescript"
|
|
37
|
-
.
|
|
38
|
-
└── src
|
|
39
|
-
└── components
|
|
40
|
-
└── MyComponent
|
|
41
|
-
├── index.content.ts # コンテンツ宣言ファイル
|
|
42
|
-
└── index.tsx
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
```bash codeFormat="esm"
|
|
46
|
-
.
|
|
47
|
-
└── src
|
|
48
|
-
└── components
|
|
49
|
-
└── MyComponent
|
|
50
|
-
├── index.content.mjs # コンテンツ宣言ファイル
|
|
51
|
-
└── index.mjx
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
```bash codeFormat="cjs"
|
|
55
|
-
.
|
|
56
|
-
└── src
|
|
57
|
-
└── components
|
|
58
|
-
└── MyComponent
|
|
59
|
-
├── index.content.cjs # コンテンツ宣言ファイル
|
|
60
|
-
└── index.cjx
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
```bash codeFormat="json"
|
|
64
|
-
.
|
|
65
|
-
└── src
|
|
66
|
-
└── components
|
|
67
|
-
└── MyComponent
|
|
68
|
-
├── index.content.json # コンテンツ宣言ファイル
|
|
69
|
-
└── index.jsx
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
2. **集中化された翻訳**
|
|
73
|
-
単一のコンテンツ宣言ファイルが、あるコンポーネントに必要なすべての翻訳を集約し、欠落した翻訳を見つけやすくします。
|
|
74
|
-
TypeScript を使用すると、翻訳が欠落している場合はコンパイル時エラーが発生します。
|
|
75
|
-
|
|
76
|
-
## インストール
|
|
77
|
-
|
|
78
|
-
Create React App プロジェクトで、これらの依存関係をインストールします。
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
# npmを使用
|
|
82
|
-
npm install intlayer react-i18next i18next i18next-resources-to-backend
|
|
83
|
-
```
|
|
26
|
+
# Intlayerを使ったreact-i18nextのJSON翻訳の自動化方法
|
|
84
27
|
|
|
85
|
-
|
|
86
|
-
# yarnを使用
|
|
87
|
-
yarn add intlayer react-i18next i18next i18next-resources-to-backend
|
|
88
|
-
```
|
|
28
|
+
## Intlayerとは何ですか?
|
|
89
29
|
|
|
90
|
-
|
|
91
|
-
# pnpmを使用
|
|
92
|
-
pnpm add intlayer react-i18next i18next i18next-resources-to-backend
|
|
93
|
-
```
|
|
30
|
+
**Intlayer**は、従来のi18nソリューションの欠点を解決するために設計された革新的なオープンソースの国際化ライブラリです。Reactアプリケーションにおけるコンテンツ管理に対して、モダンなアプローチを提供します。
|
|
94
31
|
|
|
95
|
-
|
|
32
|
+
具体的な比較については、当社のブログ記事[react-i18next vs. react-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/ja/react-i18next_vs_react-intl_vs_intlayer.md)をご覧ください。
|
|
96
33
|
|
|
97
|
-
-
|
|
98
|
-
- **react-intlayer** – 辞書のビルドを自動化するためのスクリプトを提供する、Intlayer の React 特有の統合。
|
|
99
|
-
- **react-i18next** – i18next のための React 特有の統合ライブラリで、`useTranslation` フックを含む。
|
|
100
|
-
- **i18next** – 翻訳処理の基盤となるフレームワーク。
|
|
101
|
-
- **i18next-resources-to-backend** – JSON リソースを動的にインポートする i18next バックエンド。
|
|
34
|
+
## なぜIntlayerをreact-i18nextと組み合わせるのか?
|
|
102
35
|
|
|
103
|
-
|
|
36
|
+
Intlayerは優れた単独のi18nソリューションを提供します([React統合ガイド](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/intlayer_with_vite+react.md)を参照)が、以下のような理由でreact-i18nextと組み合わせたい場合があります:
|
|
104
37
|
|
|
105
|
-
|
|
38
|
+
1. **既存のコードベース**: 既にreact-i18nextの実装があり、Intlayerの向上した開発者体験へ段階的に移行したい場合。
|
|
39
|
+
2. **レガシー要件**: プロジェクトが既存のreact-i18nextプラグインやワークフローとの互換性を必要とする場合。
|
|
40
|
+
3. **チームの慣れ親しみ**: チームがreact-i18nextに慣れているが、より良いコンテンツ管理を望んでいる場合。
|
|
106
41
|
|
|
107
|
-
|
|
108
|
-
import { Locales, type IntlayerConfig } from "intlayer";
|
|
42
|
+
**そのために、Intlayerはreact-i18nextのアダプターとして実装でき、CLIやCI/CDパイプラインでのJSON翻訳の自動化、翻訳のテストなどを支援します。**
|
|
109
43
|
|
|
110
|
-
|
|
111
|
-
internationalization: {
|
|
112
|
-
// 必要なロケールを追加します
|
|
113
|
-
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
114
|
-
defaultLocale: Locales.ENGLISH,
|
|
115
|
-
},
|
|
116
|
-
content: {
|
|
117
|
-
// Intlayer に i18next 互換の JSON を作成するように指示します
|
|
118
|
-
dictionaryOutput: ["i18next"],
|
|
44
|
+
このガイドでは、react-i18nextとの互換性を維持しながら、Intlayerの優れたコンテンツ宣言システムを活用する方法を示します。
|
|
119
45
|
|
|
120
|
-
|
|
121
|
-
// このフォルダは存在しない場合に作成されます。
|
|
122
|
-
i18nextResourcesDir: "./i18next/resources",
|
|
123
|
-
},
|
|
124
|
-
};
|
|
46
|
+
## 目次
|
|
125
47
|
|
|
126
|
-
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
> **注意**: TypeScript を使用していない場合は、この構成ファイルを `.cjs`、`.mjs`、または `.js` として作成できます(詳細は[Intlayer ドキュメント](https://intlayer.org/ja/doc/concept/configuration)を参照してください)。
|
|
130
|
-
|
|
131
|
-
## i18nextリソースのビルド
|
|
132
|
-
|
|
133
|
-
コンテンツ宣言が配置されたら(次のセクション)、**Intlayer ビルドコマンド**を実行します。
|
|
134
|
-
|
|
135
|
-
```bash
|
|
136
|
-
# npmを使用
|
|
137
|
-
npx run intlayer build
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
```bash
|
|
141
|
-
# yarnを使用
|
|
142
|
-
yarn intlayer build
|
|
143
|
-
```
|
|
48
|
+
<TOC/>
|
|
144
49
|
|
|
145
|
-
|
|
146
|
-
# pnpmを使用
|
|
147
|
-
pnpm intlayer build
|
|
148
|
-
```
|
|
50
|
+
## react-i18nextとIntlayerをセットアップするステップバイステップガイド
|
|
149
51
|
|
|
150
|
-
|
|
52
|
+
### ステップ1: 依存関係のインストール
|
|
151
53
|
|
|
152
|
-
|
|
54
|
+
必要なパッケージをインストールします:
|
|
153
55
|
|
|
154
|
-
```bash
|
|
155
|
-
|
|
156
|
-
└── i18next
|
|
157
|
-
└── resources
|
|
158
|
-
├── ja
|
|
159
|
-
│ └── my-content.json
|
|
160
|
-
├── fr
|
|
161
|
-
│ └── my-content.json
|
|
162
|
-
└── es
|
|
163
|
-
└── my-content.json
|
|
56
|
+
```bash packageManager="npm"
|
|
57
|
+
npm install intlayer @intlayer/sync-json-plugin
|
|
164
58
|
```
|
|
165
59
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
## react-i18next 構成に辞書をインポートする
|
|
169
|
-
|
|
170
|
-
これらのリソースをランタイムで動的に読み込むには、[`i18next-resources-to-backend`](https://www.npmjs.com/package/i18next-resources-to-backend) を使用します。たとえば、プロジェクトに `i18n.ts`(または `.js`)ファイルを作成します。
|
|
171
|
-
|
|
172
|
-
```typescript title="i18n.ts"
|
|
173
|
-
import i18next from "i18next";
|
|
174
|
-
import { initReactI18next } from "react-i18next";
|
|
175
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
176
|
-
|
|
177
|
-
i18next
|
|
178
|
-
// react-i18next プラグイン
|
|
179
|
-
.use(initReactI18next)
|
|
180
|
-
// リソースを動的に読み込む
|
|
181
|
-
.use(
|
|
182
|
-
resourcesToBackend((language: string, namespace: string) => {
|
|
183
|
-
// リソースディレクトリへのインポートパスを調整します
|
|
184
|
-
return import(`../i18next/resources/${language}/${namespace}.json`);
|
|
185
|
-
})
|
|
186
|
-
)
|
|
187
|
-
// i18next を初期化
|
|
188
|
-
.init({
|
|
189
|
-
// フォールバックロケール
|
|
190
|
-
fallbackLng: "ja",
|
|
191
|
-
|
|
192
|
-
// 他の i18next の構成オプションをここに追加できます。詳細は:
|
|
193
|
-
// https://www.i18next.com/overview/configuration-options
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
export default i18next;
|
|
60
|
+
```bash packageManager="pnpm"
|
|
61
|
+
pnpm add intlayer @intlayer/sync-json-plugin
|
|
197
62
|
```
|
|
198
63
|
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
import { initReactI18next } from "react-i18next";
|
|
202
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
203
|
-
|
|
204
|
-
i18next
|
|
205
|
-
.use(initReactI18next)
|
|
206
|
-
.use(
|
|
207
|
-
resourcesToBackend(
|
|
208
|
-
(language, namespace) =>
|
|
209
|
-
import(`../i18next/resources/${language}/${namespace}.json`)
|
|
210
|
-
)
|
|
211
|
-
)
|
|
212
|
-
.init({
|
|
213
|
-
fallbackLng: "ja",
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
export default i18next;
|
|
64
|
+
```bash packageManager="yarn"
|
|
65
|
+
yarn add intlayer @intlayer/sync-json-plugin
|
|
217
66
|
```
|
|
218
67
|
|
|
219
|
-
|
|
68
|
+
**パッケージの説明:**
|
|
220
69
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
import ReactDOM from "react-dom/client";
|
|
224
|
-
// 何よりも前に i18n を初期化します
|
|
225
|
-
import "./i18n";
|
|
226
|
-
import App from "./App";
|
|
70
|
+
- **intlayer**: 国際化管理、コンテンツ宣言、ビルドのためのコアライブラリ
|
|
71
|
+
- **@intlayer/sync-json-plugin**: Intlayerのコンテンツ宣言をreact-i18next互換のJSON形式にエクスポートするプラグイン
|
|
227
72
|
|
|
228
|
-
|
|
229
|
-
<React.StrictMode>
|
|
230
|
-
<App />
|
|
231
|
-
</React.StrictMode>
|
|
232
|
-
);
|
|
233
|
-
```
|
|
73
|
+
### ステップ2: JSONをラップするためのIntlayerプラグインの実装
|
|
234
74
|
|
|
235
|
-
|
|
75
|
+
サポートするロケールを定義するIntlayer設定ファイルを作成します:
|
|
236
76
|
|
|
237
|
-
|
|
238
|
-
以下は TypeScript の簡単な例です。
|
|
77
|
+
**react-i18next用のJSON辞書もエクスポートしたい場合は、`syncJSON`プラグインを追加してください:**
|
|
239
78
|
|
|
240
|
-
```typescript
|
|
241
|
-
import {
|
|
79
|
+
```typescript fileName="intlayer.config.ts"
|
|
80
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
81
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
242
82
|
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
// 各 "t" コールは別々の翻訳ノードです
|
|
248
|
-
heading: t({
|
|
249
|
-
ja: "こんにちは世界",
|
|
250
|
-
fr: "Bonjour le monde",
|
|
251
|
-
es: "Hola Mundo",
|
|
252
|
-
}),
|
|
253
|
-
description: t({
|
|
254
|
-
ja: "私の i18n 説明テキスト...",
|
|
255
|
-
fr: "Ma description en i18n...",
|
|
256
|
-
es: "Mi descripción en i18n...",
|
|
257
|
-
}),
|
|
83
|
+
const config: IntlayerConfig = {
|
|
84
|
+
internationalization: {
|
|
85
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
86
|
+
defaultLocale: Locales.ENGLISH,
|
|
258
87
|
},
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
JSON、`.cjs`、または `.mjs` を好む場合は、[Intlayer ドキュメント](https://intlayer.org/ja/doc/concept/content)を参照してください。
|
|
265
|
-
|
|
266
|
-
> デフォルトでは、有効なコンテンツ宣言は次のファイル拡張子パターンと一致します:
|
|
267
|
-
|
|
268
|
-
> `*.content.{ts,tsx,js,jsx,mjs,mjx,cjs,cjx,json}`
|
|
269
|
-
|
|
270
|
-
## React コンポーネントでの翻訳の使用
|
|
271
|
-
|
|
272
|
-
Intlayer リソースを **ビルド** し、react-i18next を構成した後は、**react-i18next** の `useTranslation` フックを直接使用できます。
|
|
273
|
-
たとえば:
|
|
274
|
-
|
|
275
|
-
```tsx title="src/components/MyComponent/MyComponent.tsx"
|
|
276
|
-
import type { FC } from "react";
|
|
277
|
-
import { useTranslation } from "react-i18next";
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* i18next の "namespace" は "MyComponent.content.ts" の Intlayer `key` です
|
|
281
|
-
* そのため、useTranslation() に "my-component" を渡します。
|
|
282
|
-
*/
|
|
283
|
-
const MyComponent: FC = () => {
|
|
284
|
-
const { t } = useTranslation("my-component");
|
|
285
|
-
|
|
286
|
-
return (
|
|
287
|
-
<div>
|
|
288
|
-
<h1>{t("heading")}</h1>
|
|
289
|
-
<p>{t("description")}</p>
|
|
290
|
-
</div>
|
|
291
|
-
);
|
|
88
|
+
plugins: [
|
|
89
|
+
syncJSON({
|
|
90
|
+
source: ({ key, locale }) => `./messages/${locale}/${key}.json`,
|
|
91
|
+
}),
|
|
92
|
+
],
|
|
292
93
|
};
|
|
293
94
|
|
|
294
|
-
export default
|
|
95
|
+
export default config;
|
|
295
96
|
```
|
|
296
97
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
## オプション: Create React App スクリプトとの統合 (CRACO)
|
|
98
|
+
`syncJSON` プラグインは JSON を自動的にラップします。コンテンツの構造を変更することなく、JSON ファイルの読み書きを行います。
|
|
300
99
|
|
|
301
|
-
|
|
100
|
+
もし JSON と intlayer のコンテンツ宣言ファイル(`.content` ファイル)を共存させたい場合、Intlayer は以下の手順で処理します:
|
|
302
101
|
|
|
303
|
-
1.
|
|
304
|
-
|
|
305
|
-
npm install react-intlayer --save-dev
|
|
306
|
-
```
|
|
307
|
-
2. **package.json スクリプトを調整** して `react-intlayer` スクリプトを使用します:
|
|
102
|
+
1. JSONファイルとコンテンツ宣言ファイルの両方を読み込み、Intlayerの辞書に変換します。
|
|
103
|
+
2. JSONファイルとコンテンツ宣言ファイルの間に競合がある場合、Intlayerはすべての辞書をマージします。これはプラグインの優先度やコンテンツ宣言ファイルの優先度に依存します(すべて設定可能です)。
|
|
308
104
|
|
|
309
|
-
|
|
310
|
-
"scripts": {
|
|
311
|
-
"start": "react-intlayer start",
|
|
312
|
-
"build": "react-intlayer build",
|
|
313
|
-
"transpile": "intlayer build"
|
|
314
|
-
}
|
|
315
|
-
```
|
|
105
|
+
CLIを使用してJSONの翻訳を行った場合やCMSを使用した場合、Intlayerは新しい翻訳でJSONファイルを更新します。
|
|
316
106
|
|
|
317
|
-
|
|
107
|
+
`syncJSON`プラグインの詳細については、[syncJSONプラグインのドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/plugins/sync-json.md)をご参照ください。
|
|
318
108
|
|
|
319
|
-
|
|
109
|
+
## Git設定
|
|
320
110
|
|
|
321
|
-
|
|
111
|
+
自動生成されたIntlayerファイルは無視することを推奨します:
|
|
322
112
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
{
|
|
327
|
-
"compilerOptions": {
|
|
328
|
-
// ...
|
|
329
|
-
},
|
|
330
|
-
"include": ["src", "types"],
|
|
331
|
-
}
|
|
113
|
+
```plaintext fileName=".gitignore"
|
|
114
|
+
# Intlayerによって生成されたファイルを無視する
|
|
115
|
+
.intlayer
|
|
332
116
|
```
|
|
333
117
|
|
|
334
|
-
|
|
118
|
+
これらのファイルはビルドプロセス中に再生成可能であり、バージョン管理にコミットする必要はありません。
|
|
335
119
|
|
|
336
|
-
|
|
120
|
+
### VS Code拡張機能
|
|
337
121
|
|
|
338
|
-
Intlayer
|
|
339
|
-
|
|
340
|
-
```plaintext
|
|
341
|
-
# Intlayer によって生成されたファイルを無視する
|
|
342
|
-
.intlayer
|
|
343
|
-
i18next
|
|
344
|
-
```
|
|
122
|
+
開発者体験を向上させるために、公式の**Intlayer VS Code拡張機能**をインストールしてください:
|
|
345
123
|
|
|
346
|
-
|
|
124
|
+
[VS Codeマーケットプレイスからインストール](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|