@intlayer/docs 5.7.2 → 5.7.3
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 +12 -12
- 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: Gender-Based Content
|
|
5
|
+
description: Learn how to use gender-based content in Intlayer to dynamically display content based on gender. Follow this documentation to implement gender-specific content efficiently in your project.
|
|
6
|
+
keywords:
|
|
7
|
+
- Gender-Based Content
|
|
8
|
+
- Dynamic Rendering
|
|
9
|
+
- Documentation
|
|
10
|
+
- Intlayer
|
|
11
|
+
- Next.js
|
|
12
|
+
- JavaScript
|
|
13
|
+
- React
|
|
14
|
+
slugs:
|
|
15
|
+
- doc
|
|
16
|
+
- concept
|
|
17
|
+
- content
|
|
18
|
+
- gender
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
# Gender-Based Content / Gender in Intlayer
|
|
22
|
+
|
|
23
|
+
## How Gender Works
|
|
24
|
+
|
|
25
|
+
In Intlayer, gender-based content is achieved through the `gender` function, which maps specific gender values ('male', 'female') to their corresponding content. This approach enables you to dynamically select content based on a given gender. When integrated with React Intlayer or Next Intlayer, the appropriate content is automatically chosen according to the gender provided at runtime.
|
|
26
|
+
|
|
27
|
+
## Setting Up Gender-Based Content
|
|
28
|
+
|
|
29
|
+
To set up gender-based content in your Intlayer project, create a content module that includes your gender-specific definitions. Below are examples in various formats.
|
|
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: "my content for male users",
|
|
39
|
+
female: "my content for female users",
|
|
40
|
+
fallback: "my content when gender is not specified", // Optional
|
|
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: "my content for male users",
|
|
57
|
+
female: "my content for female users",
|
|
58
|
+
fallback: "my content when gender is not specified", // Optional
|
|
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: "my content for male users",
|
|
75
|
+
female: "my content for female users",
|
|
76
|
+
fallback: "my content when gender is not specified", // Optional
|
|
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": "my content for male users",
|
|
93
|
+
"female": "my content for female users",
|
|
94
|
+
"fallback": "my content when gender is not specified", // Optional
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
> If no fallback is declared, the last key declared will be taken as a fallback if the gender is not specified or doesn't match any defined gender.
|
|
102
|
+
|
|
103
|
+
## Using Gender-Based Content with React Intlayer
|
|
104
|
+
|
|
105
|
+
To utilize gender-based content within a React component, import and use the `useIntlayer` hook from the `react-intlayer` package. This hook fetches the content for the specified key and allows you to pass in a gender to select the appropriate output.
|
|
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
|
+
/* Output: my content for male users */
|
|
119
|
+
myGender("male")
|
|
120
|
+
}
|
|
121
|
+
</p>
|
|
122
|
+
<p>
|
|
123
|
+
{
|
|
124
|
+
/* Output: my content for female users */
|
|
125
|
+
myGender("female")
|
|
126
|
+
}
|
|
127
|
+
</p>
|
|
128
|
+
<p>
|
|
129
|
+
{
|
|
130
|
+
/* Output: my content for male users */
|
|
131
|
+
myGender("m")
|
|
132
|
+
}
|
|
133
|
+
</p>
|
|
134
|
+
<p>
|
|
135
|
+
{
|
|
136
|
+
/* Output: my content for female users */
|
|
137
|
+
myGender("f")
|
|
138
|
+
}
|
|
139
|
+
</p>
|
|
140
|
+
<p>
|
|
141
|
+
{
|
|
142
|
+
/* Output: my content when gender is not specified */
|
|
143
|
+
myGender("")
|
|
144
|
+
}
|
|
145
|
+
</p>
|
|
146
|
+
<p>
|
|
147
|
+
{
|
|
148
|
+
/* Output: my content when gender is not specified */
|
|
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
|
+
/* Output: my content for male users */
|
|
170
|
+
myGender("male")
|
|
171
|
+
}
|
|
172
|
+
</p>
|
|
173
|
+
<p>
|
|
174
|
+
{
|
|
175
|
+
/* Output: my content for female users */
|
|
176
|
+
myGender("female")
|
|
177
|
+
}
|
|
178
|
+
</p>
|
|
179
|
+
<p>
|
|
180
|
+
{
|
|
181
|
+
/* Output: my content for male users */
|
|
182
|
+
myGender("m")
|
|
183
|
+
}
|
|
184
|
+
</p>
|
|
185
|
+
<p>
|
|
186
|
+
{
|
|
187
|
+
/* Output: my content for female users */
|
|
188
|
+
myGender("f")
|
|
189
|
+
}
|
|
190
|
+
</p>
|
|
191
|
+
<p>
|
|
192
|
+
{
|
|
193
|
+
/* Output: my content when gender is not specified */
|
|
194
|
+
myGender("")
|
|
195
|
+
}
|
|
196
|
+
</p>
|
|
197
|
+
<p>
|
|
198
|
+
{
|
|
199
|
+
/* Output: my content when gender is not specified */
|
|
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
|
+
/* Output: my content for male users */
|
|
221
|
+
myGender("male")
|
|
222
|
+
}
|
|
223
|
+
</p>
|
|
224
|
+
<p>
|
|
225
|
+
{
|
|
226
|
+
/* Output: my content for female users */
|
|
227
|
+
myGender("female")
|
|
228
|
+
}
|
|
229
|
+
</p>
|
|
230
|
+
<p>
|
|
231
|
+
{
|
|
232
|
+
/* Output: my content for male users */
|
|
233
|
+
myGender("m")
|
|
234
|
+
}
|
|
235
|
+
</p>
|
|
236
|
+
<p>
|
|
237
|
+
{
|
|
238
|
+
/* Output: my content for female users */
|
|
239
|
+
myGender("f")
|
|
240
|
+
}
|
|
241
|
+
</p>
|
|
242
|
+
<p>
|
|
243
|
+
{
|
|
244
|
+
/* Output: my content when gender is not specified */
|
|
245
|
+
myGender("")
|
|
246
|
+
}
|
|
247
|
+
</p>
|
|
248
|
+
<p>
|
|
249
|
+
{
|
|
250
|
+
/* Output: my content when gender is not specified */
|
|
251
|
+
myGender(undefined)
|
|
252
|
+
}
|
|
253
|
+
</p>
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
module.exports = GenderComponent;
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Additional Resources
|
|
262
|
+
|
|
263
|
+
For more detailed information on configuration and usage, refer to the following resources:
|
|
264
|
+
|
|
265
|
+
- [Intlayer CLI Documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_cli.md)
|
|
266
|
+
- [React Intlayer Documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_create_react_app.md)
|
|
267
|
+
- [Next Intlayer Documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_nextjs_15.md)
|
|
268
|
+
|
|
269
|
+
These resources offer further insights into the setup and usage of Intlayer across various environments and frameworks.
|
|
270
|
+
|
|
271
|
+
## Doc History
|
|
272
|
+
|
|
273
|
+
| Version | Date | Changes |
|
|
274
|
+
| ------- | ---------- | ------------------------------ |
|
|
275
|
+
| 5.7.2 | 2025-07-27 | Introduce gender based content |
|
|
@@ -95,7 +95,7 @@ Intlayer also provides a visual editor to allow you to edit your content in a vi
|
|
|
95
95
|
- The server is a simple Express application that listens to requests from the client and retreives the content of your application, such as the `dictionaries` and the configuration to make it accessible on the client side.
|
|
96
96
|
- On the other hand, the client is a React application that is used to interact with your content using a visual interface.
|
|
97
97
|
|
|
98
|
-
When you call your content using `useIntlayer` and the editor is enabled, it automatically wraps your strings with an Proxy object named `IntlayerNode`. This node uses `window.
|
|
98
|
+
When you call your content using `useIntlayer` and the editor is enabled, it automatically wraps your strings with an Proxy object named `IntlayerNode`. This node uses `window.postMessage` to communicate with a wrapped iframe containing the visual editor interface.
|
|
99
99
|
On the editor side, the editor listens to these messages and simulates real interaction with your content, allowing you to edit text directly in your application's context.
|
|
100
100
|
|
|
101
101
|
## App build optimization
|
package/docs/en/index.md
CHANGED
|
@@ -63,6 +63,9 @@ Organize your multilingual content close to your code to keep everything consist
|
|
|
63
63
|
- **[Condition](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/conditional.md)**
|
|
64
64
|
Learn how to use conditional logic in Intlayer to create dynamic content.
|
|
65
65
|
|
|
66
|
+
- **[Gender](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/gender.md)**
|
|
67
|
+
Learn how to use gender logic in Intlayer to create dynamic content.
|
|
68
|
+
|
|
66
69
|
- **[Insertion](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/insertion.md)**
|
|
67
70
|
Discover how to insert values in a string using insertion placeholders.
|
|
68
71
|
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-07-27
|
|
3
|
+
updatedAt: 2025-07-27
|
|
4
|
+
title: Locale Mapper
|
|
5
|
+
description: Discover how Locale Mapper works. See the steps used by Locale Mapper in your application. See what does the different packages do.
|
|
6
|
+
keywords:
|
|
7
|
+
- Locale Mapper
|
|
8
|
+
- Get started
|
|
9
|
+
- Intlayer
|
|
10
|
+
- Application
|
|
11
|
+
- Packages
|
|
12
|
+
slugs:
|
|
13
|
+
- doc
|
|
14
|
+
- locale-mapper
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Locale Mapper
|
|
18
|
+
|
|
19
|
+
The Locale Mapper is a powerful utility that helps you work with internationalization data in your Intlayer application. It provides three main functions to transform and organize locale-specific data: `localeMap`, `localeFlatMap`, and `localeRecord`.
|
|
20
|
+
|
|
21
|
+
## How Locale Mapper Works
|
|
22
|
+
|
|
23
|
+
The Locale Mapper operates on a `LocaleData` object that contains all the necessary information about a locale:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
type LocaleData = {
|
|
27
|
+
locale: LocalesValues; // Current locale code (e.g., 'en', 'fr')
|
|
28
|
+
defaultLocale: LocalesValues; // Default locale code
|
|
29
|
+
isDefault: boolean; // Whether this is the default locale
|
|
30
|
+
locales: LocalesValues[]; // Array of all available locales
|
|
31
|
+
urlPrefix: string; // URL prefix for this locale (e.g., '/fr' or '')
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The mapper functions automatically generate this data for each locale in your configuration, taking into account:
|
|
36
|
+
|
|
37
|
+
- Your configured locales list
|
|
38
|
+
- The default locale setting
|
|
39
|
+
- Whether the default locale should be prefixed in URLs
|
|
40
|
+
|
|
41
|
+
## Core Functions
|
|
42
|
+
|
|
43
|
+
### `localeMap`
|
|
44
|
+
|
|
45
|
+
Transforms each locale into a single object using a mapper function.
|
|
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
|
+
**Example: Creating route objects**
|
|
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
|
+
// Result:
|
|
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
|
+
Similar to `localeMap`, but the mapper function returns an array of objects that gets flattened into a single array.
|
|
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
|
+
**Example: Creating multiple routes per locale**
|
|
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
|
+
// Result:
|
|
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
|
+
Creates a record object where each locale is a key mapping to a value transformed by the mapper function.
|
|
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
|
+
**Example: Loading translation files**
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { localeRecord } from "intlayer";
|
|
136
|
+
|
|
137
|
+
const translations = localeRecord(({ locale }) =>
|
|
138
|
+
require(`./translations/${locale}.json`)
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// Result:
|
|
142
|
+
// {
|
|
143
|
+
// en: { welcome: 'Welcome', hello: 'Hello' },
|
|
144
|
+
// fr: { welcome: 'Bienvenue', hello: 'Bonjour' },
|
|
145
|
+
// es: { welcome: 'Bienvenido', hello: 'Hola' }
|
|
146
|
+
// }
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Setting Up Locale Mapper
|
|
150
|
+
|
|
151
|
+
The Locale Mapper automatically uses your Intlayer configuration, but you can override the defaults by passing parameters:
|
|
152
|
+
|
|
153
|
+
### Using Default Configuration
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { localeMap } from "intlayer";
|
|
157
|
+
|
|
158
|
+
// Uses configuration from intlayer.config.ts
|
|
159
|
+
const routes = localeMap((data) => ({
|
|
160
|
+
path: data.urlPrefix,
|
|
161
|
+
locale: data.locale,
|
|
162
|
+
}));
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Overriding Configuration
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { localeMap } from "intlayer";
|
|
169
|
+
|
|
170
|
+
// Override locales and default locale
|
|
171
|
+
const customRoutes = localeMap(
|
|
172
|
+
(data) => ({ path: data.urlPrefix, locale: data.locale }),
|
|
173
|
+
["en", "fr", "de"], // Custom locales
|
|
174
|
+
"en", // Custom default locale
|
|
175
|
+
true // Prefix default locale in URLs
|
|
176
|
+
);
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Advanced Usage Examples
|
|
180
|
+
|
|
181
|
+
### Creating Navigation Menus
|
|
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
|
+
### Generating Sitemap Data
|
|
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
|
+
### Dynamic Translation Loading
|
|
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
|
+
## Configuration Integration
|
|
231
|
+
|
|
232
|
+
The Locale Mapper seamlessly integrates with your Intlayer configuration:
|
|
233
|
+
|
|
234
|
+
- **Locales**: Automatically uses `configuration.internationalization.locales`
|
|
235
|
+
- **Default Locale**: Uses `configuration.internationalization.defaultLocale`
|
|
236
|
+
- **URL Prefixing**: Respects `configuration.middleware.prefixDefault`
|
|
237
|
+
|
|
238
|
+
This ensures consistency across your application and reduces configuration duplication.
|
|
239
|
+
|
|
240
|
+
## Doc History
|
|
241
|
+
|
|
242
|
+
| Version | Date | Changes |
|
|
243
|
+
| ------- | ---------- | ------------------------------- |
|
|
244
|
+
| 5.7.2 | 2025-07-27 | Add locale mapper documentation |
|