@intlayer/docs 7.1.0-canary.0 → 7.1.0-canary.1
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/docs/en/packages/intlayer/getPrefix.md +16 -16
- package/package.json +11 -11
|
@@ -28,13 +28,13 @@ history:
|
|
|
28
28
|
|
|
29
29
|
## Description
|
|
30
30
|
|
|
31
|
-
The `getPrefix` function determines the URL prefix for a given locale based on the routing mode configuration. It compares the locale with the default locale and returns the appropriate prefix string (e.g., `'en/'`) or an empty string.
|
|
31
|
+
The `getPrefix` function determines the URL prefix for a given locale based on the routing mode configuration. It compares the locale with the default locale and returns the appropriate prefix string (e.g., `'en/'`, `'fr/'`) or an empty string.
|
|
32
32
|
|
|
33
33
|
**Key Features:**
|
|
34
34
|
|
|
35
|
-
- Takes a locale as the first parameter (
|
|
35
|
+
- Takes a locale as the first parameter (required)
|
|
36
36
|
- Optional `options` object with `defaultLocale`, `mode`, and `addSlash`
|
|
37
|
-
- Returns a prefix string that can be used for URL construction
|
|
37
|
+
- Returns a prefix string based on the provided locale that can be used for URL construction
|
|
38
38
|
- Supports all routing modes: `prefix-no-default`, `prefix-all`, `no-prefix`, and `search-params`
|
|
39
39
|
- Lightweight utility for determining when to add locale prefixes
|
|
40
40
|
|
|
@@ -44,7 +44,7 @@ The `getPrefix` function determines the URL prefix for a given locale based on t
|
|
|
44
44
|
|
|
45
45
|
```typescript
|
|
46
46
|
getPrefix(
|
|
47
|
-
locale
|
|
47
|
+
locale: Locales, // Required
|
|
48
48
|
options?: { // Optional
|
|
49
49
|
defaultLocale?: Locales;
|
|
50
50
|
mode?: 'prefix-no-default' | 'prefix-all' | 'no-prefix' | 'search-params';
|
|
@@ -57,13 +57,10 @@ getPrefix(
|
|
|
57
57
|
|
|
58
58
|
## Parameters
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- `locale?: Locales`
|
|
63
|
-
- **Description**: The locale to check for prefix. If not provided, uses the configured default locale.
|
|
60
|
+
- `locale: Locales`
|
|
61
|
+
- **Description**: The locale to generate the prefix for. If the value is falsy (undefined, null, empty string), the function returns an empty string.
|
|
64
62
|
- **Type**: `Locales`
|
|
65
|
-
- **Required**:
|
|
66
|
-
- **Default**: [`Project Configuration`](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/configuration.md#middleware)
|
|
63
|
+
- **Required**: Yes
|
|
67
64
|
|
|
68
65
|
- `options?: object`
|
|
69
66
|
- **Description**: Configuration object for prefix determination.
|
|
@@ -93,7 +90,7 @@ getPrefix(
|
|
|
93
90
|
### Returns
|
|
94
91
|
|
|
95
92
|
- **Type**: `string`
|
|
96
|
-
- **Description**: The prefix string for the
|
|
93
|
+
- **Description**: The prefix string for the given locale (e.g., `'en/'`, `'fr/'`) or an empty string depending on the routing mode and whether the locale matches the default.
|
|
97
94
|
|
|
98
95
|
---
|
|
99
96
|
|
|
@@ -116,7 +113,7 @@ getPrefix(Locales.FRENCH, {
|
|
|
116
113
|
defaultLocale: Locales.ENGLISH,
|
|
117
114
|
mode: "prefix-no-default",
|
|
118
115
|
});
|
|
119
|
-
// Returns: '
|
|
116
|
+
// Returns: 'fr/'
|
|
120
117
|
```
|
|
121
118
|
|
|
122
119
|
```javascript codeFormat="esm"
|
|
@@ -155,7 +152,7 @@ getPrefix(Locales.FRENCH, {
|
|
|
155
152
|
mode: "prefix-no-default",
|
|
156
153
|
defaultLocale: Locales.ENGLISH,
|
|
157
154
|
});
|
|
158
|
-
// Returns: "
|
|
155
|
+
// Returns: "fr/"
|
|
159
156
|
|
|
160
157
|
// no-prefix & search-params: Never returns prefix
|
|
161
158
|
getPrefix(Locales.ENGLISH, { mode: "no-prefix" }); // Returns: ""
|
|
@@ -173,9 +170,12 @@ import { getPrefix, Locales } from "intlayer";
|
|
|
173
170
|
|
|
174
171
|
// Build URLs with the appropriate prefix for a specific locale
|
|
175
172
|
const locale = Locales.FRENCH;
|
|
176
|
-
const prefix = getPrefix(locale, {
|
|
173
|
+
const prefix = getPrefix(locale, {
|
|
174
|
+
defaultLocale: Locales.ENGLISH,
|
|
175
|
+
mode: "prefix-no-default",
|
|
176
|
+
});
|
|
177
177
|
const url = `/${prefix}about`.replace(/\/+/g, "/");
|
|
178
|
-
// Result: "/
|
|
178
|
+
// Result: "/fr/about" (because French differs from default English)
|
|
179
179
|
```
|
|
180
180
|
|
|
181
181
|
---
|
|
@@ -191,7 +191,7 @@ const url = `/${prefix}about`.replace(/\/+/g, "/");
|
|
|
191
191
|
|
|
192
192
|
```typescript
|
|
193
193
|
function getPrefix(
|
|
194
|
-
locale
|
|
194
|
+
locale: Locales,
|
|
195
195
|
options?: {
|
|
196
196
|
defaultLocale?: Locales;
|
|
197
197
|
mode?: "prefix-no-default" | "prefix-all" | "no-prefix" | "search-params";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/docs",
|
|
3
|
-
"version": "7.1.0-canary.
|
|
3
|
+
"version": "7.1.0-canary.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Intlayer documentation",
|
|
6
6
|
"keywords": [
|
|
@@ -72,13 +72,13 @@
|
|
|
72
72
|
"watch": "webpack --config ./webpack.config.ts --watch"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@intlayer/config": "7.1.0-canary.
|
|
76
|
-
"@intlayer/core": "7.1.0-canary.
|
|
77
|
-
"@intlayer/types": "7.1.0-canary.
|
|
75
|
+
"@intlayer/config": "7.1.0-canary.1",
|
|
76
|
+
"@intlayer/core": "7.1.0-canary.1",
|
|
77
|
+
"@intlayer/types": "7.1.0-canary.1"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@intlayer/api": "7.1.0-canary.
|
|
81
|
-
"@intlayer/cli": "7.1.0-canary.
|
|
80
|
+
"@intlayer/api": "7.1.0-canary.1",
|
|
81
|
+
"@intlayer/cli": "7.1.0-canary.1",
|
|
82
82
|
"@types/node": "24.10.1",
|
|
83
83
|
"@utils/ts-config": "1.0.4",
|
|
84
84
|
"@utils/ts-config-types": "1.0.4",
|
|
@@ -91,11 +91,11 @@
|
|
|
91
91
|
"vitest": "4.0.8"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
|
-
"@intlayer/api": "7.1.0-canary.
|
|
95
|
-
"@intlayer/cli": "7.1.0-canary.
|
|
96
|
-
"@intlayer/config": "7.1.0-canary.
|
|
97
|
-
"@intlayer/core": "7.1.0-canary.
|
|
98
|
-
"@intlayer/types": "7.1.0-canary.
|
|
94
|
+
"@intlayer/api": "7.1.0-canary.1",
|
|
95
|
+
"@intlayer/cli": "7.1.0-canary.1",
|
|
96
|
+
"@intlayer/config": "7.1.0-canary.1",
|
|
97
|
+
"@intlayer/core": "7.1.0-canary.1",
|
|
98
|
+
"@intlayer/types": "7.1.0-canary.1"
|
|
99
99
|
},
|
|
100
100
|
"engines": {
|
|
101
101
|
"node": ">=14.18"
|