cloudflare-next-intl-intl 0.1.1 → 0.2.0
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/README.md +221 -19
- package/dist/src/client/components/client_provider.d.ts +1 -1
- package/dist/src/client/components/client_provider.js +0 -5
- package/dist/src/client/components/client_provider_static.d.ts +1 -1
- package/dist/src/client/components/client_provider_static.js +0 -5
- package/dist/src/client/functions/get_cookie.js +2 -7
- package/dist/src/client/functions/set_cookie.js +2 -7
- package/dist/src/config/cookie_key.d.ts +0 -3
- package/dist/src/config/cookie_key.js +0 -3
- package/dist/src/config/create_intl_middleware.d.ts +1 -1
- package/dist/src/config/create_intl_middleware.js +4 -10
- package/dist/src/config/index.d.ts +1 -1
- package/dist/src/config/index.js +1 -1
- package/dist/src/config/init_config.js +0 -4
- package/dist/src/config/middleware.d.ts +1 -1
- package/dist/src/general/general_functions.js +2 -6
- package/dist/src/general/metadata.js +2 -6
- package/dist/src/general/report_intl_error.d.ts +1 -0
- package/dist/src/general/report_intl_error.js +15 -0
- package/dist/src/server/components/helper_script.d.ts +3 -3
- package/dist/src/server/components/helper_script.js +5 -289
- package/dist/src/server/components/server_provider.js +0 -2
- package/dist/src/server/components/server_provider_static.js +0 -2
- package/dist/src/server/functions/get_user_locale.js +2 -6
- package/dist/src/server/functions/server.js +2 -5
- package/dist/src/types/index.d.ts +1 -1
- package/dist/src/types/types.d.ts +2 -30
- package/llms.txt +0 -1
- package/package.json +2 -74
- package/dist/src/client/components/client_helper_script.d.ts +0 -1
- package/dist/src/client/components/client_helper_script.js +0 -15
- package/dist/src/error_handling/clear_client_cache.d.ts +0 -1
- package/dist/src/error_handling/clear_client_cache.js +0 -17
- package/dist/src/error_handling/create_server_error_action.d.ts +0 -3
- package/dist/src/error_handling/create_server_error_action.js +0 -6
- package/dist/src/error_handling/default_ignored_console_errors.d.ts +0 -1
- package/dist/src/error_handling/default_ignored_console_errors.js +0 -33
- package/dist/src/error_handling/format_error_message.d.ts +0 -2
- package/dist/src/error_handling/format_error_message.js +0 -16
- package/dist/src/error_handling/index.d.ts +0 -13
- package/dist/src/error_handling/index.js +0 -10
- package/dist/src/error_handling/install_console_error_override.d.ts +0 -3
- package/dist/src/error_handling/install_console_error_override.js +0 -39
- package/dist/src/error_handling/install_global_error_override.d.ts +0 -2
- package/dist/src/error_handling/install_global_error_override.js +0 -30
- package/dist/src/error_handling/is_stale_deploy_error.d.ts +0 -4
- package/dist/src/error_handling/is_stale_deploy_error.js +0 -51
- package/dist/src/error_handling/match_error_message.d.ts +0 -2
- package/dist/src/error_handling/match_error_message.js +0 -10
- package/dist/src/error_handling/merge_report_params.d.ts +0 -2
- package/dist/src/error_handling/merge_report_params.js +0 -9
- package/dist/src/error_handling/report_client_error.d.ts +0 -3
- package/dist/src/error_handling/report_client_error.js +0 -15
- package/dist/src/error_handling/report_client_error_action.d.ts +0 -2
- package/dist/src/error_handling/report_client_error_action.js +0 -6
- package/dist/src/error_handling/report_client_error_core.d.ts +0 -3
- package/dist/src/error_handling/report_client_error_core.js +0 -26
- package/dist/src/error_handling/report_error.d.ts +0 -9
- package/dist/src/error_handling/report_error.js +0 -73
- package/dist/src/error_handling/stringify_unknown.d.ts +0 -5
- package/dist/src/error_handling/stringify_unknown.js +0 -57
- package/dist/src/error_handling/use_stale_deploy_recovery.d.ts +0 -4
- package/dist/src/error_handling/use_stale_deploy_recovery.js +0 -141
- package/dist/src/error_handling/with_error_handling.d.ts +0 -9
- package/dist/src/error_handling/with_error_handling.js +0 -13
package/README.md
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
# cloudflare-next-intl-intl
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/cloudflare-next-intl-intl)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
|
|
6
|
+
Lightweight internationalization (i18n) for the **Next.js App Router**, built for
|
|
7
|
+
**Cloudflare Workers / Pages** (OpenNext and Vinext).
|
|
8
|
+
|
|
9
|
+
This is the core i18n engine of [`cloudflare-next-intl`](https://www.npmjs.com/package/cloudflare-next-intl),
|
|
10
|
+
published on its own with **zero runtime dependencies** and no auth, cookie-consent,
|
|
11
|
+
image or database code. Use it when you only need routing + translations; use
|
|
12
|
+
`cloudflare-next-intl` when you also want those extras auto-wired.
|
|
5
13
|
|
|
6
14
|
## Features
|
|
7
15
|
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
16
|
+
- Locale routing middleware (prefix redirects/rewrites, cookie + `Accept-Language` detection).
|
|
17
|
+
- Translations in Server Components (`getTranslations`) and Client Components (`useTranslations`).
|
|
18
|
+
- Ships only the message namespaces your client components need (`clientMessages`).
|
|
19
|
+
- Locale-aware `Link` / `LocaleLink`, `usePathname`, `getLocale`, `useLocale`.
|
|
20
|
+
- Cloudflare geo helpers: `getCountry`, `getTimezone`.
|
|
21
|
+
- SEO helpers: `hreflang` / canonical alternates via `alternatesLinks`.
|
|
22
|
+
- One subpath export per feature, so unused code is tree-shaken away.
|
|
13
23
|
|
|
14
24
|
## Installation
|
|
15
25
|
|
|
@@ -17,14 +27,16 @@ Extracted from `cloudflare-next-intl` with zero dependencies on auth, cookie con
|
|
|
17
27
|
npm install cloudflare-next-intl-intl
|
|
18
28
|
```
|
|
19
29
|
|
|
30
|
+
Peer dependencies: `next` (>= 12) and `react` (>= 16.8).
|
|
31
|
+
|
|
20
32
|
## Setup
|
|
21
33
|
|
|
22
|
-
|
|
23
|
-
|
|
34
|
+
The package finds your config through the `@intl-config` module alias and your
|
|
35
|
+
message files through `@locale-file`.
|
|
24
36
|
|
|
25
|
-
### 1. Create
|
|
37
|
+
### 1. Create the config file
|
|
26
38
|
|
|
27
|
-
```
|
|
39
|
+
```ts
|
|
28
40
|
// src/i18n/intl_config.ts
|
|
29
41
|
import { setIntlConfig } from "cloudflare-next-intl-intl/setIntlConfig";
|
|
30
42
|
|
|
@@ -34,12 +46,30 @@ export default setIntlConfig({
|
|
|
34
46
|
});
|
|
35
47
|
```
|
|
36
48
|
|
|
37
|
-
### 2.
|
|
49
|
+
### 2. Add message files
|
|
50
|
+
|
|
51
|
+
One JSON file per locale, named `<locale>.json`:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
src/i18n/messages/en.json
|
|
55
|
+
src/i18n/messages/de.json
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"Index": {
|
|
61
|
+
"title": "Hello world",
|
|
62
|
+
"items": ["One", "Two"]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 3. Add the aliases in `next.config`
|
|
38
68
|
|
|
39
|
-
|
|
40
|
-
|
|
69
|
+
Set them for both Turbopack and webpack. If one is missing, the build that uses
|
|
70
|
+
that bundler fails.
|
|
41
71
|
|
|
42
|
-
```
|
|
72
|
+
```ts
|
|
43
73
|
// next.config.ts
|
|
44
74
|
import type { NextConfig } from "next";
|
|
45
75
|
import path from "path";
|
|
@@ -64,15 +94,187 @@ const nextConfig: NextConfig = {
|
|
|
64
94
|
export default nextConfig;
|
|
65
95
|
```
|
|
66
96
|
|
|
67
|
-
|
|
97
|
+
If you deploy to Cloudflare Workers with Wrangler, add the same aliases to `wrangler.toml`:
|
|
68
98
|
|
|
69
99
|
```toml
|
|
70
|
-
# wrangler.toml
|
|
71
100
|
[alias]
|
|
72
101
|
"@intl-config" = "./src/i18n/intl_config.ts"
|
|
73
102
|
"@locale-file" = "./src/i18n/messages"
|
|
74
103
|
```
|
|
75
104
|
|
|
76
|
-
|
|
105
|
+
### 4. Add the middleware
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
// src/middleware.ts
|
|
109
|
+
import intlMiddleware from "cloudflare-next-intl-intl/middleware";
|
|
110
|
+
|
|
111
|
+
export const middleware = intlMiddleware;
|
|
112
|
+
|
|
113
|
+
export const config = {
|
|
114
|
+
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
|
|
115
|
+
};
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
To run your own logic (auth, feature flags, A/B tests) on each request, pass a `middlewareHandler`:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
export function middleware(request: NextRequest) {
|
|
122
|
+
return intlMiddleware(request, {
|
|
123
|
+
middlewareHandler: (locale, rewriteUrl, redirectUrl) => {
|
|
124
|
+
return null; // return a NextResponse to override, or null to keep the default
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
If you need the final response, for example to update session cookies, build
|
|
131
|
+
your own middleware with `createIntlMiddleware({ afterResponse })`.
|
|
132
|
+
|
|
133
|
+
### 5. Set up the root layout
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
// src/app/[locale]/layout.tsx
|
|
137
|
+
import { IntlProvider, IntlHelperScript, getLocaleStaticParams } from "cloudflare-next-intl-intl/server";
|
|
138
|
+
|
|
139
|
+
export const generateStaticParams = getLocaleStaticParams;
|
|
140
|
+
|
|
141
|
+
export default async function RootLayout({ children, params }) {
|
|
142
|
+
const { locale } = await params;
|
|
143
|
+
return (
|
|
144
|
+
<html lang={locale}>
|
|
145
|
+
<head>
|
|
146
|
+
<IntlHelperScript locale={locale} />
|
|
147
|
+
</head>
|
|
148
|
+
<body>
|
|
149
|
+
<IntlProvider language={locale}>{children}</IntlProvider>
|
|
150
|
+
</body>
|
|
151
|
+
</html>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
If you build with `output: "export"`, import `IntlProvider` from
|
|
157
|
+
`cloudflare-next-intl-intl/serverProviderStatic` instead.
|
|
158
|
+
|
|
159
|
+
## Usage
|
|
160
|
+
|
|
161
|
+
### Server Components
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
import { getTranslations, getLocale } from "cloudflare-next-intl-intl/server";
|
|
165
|
+
|
|
166
|
+
export default async function Page() {
|
|
167
|
+
const t = await getTranslations("Index");
|
|
168
|
+
const locale = await getLocale();
|
|
169
|
+
const items = t.raw("items") as string[];
|
|
170
|
+
|
|
171
|
+
return <h1>{t("title")} ({locale})</h1>;
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
`t(key)` always returns a string. For arrays or nested objects, use `t.raw(key)`.
|
|
176
|
+
|
|
177
|
+
### Client Components
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
"use client";
|
|
181
|
+
|
|
182
|
+
import { useTranslations, useLocale } from "cloudflare-next-intl-intl/use";
|
|
183
|
+
|
|
184
|
+
export function Title() {
|
|
185
|
+
const t = useTranslations("Index");
|
|
186
|
+
const locale = useLocale();
|
|
187
|
+
return <h1>{t("title")} ({locale})</h1>;
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`cloudflare-next-intl-intl/use` works in both Server and Client Components and
|
|
192
|
+
picks the right implementation automatically.
|
|
193
|
+
|
|
194
|
+
By default (`clientMessages: "auto"`), only the namespaces your client
|
|
195
|
+
components use are sent to the browser. You can set this in `setIntlConfig`:
|
|
196
|
+
|
|
197
|
+
- `clientMessages: false`: send no messages to the browser.
|
|
198
|
+
- `clientMessages: true`: send all messages.
|
|
199
|
+
- `clientMessages: ["Common", "Auth*"]`: send only the listed namespaces (prefix wildcards allowed).
|
|
200
|
+
|
|
201
|
+
### Links
|
|
202
|
+
|
|
203
|
+
```tsx
|
|
204
|
+
import Link from "cloudflare-next-intl-intl/Link";
|
|
205
|
+
import LocaleLink from "cloudflare-next-intl-intl/LocaleLink";
|
|
206
|
+
|
|
207
|
+
<Link href="/about">About</Link> // stays on the current locale: "/about" or "/de/about"
|
|
208
|
+
<LocaleLink href="/" locale="de">Deutsch</LocaleLink> // client-only, switches the locale
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`usePathname` (`cloudflare-next-intl-intl/usePathname`) returns the current path
|
|
212
|
+
without the locale prefix.
|
|
213
|
+
|
|
214
|
+
### Geo & timezone (Cloudflare)
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
import { getCountry, getTimezone } from "cloudflare-next-intl-intl/geo";
|
|
218
|
+
|
|
219
|
+
const country = await getCountry(); // "US", "DE", "UA", ...
|
|
220
|
+
const timezone = await getTimezone(undefined, "UTC");
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
These work in Server Components, Server Actions, Route Handlers, and middleware
|
|
224
|
+
(pass `request` there). The middleware forwards the Cloudflare
|
|
225
|
+
`x-cf-country` / `x-cf-timezone` headers, so these values are also available
|
|
226
|
+
further down the request. You can change the header names with
|
|
227
|
+
`generate.countryHeaderNames` / `generate.timezoneHeaderNames`.
|
|
228
|
+
|
|
229
|
+
### SEO metadata
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
import { alternatesLinks } from "cloudflare-next-intl-intl/metadata";
|
|
233
|
+
|
|
234
|
+
export async function generateMetadata({ params }) {
|
|
235
|
+
const { locale } = await params;
|
|
236
|
+
return {
|
|
237
|
+
alternates: alternatesLinks({ url: "https://example.com", locale, linkPart: "/about" }),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Cookies
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
import setCookie from "cloudflare-next-intl-intl/setCookie";
|
|
246
|
+
import getCookie from "cloudflare-next-intl-intl/getCookie";
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Public subpath exports
|
|
250
|
+
|
|
251
|
+
| Subpath | Contents |
|
|
252
|
+
| --- | --- |
|
|
253
|
+
| `.` | Everything below (prefer the specific subpaths for tree-shaking) |
|
|
254
|
+
| `./setIntlConfig` | `setIntlConfig` |
|
|
255
|
+
| `./middleware` | default `intlMiddleware`, `createIntlMiddleware` |
|
|
256
|
+
| `./server` | `getTranslations`, `getLocale`, `getMessage`, `IntlProvider`, `Link`, `IntlHelperScript`, `getLocaleStaticParams`, `getCountry`, `getTimezone` |
|
|
257
|
+
| `./client` | `LocaleLink`, `usePathname`, `setCookieClient`, `getCookieClient` |
|
|
258
|
+
| `./use` | `useTranslations`, `useLocale` (works in Server and Client Components) |
|
|
259
|
+
| `./serverProvider`, `./serverProviderStatic` | `IntlProvider` variants |
|
|
260
|
+
| `./Link`, `./LocaleLink`, `./usePathname`, `./IntlHelperScript` | Single components / hooks |
|
|
261
|
+
| `./geo`, `./getCountry`, `./getTimezone` | Geo helpers |
|
|
262
|
+
| `./metadata` | `alternatesLinks`, `languages` |
|
|
263
|
+
| `./localeStaticParams` | `getLocaleStaticParams` |
|
|
264
|
+
| `./setCookie`, `./getCookie`, `./setCookieClient`, `./getCookieClient` | Cookie helpers |
|
|
265
|
+
| `./types` | TypeScript types (`IntlRoutingConfig`, `RoutingConfig`, ...) |
|
|
266
|
+
|
|
267
|
+
`./internal/*` subpaths are only for wrapper packages such as
|
|
268
|
+
`cloudflare-next-intl` and `cloudflare-next-intl-auth`. Don't import them in
|
|
269
|
+
your app; they can change in any release.
|
|
270
|
+
|
|
271
|
+
## Related packages
|
|
272
|
+
|
|
273
|
+
- [`cloudflare-next-intl`](https://www.npmjs.com/package/cloudflare-next-intl): all-in-one package (i18n + auth + cookie consent + theme + errors + images + DB), auto-wired.
|
|
274
|
+
- [`cloudflare-next-intl-errors`](https://www.npmjs.com/package/cloudflare-next-intl-errors): Error reporting, overrides, and stale-deploy recovery.
|
|
275
|
+
- [`cloudflare-next-intl-theme`](https://www.npmjs.com/package/cloudflare-next-intl-theme): Theme switcher and dark mode cookies.
|
|
276
|
+
- [`cloudflare-next-intl-auth`](https://www.npmjs.com/package/cloudflare-next-intl-auth): Firebase Auth & App Check built on this package.
|
|
277
|
+
|
|
278
|
+
## License
|
|
77
279
|
|
|
78
|
-
|
|
280
|
+
MIT
|
|
@@ -2,16 +2,11 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { setLocaleCache, setMessageForLocaleCache } from "../../general/cache_variables.js";
|
|
4
4
|
import { useMemo } from "react";
|
|
5
|
-
import config from "../../config/intl_config.js";
|
|
6
|
-
import installConsoleErrorOverride from "../../error_handling/install_console_error_override.js";
|
|
7
|
-
import installGlobalErrorOverride from "../../error_handling/install_global_error_override.js";
|
|
8
5
|
import { LocaleContext } from "./locale_provider.js";
|
|
9
6
|
export { LocaleContext };
|
|
10
7
|
export default function LocationzationClientProvider({ language, messages, children, }) {
|
|
11
8
|
setLocaleCache(language);
|
|
12
9
|
setMessageForLocaleCache(language, messages);
|
|
13
|
-
installConsoleErrorOverride(config, true);
|
|
14
|
-
installGlobalErrorOverride(config);
|
|
15
10
|
const contextValue = useMemo(() => ({ language, messages }), [language, messages]);
|
|
16
11
|
return (_jsx(LocaleContext.Provider, { value: contextValue, children: children }));
|
|
17
12
|
}
|
|
@@ -2,16 +2,11 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { setLocaleCache, setMessageForLocaleCache } from "../../general/cache_variables.js";
|
|
4
4
|
import { useMemo } from "react";
|
|
5
|
-
import config from "../../config/intl_config.js";
|
|
6
|
-
import installConsoleErrorOverride from "../../error_handling/install_console_error_override.js";
|
|
7
|
-
import installGlobalErrorOverride from "../../error_handling/install_global_error_override.js";
|
|
8
5
|
import { LocaleContext } from "./locale_provider.js";
|
|
9
6
|
export { LocaleContext };
|
|
10
7
|
export default function LocationzationClientProvider({ language, messages, children, }) {
|
|
11
8
|
setLocaleCache(language);
|
|
12
9
|
setMessageForLocaleCache(language, messages);
|
|
13
|
-
installConsoleErrorOverride(config, true);
|
|
14
|
-
installGlobalErrorOverride(config);
|
|
15
10
|
const contextValue = useMemo(() => ({ language, messages }), [language, messages]);
|
|
16
11
|
return (_jsx(LocaleContext.Provider, { value: contextValue, children: children }));
|
|
17
12
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
2
|
+
import reportIntlError from "../../general/report_intl_error.js";
|
|
3
3
|
export default function getCookie(name) {
|
|
4
4
|
try {
|
|
5
5
|
const cookie = document.cookie;
|
|
@@ -20,12 +20,7 @@ export default function getCookie(name) {
|
|
|
20
20
|
return decodeURIComponent(value);
|
|
21
21
|
}
|
|
22
22
|
catch (e) {
|
|
23
|
-
|
|
24
|
-
error: e,
|
|
25
|
-
classOrMethodName: 'getCookie',
|
|
26
|
-
isClient: true,
|
|
27
|
-
params: { name },
|
|
28
|
-
});
|
|
23
|
+
reportIntlError(e, 'getCookie');
|
|
29
24
|
return null;
|
|
30
25
|
}
|
|
31
26
|
}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
2
|
+
import reportIntlError from "../../general/report_intl_error.js";
|
|
3
3
|
export default function setCookie({ name, value, maxAge }) {
|
|
4
4
|
try {
|
|
5
5
|
const cookieString = `${name}=${value}; path=/; max-age=${maxAge ?? 31536000}; SameSite=Lax;`;
|
|
6
6
|
document.cookie = cookieString;
|
|
7
7
|
}
|
|
8
8
|
catch (e) {
|
|
9
|
-
|
|
10
|
-
error: e,
|
|
11
|
-
classOrMethodName: 'setCookie',
|
|
12
|
-
isClient: true,
|
|
13
|
-
params: { name },
|
|
14
|
-
});
|
|
9
|
+
reportIntlError(e, 'setCookie');
|
|
15
10
|
}
|
|
16
11
|
}
|
|
17
12
|
;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
export declare const localeCookieName = "__user_locale_key__";
|
|
2
2
|
export declare const isBotCookieKey = "__is_bot_key__";
|
|
3
|
-
export declare const isDarkCookieKey = "__is_dark_key__";
|
|
4
|
-
export declare const cookieConsentCookieKey = "__cookie_consent_key__";
|
|
5
|
-
export declare const privacyPolicyDateCookieKey = "__privacy_policy_date_key__";
|
|
6
3
|
export declare const countryCookieKey = "__cf_country__";
|
|
7
4
|
export declare const timezoneCookieKey = "__cf_timezone__";
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
export const localeCookieName = '__user_locale_key__';
|
|
2
2
|
export const isBotCookieKey = '__is_bot_key__';
|
|
3
|
-
export const isDarkCookieKey = '__is_dark_key__';
|
|
4
|
-
export const cookieConsentCookieKey = '__cookie_consent_key__';
|
|
5
|
-
export const privacyPolicyDateCookieKey = '__privacy_policy_date_key__';
|
|
6
3
|
export const countryCookieKey = '__cf_country__';
|
|
7
4
|
export const timezoneCookieKey = '__cf_timezone__';
|
|
@@ -10,7 +10,7 @@ export type IntlMiddlewareHook = (response: NextResponse, ctx: IntlMiddlewareCon
|
|
|
10
10
|
export declare const localesSet: Set<string>;
|
|
11
11
|
export declare function createIntlMiddleware(middlewareOptions?: {
|
|
12
12
|
afterResponse?: IntlMiddlewareHook;
|
|
13
|
-
}): (request:
|
|
13
|
+
}): (request: any, options?: {
|
|
14
14
|
middlewareHandler?: MiddlewareCustomHandler;
|
|
15
15
|
runHandlerOnRedirect?: boolean;
|
|
16
16
|
}) => Promise<NextResponse>;
|
|
@@ -3,7 +3,7 @@ import { languageDetecotr } from '../server/functions/get_user_locale.js';
|
|
|
3
3
|
import config from './intl_config.js';
|
|
4
4
|
import { countryCookieKey, isBotCookieKey, localeCookieName, timezoneCookieKey } from './cookie_key.js';
|
|
5
5
|
import { cache } from 'react';
|
|
6
|
-
import
|
|
6
|
+
import reportIntlError from '../general/report_intl_error.js';
|
|
7
7
|
import { defaultCountryHeaderNames, defaultTimezoneHeaderNames } from '../server/functions/geo.js';
|
|
8
8
|
const sameSite = false;
|
|
9
9
|
const defaultCookieOption = {
|
|
@@ -69,14 +69,11 @@ export function createIntlMiddleware(middlewareOptions) {
|
|
|
69
69
|
}
|
|
70
70
|
const effectiveLocaleForRequest = urlLocale ?? initialChosenLocale;
|
|
71
71
|
const cf = request.cf;
|
|
72
|
-
const
|
|
73
|
-
const countryHeaderNames = cookieConsentConfig?.countryHeaderNames
|
|
74
|
-
?? config.generate?.countryHeaderNames
|
|
72
|
+
const countryHeaderNames = config.generate?.countryHeaderNames
|
|
75
73
|
?? defaultCountryHeaderNames;
|
|
76
74
|
const timezoneHeaderNames = config.generate?.timezoneHeaderNames
|
|
77
75
|
?? defaultTimezoneHeaderNames;
|
|
78
|
-
const countryCookieName =
|
|
79
|
-
?? config.generate?.countryCookieName
|
|
76
|
+
const countryCookieName = config.generate?.countryCookieName
|
|
80
77
|
?? countryCookieKey;
|
|
81
78
|
const timezoneCookieName = config.generate?.timezoneCookieName
|
|
82
79
|
?? timezoneCookieKey;
|
|
@@ -168,10 +165,7 @@ export function createIntlMiddleware(middlewareOptions) {
|
|
|
168
165
|
return response;
|
|
169
166
|
}
|
|
170
167
|
catch (e) {
|
|
171
|
-
|
|
172
|
-
error: e,
|
|
173
|
-
classOrMethodName: 'intlMiddleware',
|
|
174
|
-
});
|
|
168
|
+
reportIntlError(e, 'intlMiddleware');
|
|
175
169
|
return NextResponse.next({
|
|
176
170
|
request,
|
|
177
171
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { isBotCookieKey, localeCookieName,
|
|
1
|
+
export { isBotCookieKey, localeCookieName, countryCookieKey, timezoneCookieKey } from './cookie_key.js';
|
|
2
2
|
export { default as intlMiddleware } from './middleware.js';
|
|
3
3
|
export { setIntlConfig } from './init_config.js';
|
|
4
4
|
export { default as generateIntlSitemap } from './intl_sitemap.js';
|
package/dist/src/config/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { isBotCookieKey, localeCookieName,
|
|
1
|
+
export { isBotCookieKey, localeCookieName, countryCookieKey, timezoneCookieKey } from './cookie_key.js';
|
|
2
2
|
export { default as intlMiddleware } from './middleware.js';
|
|
3
3
|
export { setIntlConfig } from './init_config.js';
|
|
4
4
|
export { default as generateIntlSitemap } from './intl_sitemap.js';
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { setStaleDeployPatterns } from '../error_handling/is_stale_deploy_error.js';
|
|
2
1
|
export function setIntlConfig(config) {
|
|
3
|
-
if (config.errorHandling?.staleDeployPatterns) {
|
|
4
|
-
setStaleDeployPatterns(config.errorHandling.staleDeployPatterns);
|
|
5
|
-
}
|
|
6
2
|
return config;
|
|
7
3
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createIntlMiddleware, localesSet, type IntlMiddlewareContext, type IntlMiddlewareHook } from './create_intl_middleware.js';
|
|
2
2
|
export { createIntlMiddleware, localesSet, type IntlMiddlewareContext, type IntlMiddlewareHook, };
|
|
3
|
-
declare const intlMiddleware: (request:
|
|
3
|
+
declare const intlMiddleware: (request: any, options?: {
|
|
4
4
|
middlewareHandler?: import("../types/types.js").MiddlewareCustomHandler;
|
|
5
5
|
runHandlerOnRedirect?: boolean;
|
|
6
6
|
}) => Promise<import("next/server.js").NextResponse>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setTranslationCache } from "./cache_variables.js";
|
|
2
|
-
import
|
|
2
|
+
import reportIntlError from "./report_intl_error.js";
|
|
3
3
|
const errorAndReturnFallback = (message, cacheKey, locale, namespace, key) => {
|
|
4
4
|
const parts = [
|
|
5
5
|
message,
|
|
@@ -7,11 +7,7 @@ const errorAndReturnFallback = (message, cacheKey, locale, namespace, key) => {
|
|
|
7
7
|
key ? `Key: "${key}"` : '',
|
|
8
8
|
`Locale: "${locale}"`,
|
|
9
9
|
].filter(Boolean);
|
|
10
|
-
|
|
11
|
-
error: parts.join(' | '),
|
|
12
|
-
classOrMethodName: 'getTranslationsImpl',
|
|
13
|
-
params: { locale, namespace, key },
|
|
14
|
-
});
|
|
10
|
+
reportIntlError(parts.join(' | '), 'getTranslationsImpl');
|
|
15
11
|
const fallbackFn = (k) => k;
|
|
16
12
|
fallbackFn.raw = (k) => k;
|
|
17
13
|
setTranslationCache(cacheKey, fallbackFn);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cache } from "react";
|
|
2
2
|
import config from "../config/intl_config.js";
|
|
3
|
-
import
|
|
3
|
+
import reportIntlError from "./report_intl_error.js";
|
|
4
4
|
export function iAlternatesLinks({ locale, url, canonical, linkPart }) {
|
|
5
5
|
try {
|
|
6
6
|
const linkPartValue = linkPart == '/' ? undefined : linkPart;
|
|
@@ -10,11 +10,7 @@ export function iAlternatesLinks({ locale, url, canonical, linkPart }) {
|
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
catch (e) {
|
|
13
|
-
|
|
14
|
-
error: e,
|
|
15
|
-
classOrMethodName: 'alternatesLinks',
|
|
16
|
-
params: { url, linkPart },
|
|
17
|
-
});
|
|
13
|
+
reportIntlError(e, 'alternatesLinks');
|
|
18
14
|
return undefined;
|
|
19
15
|
}
|
|
20
16
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function reportIntlError(error: unknown, source: string): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import config from '../config/intl_config.js';
|
|
2
|
+
export default function reportIntlError(error, source) {
|
|
3
|
+
if (config.onError) {
|
|
4
|
+
try {
|
|
5
|
+
const res = config.onError(error, source);
|
|
6
|
+
if (res && typeof res.catch === 'function') {
|
|
7
|
+
res.catch(() => { });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
}
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
console.error('[cloudflare-next-intl-intl]', source, error);
|
|
15
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export default function HelperScript({ locale, prefetchOrigins, preconnectOrigins, }: {
|
|
1
|
+
export default function HelperScript({ locale, prefetchOrigins, preconnectOrigins, children, }: {
|
|
3
2
|
locale?: string;
|
|
4
3
|
prefetchOrigins?: string[];
|
|
5
4
|
preconnectOrigins?: string[];
|
|
6
|
-
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
}): import("react").JSX.Element;
|