@intlayer/docs 5.7.2 → 5.7.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/dist/cjs/generated/docs.entry.cjs +82 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +82 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +2 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/dictionary/gender.md +275 -0
- package/docs/ar/how_works_intlayer.md +1 -1
- package/docs/ar/locale_mapper.md +246 -0
- package/docs/de/dictionary/gender.md +316 -0
- package/docs/de/how_works_intlayer.md +1 -1
- package/docs/de/locale_mapper.md +244 -0
- package/docs/en/dictionary/gender.md +275 -0
- package/docs/en/how_works_intlayer.md +1 -1
- package/docs/en/index.md +3 -0
- package/docs/en/locale_mapper.md +244 -0
- package/docs/en-GB/dictionary/gender.md +275 -0
- package/docs/en-GB/how_works_intlayer.md +1 -1
- package/docs/en-GB/locale_mapper.md +244 -0
- package/docs/es/dictionary/gender.md +275 -0
- package/docs/es/how_works_intlayer.md +1 -1
- package/docs/es/locale_mapper.md +244 -0
- package/docs/fr/dictionary/gender.md +276 -0
- package/docs/fr/how_works_intlayer.md +1 -1
- package/docs/fr/locale_mapper.md +244 -0
- package/docs/hi/dictionary/gender.md +276 -0
- package/docs/hi/how_works_intlayer.md +1 -1
- package/docs/hi/locale_mapper.md +244 -0
- package/docs/it/dictionary/gender.md +275 -0
- package/docs/it/how_works_intlayer.md +1 -1
- package/docs/it/locale_mapper.md +244 -0
- package/docs/ja/dictionary/gender.md +275 -0
- package/docs/ja/how_works_intlayer.md +1 -1
- package/docs/ja/locale_mapper.md +244 -0
- package/docs/ko/dictionary/gender.md +275 -0
- package/docs/ko/how_works_intlayer.md +1 -1
- package/docs/ko/locale_mapper.md +244 -0
- package/docs/pt/dictionary/gender.md +275 -0
- package/docs/pt/how_works_intlayer.md +1 -1
- package/docs/pt/locale_mapper.md +244 -0
- package/docs/ru/dictionary/gender.md +275 -0
- package/docs/ru/how_works_intlayer.md +1 -1
- package/docs/ru/locale_mapper.md +244 -0
- package/docs/zh/dictionary/gender.md +275 -0
- package/docs/zh/how_works_intlayer.md +1 -1
- package/docs/zh/locale_mapper.md +244 -0
- package/package.json +11 -11
- package/src/generated/docs.entry.ts +82 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-07-27
|
|
3
|
+
updatedAt: 2025-07-27
|
|
4
|
+
title: 性別に基づくコンテンツ
|
|
5
|
+
description: Intlayerで性別に基づくコンテンツを使用して、性別に応じて動的にコンテンツを表示する方法を学びます。このドキュメントに従って、プロジェクトで性別特有のコンテンツを効率的に実装してください。
|
|
6
|
+
keywords:
|
|
7
|
+
- 性別に基づくコンテンツ
|
|
8
|
+
- 動的レンダリング
|
|
9
|
+
- ドキュメント
|
|
10
|
+
- Intlayer
|
|
11
|
+
- Next.js
|
|
12
|
+
- JavaScript
|
|
13
|
+
- React
|
|
14
|
+
slugs:
|
|
15
|
+
- doc
|
|
16
|
+
- concept
|
|
17
|
+
- content
|
|
18
|
+
- gender
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
# 性別に基づくコンテンツ / Intlayerにおける性別
|
|
22
|
+
|
|
23
|
+
## 性別の仕組み
|
|
24
|
+
|
|
25
|
+
Intlayerでは、性別に基づくコンテンツは`gender`関数を通じて実現されます。この関数は特定の性別の値('male'、'female')を対応するコンテンツにマッピングします。この方法により、指定された性別に基づいて動的にコンテンツを選択することが可能です。React IntlayerやNext Intlayerと統合すると、実行時に提供された性別に応じて適切なコンテンツが自動的に選択されます。
|
|
26
|
+
|
|
27
|
+
## 性別に基づくコンテンツの設定
|
|
28
|
+
|
|
29
|
+
Intlayerプロジェクトで性別に基づくコンテンツを設定するには、性別特有の定義を含むコンテンツモジュールを作成します。以下に様々な形式の例を示します。
|
|
30
|
+
|
|
31
|
+
```typescript fileName="**/*.content.ts" contentDeclarationFormat="typescript"
|
|
32
|
+
import { gender, type Dictionary } from "intlayer";
|
|
33
|
+
|
|
34
|
+
const myGenderContent = {
|
|
35
|
+
key: "my_key",
|
|
36
|
+
content: {
|
|
37
|
+
myGender: gender({
|
|
38
|
+
male: "男性ユーザー向けのコンテンツ",
|
|
39
|
+
female: "女性ユーザー向けのコンテンツ",
|
|
40
|
+
fallback: "性別が指定されていない場合のコンテンツ", // オプション
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
} satisfies Dictionary;
|
|
44
|
+
|
|
45
|
+
export default myGenderContent;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```javascript fileName="**/*.content.mjs" contentDeclarationFormat="esm"
|
|
49
|
+
import { gender } from "intlayer";
|
|
50
|
+
|
|
51
|
+
/** @type {import('intlayer').Dictionary} */
|
|
52
|
+
const myGenderContent = {
|
|
53
|
+
key: "my_key",
|
|
54
|
+
content: {
|
|
55
|
+
myGender: gender({
|
|
56
|
+
male: "男性ユーザー向けのコンテンツ",
|
|
57
|
+
female: "女性ユーザー向けのコンテンツ",
|
|
58
|
+
fallback: "性別が指定されていない場合のコンテンツ", // オプション
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default myGenderContent;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```javascript fileName="**/*.content.cjs" contentDeclarationFormat="commonjs"
|
|
67
|
+
const { gender } = require("intlayer");
|
|
68
|
+
|
|
69
|
+
/** @type {import('intlayer').Dictionary} */
|
|
70
|
+
const myGenderContent = {
|
|
71
|
+
key: "my_key",
|
|
72
|
+
content: {
|
|
73
|
+
myGender: gender({
|
|
74
|
+
male: "男性ユーザー向けのコンテンツ",
|
|
75
|
+
female: "女性ユーザー向けのコンテンツ",
|
|
76
|
+
fallback: "性別が指定されていない場合のコンテンツ", // オプション
|
|
77
|
+
}),
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
module.exports = myGenderContent;
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```json5 fileName="**/*.content.json" contentDeclarationFormat="json"
|
|
85
|
+
{
|
|
86
|
+
"$schema": "https://intlayer.org/schema.json",
|
|
87
|
+
"key": "my_key",
|
|
88
|
+
"content": {
|
|
89
|
+
"myGender": {
|
|
90
|
+
"nodeType": "gender",
|
|
91
|
+
"gender": {
|
|
92
|
+
"male": "男性ユーザー向けのコンテンツ",
|
|
93
|
+
"female": "女性ユーザー向けのコンテンツ",
|
|
94
|
+
"fallback": "性別が指定されていない場合のコンテンツ", // オプション
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
> フォールバックが宣言されていない場合、性別が指定されていないか、定義された性別に一致しない場合は、最後に宣言されたキーがフォールバックとして使用されます。
|
|
102
|
+
|
|
103
|
+
## React Intlayerでの性別ベースのコンテンツの使用
|
|
104
|
+
|
|
105
|
+
Reactコンポーネント内で性別ベースのコンテンツを利用するには、`react-intlayer`パッケージから`useIntlayer`フックをインポートして使用します。このフックは指定されたキーのコンテンツを取得し、適切な出力を選択するために性別を渡すことができます。
|
|
106
|
+
|
|
107
|
+
```tsx fileName="**/*.tsx" codeFormat="typescript"
|
|
108
|
+
import type { FC } from "react";
|
|
109
|
+
import { useIntlayer } from "react-intlayer";
|
|
110
|
+
|
|
111
|
+
const GenderComponent: FC = () => {
|
|
112
|
+
const { myGender } = useIntlayer("my_key");
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<div>
|
|
116
|
+
<p>
|
|
117
|
+
{
|
|
118
|
+
/* 出力: 男性ユーザー向けのコンテンツ */
|
|
119
|
+
myGender("male")
|
|
120
|
+
}
|
|
121
|
+
</p>
|
|
122
|
+
<p>
|
|
123
|
+
{
|
|
124
|
+
/* 出力: 女性ユーザー向けのコンテンツ */
|
|
125
|
+
myGender("female")
|
|
126
|
+
}
|
|
127
|
+
</p>
|
|
128
|
+
<p>
|
|
129
|
+
{
|
|
130
|
+
/* 出力: 男性ユーザー向けのコンテンツ */
|
|
131
|
+
myGender("m")
|
|
132
|
+
}
|
|
133
|
+
</p>
|
|
134
|
+
<p>
|
|
135
|
+
{
|
|
136
|
+
/* 出力: 女性ユーザー向けのコンテンツ */
|
|
137
|
+
myGender("f")
|
|
138
|
+
}
|
|
139
|
+
</p>
|
|
140
|
+
<p>
|
|
141
|
+
{
|
|
142
|
+
/* 出力: 性別が指定されていない場合のコンテンツ */
|
|
143
|
+
myGender("")
|
|
144
|
+
}
|
|
145
|
+
</p>
|
|
146
|
+
<p>
|
|
147
|
+
{
|
|
148
|
+
/* 出力: 性別が指定されていない場合のコンテンツ */
|
|
149
|
+
myGender(undefined)
|
|
150
|
+
}
|
|
151
|
+
</p>
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export default GenderComponent;
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
```javascript fileName="**/*.mjx" codeFormat="esm"
|
|
160
|
+
import { useIntlayer } from "react-intlayer";
|
|
161
|
+
|
|
162
|
+
const GenderComponent = () => {
|
|
163
|
+
const { myGender } = useIntlayer("my_key");
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<div>
|
|
167
|
+
<p>
|
|
168
|
+
{
|
|
169
|
+
/* 出力: 男性ユーザー向けのコンテンツ */
|
|
170
|
+
myGender("male")
|
|
171
|
+
}
|
|
172
|
+
</p>
|
|
173
|
+
<p>
|
|
174
|
+
{
|
|
175
|
+
/* 出力: 女性ユーザー向けのコンテンツ */
|
|
176
|
+
myGender("female")
|
|
177
|
+
}
|
|
178
|
+
</p>
|
|
179
|
+
<p>
|
|
180
|
+
{
|
|
181
|
+
/* 出力: 男性ユーザー向けのコンテンツ */
|
|
182
|
+
myGender("m")
|
|
183
|
+
}
|
|
184
|
+
</p>
|
|
185
|
+
<p>
|
|
186
|
+
{
|
|
187
|
+
/* 出力: 女性ユーザー向けのコンテンツ */
|
|
188
|
+
myGender("f")
|
|
189
|
+
}
|
|
190
|
+
</p>
|
|
191
|
+
<p>
|
|
192
|
+
{
|
|
193
|
+
/* 出力: 性別が指定されていない場合のコンテンツ */
|
|
194
|
+
myGender("")
|
|
195
|
+
}
|
|
196
|
+
</p>
|
|
197
|
+
<p>
|
|
198
|
+
{
|
|
199
|
+
/* 出力: 性別が指定されていない場合のコンテンツ */
|
|
200
|
+
myGender(undefined)
|
|
201
|
+
}
|
|
202
|
+
</p>
|
|
203
|
+
</div>
|
|
204
|
+
);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export default GenderComponent;
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
```javascript fileName="**/*.cjs" codeFormat="commonjs"
|
|
211
|
+
const { useIntlayer } = require("react-intlayer");
|
|
212
|
+
|
|
213
|
+
const GenderComponent = () => {
|
|
214
|
+
const { myGender } = useIntlayer("my_key");
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<div>
|
|
218
|
+
<p>
|
|
219
|
+
{
|
|
220
|
+
/* 出力: 男性ユーザー向けのコンテンツ */
|
|
221
|
+
myGender("male")
|
|
222
|
+
}
|
|
223
|
+
</p>
|
|
224
|
+
<p>
|
|
225
|
+
{
|
|
226
|
+
/* 出力: 女性ユーザー向けのコンテンツ */
|
|
227
|
+
myGender("female")
|
|
228
|
+
}
|
|
229
|
+
</p>
|
|
230
|
+
<p>
|
|
231
|
+
{
|
|
232
|
+
/* 出力: 男性ユーザー向けのコンテンツ */
|
|
233
|
+
myGender("m")
|
|
234
|
+
}
|
|
235
|
+
</p>
|
|
236
|
+
<p>
|
|
237
|
+
{
|
|
238
|
+
/* 出力: 女性ユーザー向けのコンテンツ */
|
|
239
|
+
myGender("f")
|
|
240
|
+
}
|
|
241
|
+
</p>
|
|
242
|
+
<p>
|
|
243
|
+
{
|
|
244
|
+
/* 出力: 性別が指定されていない場合のコンテンツ */
|
|
245
|
+
myGender("")
|
|
246
|
+
}
|
|
247
|
+
</p>
|
|
248
|
+
<p>
|
|
249
|
+
{
|
|
250
|
+
/* 出力: 性別が指定されていない場合のコンテンツ */
|
|
251
|
+
myGender(undefined)
|
|
252
|
+
}
|
|
253
|
+
</p>
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
module.exports = GenderComponent;
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## 追加リソース
|
|
262
|
+
|
|
263
|
+
設定や使用方法の詳細については、以下のリソースを参照してください:
|
|
264
|
+
|
|
265
|
+
- [Intlayer CLI ドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/intlayer_cli.md)
|
|
266
|
+
- [React Intlayer ドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/intlayer_with_create_react_app.md)
|
|
267
|
+
- [Next Intlayer ドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/intlayer_with_nextjs_15.md)
|
|
268
|
+
|
|
269
|
+
これらのリソースは、さまざまな環境やフレームワークにおけるIntlayerのセットアップと使用方法について、さらに詳しい情報を提供します。
|
|
270
|
+
|
|
271
|
+
## ドキュメント履歴
|
|
272
|
+
|
|
273
|
+
| バージョン | 日付 | 変更内容 |
|
|
274
|
+
| ---------- | ---------- | ---------------------------- |
|
|
275
|
+
| 5.7.2 | 2025-07-27 | 性別に基づくコンテンツの導入 |
|
|
@@ -93,7 +93,7 @@ Intlayerは、視覚的にコンテンツを編集できるビジュアルエデ
|
|
|
93
93
|
|
|
94
94
|
- サーバーは、クライアントからのリクエストを受け取り、`dictionaries`やクライアント側でアクセス可能にするための設定など、アプリケーションのコンテンツを取得するシンプルなExpressアプリケーションです。
|
|
95
95
|
- 一方、クライアントは視覚的なインターフェースを使ってコンテンツとやり取りするためのReactアプリケーションです。
|
|
96
|
-
`useIntlayer`を使ってコンテンツを呼び出し、エディタが有効になっている場合、文字列は自動的に`IntlayerNode`という名前のProxyオブジェクトでラップされます。このノードは、ビジュアルエディタのインターフェースを含むラップされたiframeと通信するために`window.
|
|
96
|
+
`useIntlayer`を使ってコンテンツを呼び出し、エディタが有効になっている場合、文字列は自動的に`IntlayerNode`という名前のProxyオブジェクトでラップされます。このノードは、ビジュアルエディタのインターフェースを含むラップされたiframeと通信するために`window.postMessage`を使用します。
|
|
97
97
|
エディタ側では、これらのメッセージを受信してコンテンツとの実際のインタラクションをシミュレートし、アプリケーションのコンテキスト内で直接テキストを編集できるようにします。
|
|
98
98
|
|
|
99
99
|
## アプリビルドの最適化
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-07-27
|
|
3
|
+
updatedAt: 2025-07-27
|
|
4
|
+
title: ロケールマッパー
|
|
5
|
+
description: ロケールマッパーの動作方法を解説します。アプリケーションでロケールマッパーが使用する手順を確認しましょう。各パッケージの役割も説明します。
|
|
6
|
+
keywords:
|
|
7
|
+
- ロケールマッパー
|
|
8
|
+
- はじめに
|
|
9
|
+
- Intlayer
|
|
10
|
+
- アプリケーション
|
|
11
|
+
- パッケージ
|
|
12
|
+
slugs:
|
|
13
|
+
- doc
|
|
14
|
+
- locale-mapper
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# ロケールマッパー
|
|
18
|
+
|
|
19
|
+
ロケールマッパーは、Intlayerアプリケーションで国際化データを扱うための強力なユーティリティです。ロケール固有のデータを変換・整理するための3つの主要な関数、`localeMap`、`localeFlatMap`、`localeRecord`を提供します。
|
|
20
|
+
|
|
21
|
+
## ロケールマッパーの仕組み
|
|
22
|
+
|
|
23
|
+
ロケールマッパーは、ロケールに関する必要な情報をすべて含む`LocaleData`オブジェクトを操作します:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
type LocaleData = {
|
|
27
|
+
locale: LocalesValues; // 現在のロケールコード(例:'en', 'fr')
|
|
28
|
+
defaultLocale: LocalesValues; // デフォルトのロケールコード
|
|
29
|
+
isDefault: boolean; // これはデフォルトのロケールかどうか
|
|
30
|
+
locales: LocalesValues[]; // 利用可能なすべてのロケールの配列
|
|
31
|
+
urlPrefix: string; // このロケールのURLプレフィックス(例:'/fr' または '')
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
マッパー関数は、設定内の各ロケールに対してこのデータを自動的に生成し、以下を考慮します:
|
|
36
|
+
|
|
37
|
+
- 設定されたロケールリスト
|
|
38
|
+
- デフォルトロケールの設定
|
|
39
|
+
- デフォルトロケールがURLにプレフィックスされるかどうか
|
|
40
|
+
|
|
41
|
+
## コア関数
|
|
42
|
+
|
|
43
|
+
### `localeMap`
|
|
44
|
+
|
|
45
|
+
マッパー関数を使って各ロケールを単一のオブジェクトに変換します。
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
localeMap<T>(
|
|
49
|
+
mapper: (locale: LocaleData) => T,
|
|
50
|
+
locales?: LocalesValues[],
|
|
51
|
+
defaultLocale?: LocalesValues,
|
|
52
|
+
prefixDefault?: boolean
|
|
53
|
+
): T[]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**例:ルートオブジェクトの作成**
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { localeMap } from "intlayer";
|
|
60
|
+
|
|
61
|
+
const routes = localeMap((localizedData) => ({
|
|
62
|
+
path: localizedData.urlPrefix,
|
|
63
|
+
name: localizedData.locale,
|
|
64
|
+
isDefault: localizedData.isDefault,
|
|
65
|
+
locales: localizedData.locales,
|
|
66
|
+
defaultLocale: localizedData.defaultLocale,
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
// 結果:
|
|
70
|
+
// [
|
|
71
|
+
// { path: '/', name: 'en', isDefault: true, locales: ['en', 'fr', 'es'], defaultLocale: 'en' },
|
|
72
|
+
// { path: '/fr', name: 'fr', isDefault: false, locales: ['en', 'fr', 'es'], defaultLocale: 'en' },
|
|
73
|
+
// { path: '/es', name: 'es', isDefault: false, locales: ['en', 'fr', 'es'], defaultLocale: 'en' }
|
|
74
|
+
// ]
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### `localeFlatMap`
|
|
78
|
+
|
|
79
|
+
`localeMap`に似ていますが、マッパー関数がオブジェクトの配列を返し、それが単一の配列にフラット化されます。
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
localeFlatMap<T>(
|
|
83
|
+
mapper: (locale: LocaleData) => T[],
|
|
84
|
+
locales?: LocalesValues[],
|
|
85
|
+
defaultLocale?: LocalesValues,
|
|
86
|
+
prefixDefault?: boolean
|
|
87
|
+
): T[]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**例: ロケールごとに複数のルートを作成する**
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { localeFlatMap } from "intlayer";
|
|
94
|
+
|
|
95
|
+
const routes = localeFlatMap((localizedData) => [
|
|
96
|
+
{
|
|
97
|
+
path: localizedData.urlPrefix,
|
|
98
|
+
name: localizedData.locale,
|
|
99
|
+
isDefault: localizedData.isDefault,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
path: `${localizedData.urlPrefix}/about`,
|
|
103
|
+
name: `${localizedData.locale}-about`,
|
|
104
|
+
isDefault: localizedData.isDefault,
|
|
105
|
+
},
|
|
106
|
+
]);
|
|
107
|
+
|
|
108
|
+
// 結果:
|
|
109
|
+
// [
|
|
110
|
+
// { path: '/', name: 'en', isDefault: true },
|
|
111
|
+
{ path: '/about', name: 'en-about', isDefault: true },
|
|
112
|
+
{ path: '/fr', name: 'fr', isDefault: false },
|
|
113
|
+
{ path: '/fr/about', name: 'fr-about', isDefault: false },
|
|
114
|
+
{ path: '/es', name: 'es', isDefault: false },
|
|
115
|
+
{ path: '/es/about', name: 'es-about', isDefault: false }
|
|
116
|
+
]
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### `localeRecord`
|
|
120
|
+
|
|
121
|
+
各ロケールをキーとし、マッパー関数によって変換された値をマッピングするレコードオブジェクトを作成します。
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
localeRecord<T>(
|
|
125
|
+
mapper: (locale: LocaleData) => T,
|
|
126
|
+
locales?: Locales[],
|
|
127
|
+
defaultLocale?: Locales,
|
|
128
|
+
prefixDefault?: boolean
|
|
129
|
+
): Record<Locales, T>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**例: 翻訳ファイルの読み込み**
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { localeRecord } from "intlayer";
|
|
136
|
+
|
|
137
|
+
const translations = localeRecord(({ locale }) =>
|
|
138
|
+
require(`./translations/${locale}.json`)
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// 結果:
|
|
142
|
+
// {
|
|
143
|
+
// en: { welcome: 'Welcome', hello: 'Hello' },
|
|
144
|
+
// fr: { welcome: 'Bienvenue', hello: 'Bonjour' },
|
|
145
|
+
// es: { welcome: 'Bienvenido', hello: 'Hola' }
|
|
146
|
+
// }
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## ロケールマッパーの設定
|
|
150
|
+
|
|
151
|
+
ロケールマッパーは自動的にあなたのIntlayer設定を使用しますが、パラメータを渡すことでデフォルト設定を上書きすることができます。
|
|
152
|
+
|
|
153
|
+
### デフォルト設定の使用
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { localeMap } from "intlayer";
|
|
157
|
+
|
|
158
|
+
// intlayer.config.tsの設定を使用
|
|
159
|
+
const routes = localeMap((data) => ({
|
|
160
|
+
path: data.urlPrefix,
|
|
161
|
+
locale: data.locale,
|
|
162
|
+
}));
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### 設定の上書き
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { localeMap } from "intlayer";
|
|
169
|
+
|
|
170
|
+
// ロケールとデフォルトロケールを上書き
|
|
171
|
+
const customRoutes = localeMap(
|
|
172
|
+
(data) => ({ path: data.urlPrefix, locale: data.locale }),
|
|
173
|
+
["en", "fr", "de"], // カスタムロケール
|
|
174
|
+
"en", // カスタムデフォルトロケール
|
|
175
|
+
true // URLにデフォルトロケールをプレフィックスする
|
|
176
|
+
);
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## 高度な使用例
|
|
180
|
+
|
|
181
|
+
### ナビゲーションメニューの作成
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { localeMap } from "intlayer";
|
|
185
|
+
|
|
186
|
+
const navigationItems = localeMap((data) => ({
|
|
187
|
+
label: data.locale.toUpperCase(),
|
|
188
|
+
href: data.urlPrefix || "/",
|
|
189
|
+
isActive: data.isDefault,
|
|
190
|
+
flag: `/flags/${data.locale}.svg`, // 国旗のパス
|
|
191
|
+
}));
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### サイトマップデータの生成
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import { localeFlatMap } from "intlayer";
|
|
198
|
+
|
|
199
|
+
const sitemapUrls = localeFlatMap((data) => [
|
|
200
|
+
{
|
|
201
|
+
url: `${data.urlPrefix}/`,
|
|
202
|
+
lastmod: new Date().toISOString(),
|
|
203
|
+
changefreq: "daily",
|
|
204
|
+
priority: data.isDefault ? 1.0 : 0.8,
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
url: `${data.urlPrefix}/about`,
|
|
208
|
+
lastmod: new Date().toISOString(),
|
|
209
|
+
changefreq: "monthly",
|
|
210
|
+
priority: data.isDefault ? 0.8 : 0.6,
|
|
211
|
+
},
|
|
212
|
+
]);
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### 動的翻訳の読み込み
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
import { localeRecord } from "intlayer";
|
|
219
|
+
|
|
220
|
+
const translationModules = localeRecord(({ locale }) => ({
|
|
221
|
+
messages: import(`./locales/${locale}/messages.json`), // メッセージのインポート
|
|
222
|
+
validation: import(`./locales/${locale}/validation.json`), // バリデーションメッセージのインポート
|
|
223
|
+
metadata: {
|
|
224
|
+
locale,
|
|
225
|
+
direction: ["ar", "he", "fa"].includes(locale) ? "rtl" : "ltr", // 右から左への言語かどうかの判定
|
|
226
|
+
},
|
|
227
|
+
}));
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## 設定との統合
|
|
231
|
+
|
|
232
|
+
Locale MapperはIntlayerの設定とシームレスに統合されます:
|
|
233
|
+
|
|
234
|
+
- **ロケール**: `configuration.internationalization.locales` を自動的に使用します
|
|
235
|
+
- **デフォルトロケール**: `configuration.internationalization.defaultLocale` を使用します
|
|
236
|
+
- **URLプレフィックス**: `configuration.middleware.prefixDefault` を尊重します
|
|
237
|
+
|
|
238
|
+
これにより、アプリケーション全体で一貫性が保たれ、設定の重複が削減されます。
|
|
239
|
+
|
|
240
|
+
## ドキュメント履歴
|
|
241
|
+
|
|
242
|
+
| バージョン | 日付 | 変更内容 |
|
|
243
|
+
| ---------- | ---------- | ------------------------------------ |
|
|
244
|
+
| 5.7.2 | 2025-07-27 | ロケールマッパーのドキュメントを追加 |
|