next-intl 2.15.0-beta.5 → 2.15.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/dist/client/index.d.ts +0 -6
- package/dist/middleware/NextIntlMiddlewareConfig.d.ts +0 -18
- package/dist/middleware/middleware.d.ts +1 -1
- package/dist/next-intl.cjs.development.js +1 -218
- package/dist/next-intl.cjs.development.js.map +1 -1
- package/dist/next-intl.cjs.production.min.js +1 -1
- package/dist/next-intl.cjs.production.min.js.map +1 -1
- package/dist/next-intl.esm.js +1 -4
- package/dist/next-intl.esm.js.map +1 -1
- package/dist/react-client/index.d.ts +0 -5
- package/dist/react-server/index.d.ts +9 -11
- package/dist/server/index.d.ts +1 -9
- package/dist/shared/constants.d.ts +0 -1
- package/dist/src/client/index.d.ts +0 -6
- package/dist/src/client/index.js +0 -6
- package/dist/src/client/index.js.map +1 -1
- package/dist/src/middleware/NextIntlMiddlewareConfig.d.ts +0 -18
- package/dist/src/middleware/middleware.d.ts +1 -1
- package/dist/src/middleware/middleware.js +1 -42
- package/dist/src/middleware/middleware.js.map +1 -1
- package/dist/src/react-client/index.d.ts +0 -5
- package/dist/src/react-client/index.js +0 -5
- package/dist/src/react-client/index.js.map +1 -1
- package/dist/src/react-server/index.d.ts +9 -11
- package/dist/src/react-server/index.js +16 -14
- package/dist/src/react-server/index.js.map +1 -1
- package/dist/src/server/index.d.ts +1 -9
- package/dist/src/server/index.js +3 -11
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/shared/constants.d.ts +0 -1
- package/dist/src/shared/constants.js +0 -2
- package/dist/src/shared/constants.js.map +1 -1
- package/package.json +19 -31
- package/src/client/index.tsx +0 -9
- package/src/middleware/NextIntlMiddlewareConfig.tsx +0 -21
- package/src/middleware/middleware.tsx +1 -54
- package/src/react-client/index.tsx +0 -8
- package/src/react-server/index.tsx +17 -16
- package/src/server/index.tsx +3 -13
- package/src/shared/constants.tsx +0 -3
- package/config.js +0 -3
- package/dist/client/next-intl.esm.js +0 -45
- package/dist/client/next-intl.esm.js.map +0 -1
- package/dist/client/next-intl.esm2.js +0 -18
- package/dist/client/next-intl.esm2.js.map +0 -1
- package/dist/link/next-intl.esm.js +0 -39
- package/dist/link/next-intl.esm.js.map +0 -1
- package/dist/link/react-server/Link.d.ts +0 -7
- package/dist/link/react-server/index.d.ts +0 -1
- package/dist/react-client/Link.d.ts +0 -4
- package/dist/react-client/next-intl.esm.js +0 -21
- package/dist/react-client/next-intl.esm.js.map +0 -1
- package/dist/react-client/next-intl.esm2.js +0 -18
- package/dist/react-client/next-intl.esm2.js.map +0 -1
- package/dist/react-client/next-intl.esm3.js +0 -15
- package/dist/react-client/next-intl.esm3.js.map +0 -1
- package/dist/react-client/useLocalizedRouter.d.ts +0 -8
- package/dist/react-server/Link.d.ts +0 -4
- package/dist/react-server/useFormatter.d.ts +0 -2
- package/dist/react-server/useHook.d.ts +0 -1
- package/dist/react-server/useIntl.d.ts +0 -5
- package/dist/react-server/useLocale.d.ts +0 -2
- package/dist/react-server/useNow.d.ts +0 -2
- package/dist/react-server/useTimeZone.d.ts +0 -2
- package/dist/react-server/useTranslations.d.ts +0 -2
- package/dist/server/createRequestConfig.d.ts +0 -4
- package/dist/server/getConfig.d.ts +0 -23
- package/dist/server/getFormatter.d.ts +0 -6
- package/dist/server/getIntl.d.ts +0 -7
- package/dist/server/getLocale.d.ts +0 -2
- package/dist/server/getNow.d.ts +0 -2
- package/dist/server/getRequestConfig.d.ts +0 -10
- package/dist/server/getTimeZone.d.ts +0 -2
- package/dist/server/getTranslations.d.ts +0 -38
- package/dist/server/react-client/index.d.ts +0 -8
- package/dist/server/react-client/redirect.d.ts +0 -1
- package/dist/server/redirect.d.ts +0 -1
- package/dist/shared/next-intl.esm2.js +0 -55
- package/dist/shared/next-intl.esm2.js.map +0 -1
- package/dist/shared/next-intl.esm3.js +0 -49
- package/dist/shared/next-intl.esm3.js.map +0 -1
- package/dist/shared/next-intl.esm4.js +0 -6
- package/dist/shared/next-intl.esm4.js.map +0 -1
- package/dist/shared/redirect.d.ts +0 -1
- package/dist/src/link/react-server/Link.d.ts +0 -7
- package/dist/src/link/react-server/Link.js +0 -8
- package/dist/src/link/react-server/Link.js.map +0 -1
- package/dist/src/link/react-server/index.d.ts +0 -1
- package/dist/src/link/react-server/index.js +0 -2
- package/dist/src/link/react-server/index.js.map +0 -1
- package/dist/src/react-client/Link.d.ts +0 -4
- package/dist/src/react-client/Link.js +0 -19
- package/dist/src/react-client/Link.js.map +0 -1
- package/dist/src/react-client/useLocalizedRouter.d.ts +0 -8
- package/dist/src/react-client/useLocalizedRouter.js +0 -12
- package/dist/src/react-client/useLocalizedRouter.js.map +0 -1
- package/dist/src/react-server/Link.d.ts +0 -4
- package/dist/src/react-server/Link.js +0 -19
- package/dist/src/react-server/Link.js.map +0 -1
- package/dist/src/react-server/useFormatter.d.ts +0 -2
- package/dist/src/react-server/useFormatter.js +0 -8
- package/dist/src/react-server/useFormatter.js.map +0 -1
- package/dist/src/react-server/useHook.d.ts +0 -1
- package/dist/src/react-server/useHook.js +0 -28
- package/dist/src/react-server/useHook.js.map +0 -1
- package/dist/src/react-server/useIntl.d.ts +0 -5
- package/dist/src/react-server/useIntl.js +0 -11
- package/dist/src/react-server/useIntl.js.map +0 -1
- package/dist/src/react-server/useLocale.d.ts +0 -2
- package/dist/src/react-server/useLocale.js +0 -7
- package/dist/src/react-server/useLocale.js.map +0 -1
- package/dist/src/react-server/useNow.d.ts +0 -2
- package/dist/src/react-server/useNow.js +0 -9
- package/dist/src/react-server/useNow.js.map +0 -1
- package/dist/src/react-server/useTimeZone.d.ts +0 -2
- package/dist/src/react-server/useTimeZone.js +0 -8
- package/dist/src/react-server/useTimeZone.js.map +0 -1
- package/dist/src/react-server/useTranslations.d.ts +0 -2
- package/dist/src/react-server/useTranslations.js +0 -9
- package/dist/src/react-server/useTranslations.js.map +0 -1
- package/dist/src/server/createRequestConfig.d.ts +0 -4
- package/dist/src/server/createRequestConfig.js +0 -5
- package/dist/src/server/createRequestConfig.js.map +0 -1
- package/dist/src/server/getConfig.d.ts +0 -23
- package/dist/src/server/getConfig.js +0 -23
- package/dist/src/server/getConfig.js.map +0 -1
- package/dist/src/server/getFormatter.d.ts +0 -6
- package/dist/src/server/getFormatter.js +0 -9
- package/dist/src/server/getFormatter.js.map +0 -1
- package/dist/src/server/getIntl.d.ts +0 -7
- package/dist/src/server/getIntl.js +0 -15
- package/dist/src/server/getIntl.js.map +0 -1
- package/dist/src/server/getLocale.d.ts +0 -2
- package/dist/src/server/getLocale.js +0 -33
- package/dist/src/server/getLocale.js.map +0 -1
- package/dist/src/server/getNow.d.ts +0 -2
- package/dist/src/server/getNow.js +0 -8
- package/dist/src/server/getNow.js.map +0 -1
- package/dist/src/server/getRequestConfig.d.ts +0 -10
- package/dist/src/server/getRequestConfig.js +0 -7
- package/dist/src/server/getRequestConfig.js.map +0 -1
- package/dist/src/server/getTimeZone.d.ts +0 -2
- package/dist/src/server/getTimeZone.js +0 -8
- package/dist/src/server/getTimeZone.js.map +0 -1
- package/dist/src/server/getTranslations.d.ts +0 -38
- package/dist/src/server/getTranslations.js +0 -23
- package/dist/src/server/getTranslations.js.map +0 -1
- package/dist/src/server/react-client/index.d.ts +0 -8
- package/dist/src/server/react-client/index.js +0 -15
- package/dist/src/server/react-client/index.js.map +0 -1
- package/dist/src/server/react-client/redirect.d.ts +0 -1
- package/dist/src/server/react-client/redirect.js +0 -8
- package/dist/src/server/react-client/redirect.js.map +0 -1
- package/dist/src/server/redirect.d.ts +0 -1
- package/dist/src/server/redirect.js +0 -7
- package/dist/src/server/redirect.js.map +0 -1
- package/dist/src/shared/redirect.d.ts +0 -1
- package/dist/src/shared/redirect.js +0 -7
- package/dist/src/shared/redirect.js.map +0 -1
- package/plugin.d.ts +0 -3
- package/plugin.js +0 -65
- package/src/link/react-server/Link.tsx +0 -12
- package/src/link/react-server/index.tsx +0 -1
- package/src/react-client/Link.tsx +0 -24
- package/src/react-client/useLocalizedRouter.tsx +0 -17
- package/src/react-server/Link.tsx +0 -24
- package/src/react-server/useFormatter.tsx +0 -10
- package/src/react-server/useHook.tsx +0 -34
- package/src/react-server/useIntl.tsx +0 -15
- package/src/react-server/useLocale.tsx +0 -9
- package/src/react-server/useNow.tsx +0 -15
- package/src/react-server/useTimeZone.tsx +0 -10
- package/src/react-server/useTranslations.tsx +0 -13
- package/src/server/createRequestConfig.tsx +0 -9
- package/src/server/getConfig.tsx +0 -27
- package/src/server/getFormatter.tsx +0 -10
- package/src/server/getIntl.tsx +0 -20
- package/src/server/getLocale.tsx +0 -40
- package/src/server/getNow.tsx +0 -9
- package/src/server/getRequestConfig.tsx +0 -18
- package/src/server/getTimeZone.tsx +0 -9
- package/src/server/getTranslations.tsx +0 -102
- package/src/server/react-client/index.tsx +0 -16
- package/src/server/react-client/redirect.tsx +0 -8
- package/src/server/redirect.tsx +0 -7
- package/src/shared/redirect.tsx +0 -7
- package/withNextIntl.d.ts +0 -5
- package/withNextIntl.js +0 -13
package/dist/client/index.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Client-only APIs available via `next-intl/client`.
|
|
3
3
|
*/
|
|
4
|
-
import usePathname from './usePathname';
|
|
5
|
-
import useRouter from './useRouter';
|
|
6
4
|
export { default as useRouter } from './useRouter';
|
|
7
5
|
export { default as usePathname } from './usePathname';
|
|
8
|
-
/** @deprecated Is called `usePathname` now. */
|
|
9
|
-
export declare const useUnlocalizedPathname: typeof usePathname;
|
|
10
|
-
/** @deprecated Is called `useRouter` now. */
|
|
11
|
-
export declare const useLocalizedRouter: typeof useRouter;
|
|
12
6
|
export { default as NextIntlClientProvider } from './NextIntlClientProvider';
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
type RoutingConfigPrefix = {
|
|
2
|
-
type: 'prefix';
|
|
3
|
-
/** The default locale can be used without a prefix (e.g. `/about`). If you prefer to have a prefix for the default locale as well (e.g. `/en/about`), you can switch this option to `always`.
|
|
4
|
-
*/
|
|
5
|
-
prefix?: 'as-needed' | 'always';
|
|
6
|
-
};
|
|
7
|
-
type RoutingConfigDomain = {
|
|
8
|
-
type: 'domain';
|
|
9
|
-
/** Provide a list of mappings between domains and locales. Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
|
|
10
|
-
domains: Array<{
|
|
11
|
-
domain: string;
|
|
12
|
-
locale: string;
|
|
13
|
-
}>;
|
|
14
|
-
};
|
|
15
1
|
type LocalePrefix = 'as-needed' | 'always';
|
|
16
2
|
type RoutingBaseConfig = {
|
|
17
3
|
/** A list of all locales that are supported. */
|
|
@@ -25,8 +11,6 @@ export type DomainConfig = Omit<RoutingBaseConfig, 'locales' | 'localePrefix'> &
|
|
|
25
11
|
/** The domain name (e.g. "example.com", "www.example.com" or "fr.example.com"). Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
|
|
26
12
|
domain: string;
|
|
27
13
|
locales?: RoutingBaseConfig['locales'];
|
|
28
|
-
/** @deprecated Use `defaultLocale` instead. */
|
|
29
|
-
locale?: string;
|
|
30
14
|
};
|
|
31
15
|
type MiddlewareConfig = RoutingBaseConfig & {
|
|
32
16
|
/** Can be used to change the locale handling per domain. */
|
|
@@ -35,8 +19,6 @@ type MiddlewareConfig = RoutingBaseConfig & {
|
|
|
35
19
|
localeDetection?: boolean;
|
|
36
20
|
/** Sets the `Link` response header to notify search engines about content in other languages (defaults to `true`). See https://developers.google.com/search/docs/specialty/international/localized-versions#http */
|
|
37
21
|
alternateLinks?: boolean;
|
|
38
|
-
/** @deprecated Deprecated in favor of `localePrefix` and `domains`. */
|
|
39
|
-
routing?: RoutingConfigPrefix | RoutingConfigDomain;
|
|
40
22
|
};
|
|
41
23
|
export type MiddlewareConfigWithDefaults = MiddlewareConfig & {
|
|
42
24
|
alternateLinks: boolean;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import MiddlewareConfig from './NextIntlMiddlewareConfig';
|
|
3
|
-
export default function createMiddleware(config: MiddlewareConfig): (request: NextRequest) => NextResponse
|
|
3
|
+
export default function createMiddleware(config: MiddlewareConfig): (request: NextRequest) => NextResponse<unknown>;
|
|
@@ -2,16 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var React = require('react');
|
|
6
|
-
var navigation = require('next/navigation');
|
|
7
5
|
var useIntl = require('use-intl');
|
|
8
|
-
var NextLink = require('next/link');
|
|
9
6
|
var router = require('next/router');
|
|
7
|
+
var React = require('react');
|
|
10
8
|
|
|
11
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
10
|
|
|
13
11
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
14
|
-
var NextLink__default = /*#__PURE__*/_interopDefaultLegacy(NextLink);
|
|
15
12
|
|
|
16
13
|
function _extends() {
|
|
17
14
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
@@ -40,157 +37,6 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
40
37
|
return target;
|
|
41
38
|
}
|
|
42
39
|
|
|
43
|
-
// Reuse the legacy cookie name
|
|
44
|
-
// In a URL like "/en-US/about", the locale segment is "en-US"
|
|
45
|
-
var LOCALE_SEGMENT_NAME = 'locale';
|
|
46
|
-
|
|
47
|
-
function useClientLocale() {
|
|
48
|
-
var locale;
|
|
49
|
-
var params = navigation.useParams();
|
|
50
|
-
if (params[LOCALE_SEGMENT_NAME]) {
|
|
51
|
-
locale = params[LOCALE_SEGMENT_NAME];
|
|
52
|
-
} else {
|
|
53
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine
|
|
54
|
-
locale = useIntl.useLocale();
|
|
55
|
-
}
|
|
56
|
-
return locale;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function isRelativeHref(href) {
|
|
60
|
-
var pathname = typeof href === 'object' ? href.pathname : href;
|
|
61
|
-
return pathname != null && !pathname.startsWith('/');
|
|
62
|
-
}
|
|
63
|
-
function isLocalHref(href) {
|
|
64
|
-
if (typeof href === 'object') {
|
|
65
|
-
return href.host == null && href.hostname == null;
|
|
66
|
-
} else {
|
|
67
|
-
var hasProtocol = /^[a-z]+:/i.test(href);
|
|
68
|
-
return !hasProtocol;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function localizeHref(href, locale, defaultLocale, pathname) {
|
|
72
|
-
if (defaultLocale === void 0) {
|
|
73
|
-
defaultLocale = locale;
|
|
74
|
-
}
|
|
75
|
-
if (!isLocalHref(href) || isRelativeHref(href)) {
|
|
76
|
-
return href;
|
|
77
|
-
}
|
|
78
|
-
var isSwitchingLocale = locale !== defaultLocale;
|
|
79
|
-
var isPathnamePrefixed = locale == null || hasPathnamePrefixed(locale, pathname);
|
|
80
|
-
var shouldPrefix = isPathnamePrefixed || isSwitchingLocale;
|
|
81
|
-
if (shouldPrefix && locale != null) {
|
|
82
|
-
return prefixHref(href, locale);
|
|
83
|
-
}
|
|
84
|
-
return href;
|
|
85
|
-
}
|
|
86
|
-
function prefixHref(href, locale) {
|
|
87
|
-
var prefixedHref;
|
|
88
|
-
if (typeof href === 'string') {
|
|
89
|
-
prefixedHref = localizePathname(locale, href);
|
|
90
|
-
} else {
|
|
91
|
-
prefixedHref = _extends({}, href);
|
|
92
|
-
if (href.pathname) {
|
|
93
|
-
prefixedHref.pathname = localizePathname(locale, href.pathname);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return prefixedHref;
|
|
97
|
-
}
|
|
98
|
-
function localizePathname(locale, pathname) {
|
|
99
|
-
var localizedHref = '/' + locale;
|
|
100
|
-
if (pathname !== '/') {
|
|
101
|
-
localizedHref += pathname;
|
|
102
|
-
}
|
|
103
|
-
return localizedHref;
|
|
104
|
-
}
|
|
105
|
-
function hasPathnamePrefixed(locale, pathname) {
|
|
106
|
-
var prefix = "/" + locale;
|
|
107
|
-
return pathname === prefix || pathname.startsWith(prefix + "/");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
var _excluded$2 = ["href", "locale", "prefetch"];
|
|
111
|
-
function BaseLink(_ref, ref) {
|
|
112
|
-
var href = _ref.href,
|
|
113
|
-
locale = _ref.locale,
|
|
114
|
-
prefetch = _ref.prefetch,
|
|
115
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
116
|
-
var pathname = navigation.usePathname();
|
|
117
|
-
var defaultLocale = useClientLocale();
|
|
118
|
-
var isChangingLocale = locale !== defaultLocale;
|
|
119
|
-
var _useState = React.useState(function () {
|
|
120
|
-
return isLocalHref(href) && locale ?
|
|
121
|
-
// Potentially the href shouldn't be prefixed, but to determine this we
|
|
122
|
-
// need a) the default locale and b) the information if we use prefixed
|
|
123
|
-
// routing. During the server side render (both in RSC as well as SSR),
|
|
124
|
-
// we don't have this information. Therefore we always prefix the href
|
|
125
|
-
// since this will always result in a valid URL, even if it might cause
|
|
126
|
-
// a redirect. This is better than pointing to a non-localized href
|
|
127
|
-
// during the server render, which would potentially be wrong. The final
|
|
128
|
-
// href is determined in the effect below.
|
|
129
|
-
prefixHref(href, locale) : href;
|
|
130
|
-
}),
|
|
131
|
-
localizedHref = _useState[0],
|
|
132
|
-
setLocalizedHref = _useState[1];
|
|
133
|
-
React.useEffect(function () {
|
|
134
|
-
setLocalizedHref(localizeHref(href, locale, defaultLocale, pathname != null ? pathname : undefined));
|
|
135
|
-
}, [defaultLocale, href, locale, pathname]);
|
|
136
|
-
if (isChangingLocale) {
|
|
137
|
-
if (prefetch && "development" !== 'production') {
|
|
138
|
-
console.error('The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`');
|
|
139
|
-
}
|
|
140
|
-
prefetch = false;
|
|
141
|
-
}
|
|
142
|
-
return React__default["default"].createElement(NextLink__default["default"], _extends({
|
|
143
|
-
ref: ref,
|
|
144
|
-
href: localizedHref,
|
|
145
|
-
prefetch: prefetch
|
|
146
|
-
}, rest));
|
|
147
|
-
}
|
|
148
|
-
var BaseLink$1 = /*#__PURE__*/React.forwardRef(BaseLink);
|
|
149
|
-
|
|
150
|
-
var _excluded$1 = ["locale"];
|
|
151
|
-
function Link(_ref, ref) {
|
|
152
|
-
var locale = _ref.locale,
|
|
153
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
154
|
-
var defaultLocale = useClientLocale();
|
|
155
|
-
return React__default["default"].createElement(BaseLink$1, _extends({
|
|
156
|
-
ref: ref,
|
|
157
|
-
locale: locale || defaultLocale
|
|
158
|
-
}, rest));
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Wraps `next/link` and prefixes the `href` with the current locale if
|
|
162
|
-
* necessary.
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* ```tsx
|
|
166
|
-
* import {Link} from 'next-intl';
|
|
167
|
-
*
|
|
168
|
-
* // When the user is on `/en`, the link will point to `/en/about`
|
|
169
|
-
* <Link href="/about">About</Link>
|
|
170
|
-
*
|
|
171
|
-
* // You can override the `locale` to switch to another language
|
|
172
|
-
* <Link href="/" locale="de">Switch to German</Link>
|
|
173
|
-
* ```
|
|
174
|
-
*
|
|
175
|
-
* Note that when a `locale` prop is passed to switch the locale, the `prefetch`
|
|
176
|
-
* prop is not supported. This is because Next.js would prefetch the page and
|
|
177
|
-
* the `set-cookie` response header would cause the locale cookie on the current
|
|
178
|
-
* page to be overwritten before the user even decides to change the locale.
|
|
179
|
-
*/
|
|
180
|
-
var Link$1 = /*#__PURE__*/React.forwardRef(Link);
|
|
181
|
-
|
|
182
|
-
// TODO: Only available for backwards compatibility
|
|
183
|
-
// during the beta, remove for stable release
|
|
184
|
-
var hasWarned$1 = false;
|
|
185
|
-
/** @deprecated Is available as `import Link from 'next-intl/link'` now. */
|
|
186
|
-
function LinkDeprecated(props) {
|
|
187
|
-
if (!hasWarned$1) {
|
|
188
|
-
console.warn("\n\nDEPRECATION WARNING: The import for `Link` from next-intl has changed.\n\nPreviously: import {Link} from 'next-intl';\nNow: import Link from 'next-intl/link';\n\nPlease upgrade your import accordingly. See also https://next-intl-docs.vercel.app/docs/next-13/navigation#link\n\n");
|
|
189
|
-
hasWarned$1 = true;
|
|
190
|
-
}
|
|
191
|
-
return React__default["default"].createElement(Link$1, _extends({}, props));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
40
|
var _excluded = ["children", "locale", "now"];
|
|
195
41
|
function NextIntlClientProvider(_ref) {
|
|
196
42
|
var children = _ref.children,
|
|
@@ -225,71 +71,8 @@ function NextIntlClientProvider(_ref) {
|
|
|
225
71
|
}, rest), children);
|
|
226
72
|
}
|
|
227
73
|
|
|
228
|
-
/**
|
|
229
|
-
* Returns a wrapped instance of `useRouter` from `next/navigation` that
|
|
230
|
-
* will automatically localize the `href` parameters it receives.
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* ```tsx
|
|
234
|
-
* 'use client';
|
|
235
|
-
*
|
|
236
|
-
* import {useRouter} from 'next-intl/client';
|
|
237
|
-
*
|
|
238
|
-
* const router = useRouter();
|
|
239
|
-
*
|
|
240
|
-
* // When the user is on `/en`, the router will navigate to `/en/about`
|
|
241
|
-
* router.push('/about');
|
|
242
|
-
* ```
|
|
243
|
-
*/
|
|
244
|
-
function useRouter() {
|
|
245
|
-
var router = navigation.useRouter();
|
|
246
|
-
var locale = useClientLocale();
|
|
247
|
-
return React.useMemo(function () {
|
|
248
|
-
function localize(href) {
|
|
249
|
-
return localizeHref(href, locale, locale, window.location.pathname);
|
|
250
|
-
}
|
|
251
|
-
return _extends({}, router, {
|
|
252
|
-
push: function push(href) {
|
|
253
|
-
return router.push(localize(href));
|
|
254
|
-
},
|
|
255
|
-
replace: function replace(href) {
|
|
256
|
-
return router.replace(localize(href));
|
|
257
|
-
},
|
|
258
|
-
prefetch: function prefetch(href) {
|
|
259
|
-
return router.prefetch(localize(href));
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
}, [locale, router]);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// TODO: Only available for backwards compatibility
|
|
266
|
-
// during the beta, remove for stable release
|
|
267
|
-
var hasWarned = false;
|
|
268
|
-
function useLocalizedRouterDeprecated() {
|
|
269
|
-
if (!hasWarned) {
|
|
270
|
-
console.warn("\n\nDEPRECATION WARNING: The `useLocalizedRouter` import from `next-intl` is deprecated and will be removed in the stable release of next-intl. Please import `useLocalizedRouter` from `next-intl/client` instead. See https://next-intl-docs.vercel.app/docs/next-13/server-components\n\n");
|
|
271
|
-
hasWarned = true;
|
|
272
|
-
}
|
|
273
|
-
return useRouter();
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* This is the main entry file when non-'react-server'
|
|
278
|
-
* environments import from 'next-intl'.
|
|
279
|
-
*
|
|
280
|
-
* Maintainer notes:
|
|
281
|
-
* - Make sure this mirrors the API from 'react-server'.
|
|
282
|
-
* - Make sure everything exported from this module is
|
|
283
|
-
* supported in all Next.js versions that are supported.
|
|
284
|
-
*/
|
|
285
|
-
/** @deprecated Is available as `import Link from 'next-intl/link'` now. */
|
|
286
|
-
var LocalizedLink = LinkDeprecated;
|
|
287
|
-
|
|
288
|
-
exports.Link = LinkDeprecated;
|
|
289
|
-
exports.LocalizedLink = LocalizedLink;
|
|
290
74
|
exports.NextIntlClientProvider = NextIntlClientProvider;
|
|
291
75
|
exports.NextIntlProvider = NextIntlClientProvider;
|
|
292
|
-
exports.useLocalizedRouter = useLocalizedRouterDeprecated;
|
|
293
76
|
Object.keys(useIntl).forEach(function (k) {
|
|
294
77
|
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
295
78
|
enumerable: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.cjs.development.js","sources":["../src/shared/constants.tsx","../src/client/useClientLocale.tsx","../src/shared/utils.tsx","../src/shared/BaseLink.tsx","../src/link/Link.tsx","../src/react-client/Link.tsx","../src/shared/NextIntlClientProvider.tsx","../src/client/useRouter.tsx","../src/react-client/useLocalizedRouter.tsx","../src/react-client/index.tsx"],"sourcesContent":["// Reuse the legacy cookie name\n// https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie\nexport const COOKIE_LOCALE_NAME = 'NEXT_LOCALE';\n\n// Should take precedence over the cookie\nexport const HEADER_LOCALE_NAME = 'X-NEXT-INTL-LOCALE';\n\n// In a URL like \"/en-US/about\", the locale segment is \"en-US\"\nexport const LOCALE_SEGMENT_NAME = 'locale';\n","import {useParams} from 'next/navigation';\nimport {useLocale} from 'use-intl';\nimport {LOCALE_SEGMENT_NAME} from '../shared/constants';\n\nexport default function useClientLocale(): string {\n let locale;\n\n const params = useParams();\n if (params[LOCALE_SEGMENT_NAME]) {\n locale = params[LOCALE_SEGMENT_NAME];\n } else {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine\n locale = useLocale();\n }\n\n return locale;\n}\n","import {UrlObject} from 'url';\nimport NextLink from 'next/link';\nimport {ComponentProps} from 'react';\n\ntype Href = ComponentProps<typeof NextLink>['href'];\n\nexport function isRelativeHref(href: Href) {\n const pathname = typeof href === 'object' ? href.pathname : href;\n return pathname != null && !pathname.startsWith('/');\n}\n\nexport function isLocalHref(href: Href) {\n if (typeof href === 'object') {\n return href.host == null && href.hostname == null;\n } else {\n const hasProtocol = /^[a-z]+:/i.test(href);\n return !hasProtocol;\n }\n}\n\nexport function localizeHref(\n href: string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): UrlObject | string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string = locale,\n pathname: string\n) {\n if (!isLocalHref(href) || isRelativeHref(href)) {\n return href;\n }\n\n const isSwitchingLocale = locale !== defaultLocale;\n const isPathnamePrefixed =\n locale == null || hasPathnamePrefixed(locale, pathname);\n const shouldPrefix = isPathnamePrefixed || isSwitchingLocale;\n\n if (shouldPrefix && locale != null) {\n return prefixHref(href, locale);\n }\n\n return href;\n}\n\nexport function prefixHref(href: string, locale: string): string;\nexport function prefixHref(\n href: UrlObject | string,\n locale: string\n): UrlObject | string;\nexport function prefixHref(href: UrlObject | string, locale: string) {\n let prefixedHref;\n if (typeof href === 'string') {\n prefixedHref = localizePathname(locale, href);\n } else {\n prefixedHref = {...href};\n if (href.pathname) {\n prefixedHref.pathname = localizePathname(locale, href.pathname);\n }\n }\n\n return prefixedHref;\n}\n\nexport function unlocalizePathname(pathname: string, locale: string) {\n return pathname.replace(new RegExp(`^/${locale}`), '') || '/';\n}\n\nexport function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n\nexport function hasPathnamePrefixed(locale: string, pathname: string) {\n const prefix = `/${locale}`;\n return pathname === prefix || pathname.startsWith(`${prefix}/`);\n}\n","'use client';\n\nimport NextLink from 'next/link';\nimport {usePathname} from 'next/navigation';\nimport React, {ComponentProps, forwardRef, useEffect, useState} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport {isLocalHref, localizeHref, prefixHref} from './utils';\n\ntype Props = Omit<ComponentProps<typeof NextLink>, 'locale'> & {\n locale: string;\n};\n\nfunction BaseLink({href, locale, prefetch, ...rest}: Props, ref: Props['ref']) {\n const pathname = usePathname();\n const defaultLocale = useClientLocale();\n const isChangingLocale = locale !== defaultLocale;\n\n const [localizedHref, setLocalizedHref] = useState<typeof href>(() =>\n isLocalHref(href) && locale\n ? // Potentially the href shouldn't be prefixed, but to determine this we\n // need a) the default locale and b) the information if we use prefixed\n // routing. During the server side render (both in RSC as well as SSR),\n // we don't have this information. Therefore we always prefix the href\n // since this will always result in a valid URL, even if it might cause\n // a redirect. This is better than pointing to a non-localized href\n // during the server render, which would potentially be wrong. The final\n // href is determined in the effect below.\n prefixHref(href, locale)\n : href\n );\n\n useEffect(() => {\n setLocalizedHref(\n localizeHref(href, locale, defaultLocale, pathname ?? undefined)\n );\n }, [defaultLocale, href, locale, pathname]);\n\n if (isChangingLocale) {\n if (prefetch && process.env.NODE_ENV !== 'production') {\n console.error(\n 'The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`'\n );\n }\n prefetch = false;\n }\n\n return (\n <NextLink ref={ref} href={localizedHref} prefetch={prefetch} {...rest} />\n );\n}\n\nexport default forwardRef(BaseLink);\n","import React, {ComponentProps, forwardRef} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport BaseLink from '../shared/BaseLink';\n\ntype Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {\n locale?: string;\n};\n\nfunction Link({locale, ...rest}: Props, ref: Props['ref']) {\n const defaultLocale = useClientLocale();\n return <BaseLink ref={ref} locale={locale || defaultLocale} {...rest} />;\n}\n\n/**\n * Wraps `next/link` and prefixes the `href` with the current locale if\n * necessary.\n *\n * @example\n * ```tsx\n * import {Link} from 'next-intl';\n *\n * // When the user is on `/en`, the link will point to `/en/about`\n * <Link href=\"/about\">About</Link>\n *\n * // You can override the `locale` to switch to another language\n * <Link href=\"/\" locale=\"de\">Switch to German</Link>\n * ```\n *\n * Note that when a `locale` prop is passed to switch the locale, the `prefetch`\n * prop is not supported. This is because Next.js would prefetch the page and\n * the `set-cookie` response header would cause the locale cookie on the current\n * page to be overwritten before the user even decides to change the locale.\n */\nexport default forwardRef(Link);\n","import React, {ComponentProps} from 'react';\nimport Link from '../link';\n\n// TODO: Only available for backwards compatibility\n// during the beta, remove for stable release\n\nlet hasWarned = false;\n\n/** @deprecated Is available as `import Link from 'next-intl/link'` now. */\nexport default function LinkDeprecated(props: ComponentProps<typeof Link>) {\n if (!hasWarned) {\n console.warn(\n `\\n\\nDEPRECATION WARNING: The import for \\`Link\\` from next-intl has changed.\n\nPreviously: import {Link} from 'next-intl';\nNow: import Link from 'next-intl/link';\n\nPlease upgrade your import accordingly. See also https://next-intl-docs.vercel.app/docs/next-13/navigation#link\\n\\n`\n );\n hasWarned = true;\n }\n\n return <Link {...props} />;\n}\n","'use client';\n\nimport {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale' | 'now'> & {\n locale?: string;\n /** If a string is supplied, make sure this conforms to the ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ */\n now?: Date | string;\n};\n\nexport default function NextIntlClientProvider({\n children,\n locale,\n now,\n ...rest\n}: Props) {\n let router;\n try {\n // Reading from context is practically ok to do conditionally\n // eslint-disable-next-line react-hooks/rules-of-hooks\n router = useRouter();\n } catch (error) {\n // Calling `useRouter` is not supported in the app folder\n }\n\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n if (!locale && router) {\n locale = router.locale;\n }\n\n // Currently RSC serialize dates to strings, therefore make sure we have\n // a date object. We might be able to remove this once more types have\n // first-class serialization support (https://github.com/facebook/react/issues/25687)\n if (typeof now === 'string') {\n now = new Date(now);\n }\n\n if (!locale) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? \"Couldn't determine locale. Please pass an explicit `locale` prop the provider, or if you're using the `pages` folder, use internationalized routing (https://nextjs.org/docs/advanced-features/i18n-routing).\"\n : undefined\n );\n }\n\n return (\n <IntlProvider locale={locale} now={now} {...rest}>\n {children}\n </IntlProvider>\n );\n}\n","import {useRouter as useNextRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {localizeHref} from '../shared/utils';\nimport useClientLocale from './useClientLocale';\n\n/**\n * Returns a wrapped instance of `useRouter` from `next/navigation` that\n * will automatically localize the `href` parameters it receives.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import {useRouter} from 'next-intl/client';\n *\n * const router = useRouter();\n *\n * // When the user is on `/en`, the router will navigate to `/en/about`\n * router.push('/about');\n * ```\n */\nexport default function useRouter() {\n const router = useNextRouter();\n const locale = useClientLocale();\n\n return useMemo(() => {\n function localize(href: string) {\n return localizeHref(href, locale, locale, window.location.pathname);\n }\n\n return {\n ...router,\n push(href: string) {\n return router.push(localize(href));\n },\n replace(href: string) {\n return router.replace(localize(href));\n },\n prefetch(href: string) {\n return router.prefetch(localize(href));\n }\n };\n }, [locale, router]);\n}\n","import useRouter from '../client/useRouter';\n\n// TODO: Only available for backwards compatibility\n// during the beta, remove for stable release\n\nlet hasWarned = false;\n\nexport default function useLocalizedRouterDeprecated() {\n if (!hasWarned) {\n console.warn(\n `\\n\\nDEPRECATION WARNING: The \\`useLocalizedRouter\\` import from \\`next-intl\\` is deprecated and will be removed in the stable release of next-intl. Please import \\`useLocalizedRouter\\` from \\`next-intl/client\\` instead. See https://next-intl-docs.vercel.app/docs/next-13/server-components\\n\\n`\n );\n hasWarned = true;\n }\n\n return useRouter();\n}\n","/**\n * This is the main entry file when non-'react-server'\n * environments import from 'next-intl'.\n *\n * Maintainer notes:\n * - Make sure this mirrors the API from 'react-server'.\n * - Make sure everything exported from this module is\n * supported in all Next.js versions that are supported.\n */\n\nimport Link from './Link';\n\nexport * from 'use-intl';\nexport {default as NextIntlClientProvider} from '../shared/NextIntlClientProvider';\n\n// Legacy export (TBD if we'll deprecate this in favour of `NextIntlClientProvider`)\nexport {default as NextIntlProvider} from '../shared/NextIntlClientProvider';\n\n/** @deprecated Is available as `import Link from 'next-intl/link'` now. */\nexport const LocalizedLink = Link;\nexport {default as Link} from './Link';\n\nexport {default as useLocalizedRouter} from './useLocalizedRouter';\n"],"names":["LOCALE_SEGMENT_NAME","useClientLocale","locale","params","useParams","useLocale","isRelativeHref","href","pathname","startsWith","isLocalHref","host","hostname","hasProtocol","test","localizeHref","defaultLocale","isSwitchingLocale","isPathnamePrefixed","hasPathnamePrefixed","shouldPrefix","prefixHref","prefixedHref","localizePathname","_extends","localizedHref","prefix","_excluded","BaseLink","_ref","ref","prefetch","rest","_objectWithoutPropertiesLoose","usePathname","isChangingLocale","_useState","useState","setLocalizedHref","useEffect","undefined","process","console","error","React","createElement","NextLink","forwardRef","Link","hasWarned","LinkDeprecated","props","warn","NextIntlClientProvider","children","now","router","useRouter","Date","Error","IntlProvider","useNextRouter","useMemo","localize","window","location","push","replace","useLocalizedRouterDeprecated","LocalizedLink"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAOA;AACO,IAAMA,mBAAmB,GAAG,QAAQ;;ACJ7B,SAAUC,eAAeA,GAAA;AACrC,EAAA,IAAIC,MAAM,CAAA;AAEV,EAAA,IAAMC,MAAM,GAAGC,oBAAS,EAAE,CAAA;AAC1B,EAAA,IAAID,MAAM,CAACH,mBAAmB,CAAC,EAAE;AAC/BE,IAAAA,MAAM,GAAGC,MAAM,CAACH,mBAAmB,CAAC,CAAA;AACrC,GAAA,MAAM;AACL;IACAE,MAAM,GAAGG,iBAAS,EAAE,CAAA;AACrB,GAAA;AAED,EAAA,OAAOH,MAAM,CAAA;AACf;;ACVM,SAAUI,cAAcA,CAACC,IAAU,EAAA;EACvC,IAAMC,QAAQ,GAAG,OAAOD,IAAI,KAAK,QAAQ,GAAGA,IAAI,CAACC,QAAQ,GAAGD,IAAI,CAAA;EAChE,OAAOC,QAAQ,IAAI,IAAI,IAAI,CAACA,QAAQ,CAACC,UAAU,CAAC,GAAG,CAAC,CAAA;AACtD,CAAA;AAEM,SAAUC,WAAWA,CAACH,IAAU,EAAA;AACpC,EAAA,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IAC5B,OAAOA,IAAI,CAACI,IAAI,IAAI,IAAI,IAAIJ,IAAI,CAACK,QAAQ,IAAI,IAAI,CAAA;AAClD,GAAA,MAAM;AACL,IAAA,IAAMC,WAAW,GAAG,WAAW,CAACC,IAAI,CAACP,IAAI,CAAC,CAAA;AAC1C,IAAA,OAAO,CAACM,WAAW,CAAA;AACpB,GAAA;AACH,CAAA;AAcM,SAAUE,YAAYA,CAC1BR,IAAwB,E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AI,CAACnB,SAAS,EAAE;IACdP,OAAO,CAACU,IAAI,CAAA,8RAC4R,CACvS,CAAA;AACDH,IAAAA,SAAS,GAAG,IAAI,CAAA;AACjB,GAAA;EAED,OAAOQ,SAAS,EAAE,CAAA;AACpB;;AChBA;;;;;;;;AAQG;AAUH;AACO,IAAMY,aAAa,GAAGrB;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"next-intl.cjs.development.js","sources":["../src/shared/NextIntlClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale' | 'now'> & {\n locale?: string;\n /** If a string is supplied, make sure this conforms to the ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ */\n now?: Date | string;\n};\n\nexport default function NextIntlClientProvider({\n children,\n locale,\n now,\n ...rest\n}: Props) {\n let router;\n try {\n // Reading from context is practically ok to do conditionally\n // eslint-disable-next-line react-hooks/rules-of-hooks\n router = useRouter();\n } catch (error) {\n // Calling `useRouter` is not supported in the app folder\n }\n\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n if (!locale && router) {\n locale = router.locale;\n }\n\n // Currently RSC serialize dates to strings, therefore make sure we have\n // a date object. We might be able to remove this once more types have\n // first-class serialization support (https://github.com/facebook/react/issues/25687)\n if (typeof now === 'string') {\n now = new Date(now);\n }\n\n if (!locale) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? \"Couldn't determine locale. Please pass an explicit `locale` prop the provider, or if you're using the `pages` folder, use internationalized routing (https://nextjs.org/docs/advanced-features/i18n-routing).\"\n : undefined\n );\n }\n\n return (\n <IntlProvider locale={locale} now={now} {...rest}>\n {children}\n </IntlProvider>\n );\n}\n"],"names":["_excluded","NextIntlClientProvider","_ref","children","locale","now","rest","_objectWithoutPropertiesLoose","router","useRouter","error","Date","Error","React","createElement","IntlProvider","_extends"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAa,IAAAA,SAAA,GAAA,CAAA,UAAA,EAAA,QAAA,EAAA,KAAA,CAAA,CAAA;AAYW,SAAAC,sBAAsBA,CAAAC,IAAA,EAKtC;AAAA,EAAA,IAJNC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IACRC,MAAM,GAAAF,IAAA,CAANE,MAAM;IACNC,GAAG,GAAAH,IAAA,CAAHG,GAAG;AACAC,IAAAA,IAAI,GAAAC,6BAAA,CAAAL,IAAA,EAAAF,SAAA,CAAA,CAAA;AAEP,EAAA,IAAIQ,QAAM,CAAA;EACV,IAAI;AACF;AACA;IACAA,QAAM,GAAGC,gBAAS,EAAE,CAAA;GACrB,CAAC,OAAOC,KAAK,EAAE;AACd;AAAA,GAAA;AAGF;AACA;AACA,EAAA,IAAI,CAACN,MAAM,IAAII,QAAM,EAAE;IACrBJ,MAAM,GAAGI,QAAM,CAACJ,MAAM,CAAA;AACvB,GAAA;AAED;AACA;AACA;AACA,EAAA,IAAI,OAAOC,GAAG,KAAK,QAAQ,EAAE;AAC3BA,IAAAA,GAAG,GAAG,IAAIM,IAAI,CAACN,GAAG,CAAC,CAAA;AACpB,GAAA;EAED,IAAI,CAACD,MAAM,EAAE;AACX,IAAA,MAAM,IAAIQ,KAAK,CAET,+MAA+M,CACtM,CACd,CAAA;AACF,GAAA;AAED,EAAA,OACEC,yBAAC,CAAAC,aAAA,CAAAC,oBAAY,EAAAC,QAAA,CAAA;AAACZ,IAAAA,MAAM,EAAEA,MAAM;AAAEC,IAAAA,GAAG,EAAEA,GAAAA;GAASC,EAAAA,IAAI,CAC7CH,EAAAA,QAAQ,CACI,CAAA;AAEnB;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("use-intl"),r=require("next/router");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(require("react"));function o(){return o=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},o.apply(this,arguments)}var i=["children","locale","now"];function l(t){var l,u=t.children,a=t.locale,c=t.now,f=function(e,r){if(null==e)return{};var t,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r.indexOf(t=i[n])>=0||(o[t]=e[t]);return o}(t,i);try{l=r.useRouter()}catch(e){}if(!a&&l&&(a=l.locale),"string"==typeof c&&(c=new Date(c)),!a)throw new Error(void 0);return n.default.createElement(e.IntlProvider,o({locale:a,now:c},f),u)}exports.NextIntlClientProvider=l,exports.NextIntlProvider=l,Object.keys(e).forEach((function(r){"default"===r||exports.hasOwnProperty(r)||Object.defineProperty(exports,r,{enumerable:!0,get:function(){return e[r]}})}));
|
|
2
2
|
//# sourceMappingURL=next-intl.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.cjs.production.min.js","sources":["../src/shared/constants.tsx","../src/client/useClientLocale.tsx","../src/shared/utils.tsx","../src/shared/BaseLink.tsx","../src/link/Link.tsx","../src/react-client/Link.tsx","../src/shared/NextIntlClientProvider.tsx","../src/react-client/useLocalizedRouter.tsx","../src/react-client/index.tsx","../src/client/useRouter.tsx"],"sourcesContent":["// Reuse the legacy cookie name\n// https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie\nexport const COOKIE_LOCALE_NAME = 'NEXT_LOCALE';\n\n// Should take precedence over the cookie\nexport const HEADER_LOCALE_NAME = 'X-NEXT-INTL-LOCALE';\n\n// In a URL like \"/en-US/about\", the locale segment is \"en-US\"\nexport const LOCALE_SEGMENT_NAME = 'locale';\n","import {useParams} from 'next/navigation';\nimport {useLocale} from 'use-intl';\nimport {LOCALE_SEGMENT_NAME} from '../shared/constants';\n\nexport default function useClientLocale(): string {\n let locale;\n\n const params = useParams();\n if (params[LOCALE_SEGMENT_NAME]) {\n locale = params[LOCALE_SEGMENT_NAME];\n } else {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine\n locale = useLocale();\n }\n\n return locale;\n}\n","import {UrlObject} from 'url';\nimport NextLink from 'next/link';\nimport {ComponentProps} from 'react';\n\ntype Href = ComponentProps<typeof NextLink>['href'];\n\nexport function isRelativeHref(href: Href) {\n const pathname = typeof href === 'object' ? href.pathname : href;\n return pathname != null && !pathname.startsWith('/');\n}\n\nexport function isLocalHref(href: Href) {\n if (typeof href === 'object') {\n return href.host == null && href.hostname == null;\n } else {\n const hasProtocol = /^[a-z]+:/i.test(href);\n return !hasProtocol;\n }\n}\n\nexport function localizeHref(\n href: string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): UrlObject | string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string = locale,\n pathname: string\n) {\n if (!isLocalHref(href) || isRelativeHref(href)) {\n return href;\n }\n\n const isSwitchingLocale = locale !== defaultLocale;\n const isPathnamePrefixed =\n locale == null || hasPathnamePrefixed(locale, pathname);\n const shouldPrefix = isPathnamePrefixed || isSwitchingLocale;\n\n if (shouldPrefix && locale != null) {\n return prefixHref(href, locale);\n }\n\n return href;\n}\n\nexport function prefixHref(href: string, locale: string): string;\nexport function prefixHref(\n href: UrlObject | string,\n locale: string\n): UrlObject | string;\nexport function prefixHref(href: UrlObject | string, locale: string) {\n let prefixedHref;\n if (typeof href === 'string') {\n prefixedHref = localizePathname(locale, href);\n } else {\n prefixedHref = {...href};\n if (href.pathname) {\n prefixedHref.pathname = localizePathname(locale, href.pathname);\n }\n }\n\n return prefixedHref;\n}\n\nexport function unlocalizePathname(pathname: string, locale: string) {\n return pathname.replace(new RegExp(`^/${locale}`), '') || '/';\n}\n\nexport function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n\nexport function hasPathnamePrefixed(locale: string, pathname: string) {\n const prefix = `/${locale}`;\n return pathname === prefix || pathname.startsWith(`${prefix}/`);\n}\n","'use client';\n\nimport NextLink from 'next/link';\nimport {usePathname} from 'next/navigation';\nimport React, {ComponentProps, forwardRef, useEffect, useState} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport {isLocalHref, localizeHref, prefixHref} from './utils';\n\ntype Props = Omit<ComponentProps<typeof NextLink>, 'locale'> & {\n locale: string;\n};\n\nfunction BaseLink({href, locale, prefetch, ...rest}: Props, ref: Props['ref']) {\n const pathname = usePathname();\n const defaultLocale = useClientLocale();\n const isChangingLocale = locale !== defaultLocale;\n\n const [localizedHref, setLocalizedHref] = useState<typeof href>(() =>\n isLocalHref(href) && locale\n ? // Potentially the href shouldn't be prefixed, but to determine this we\n // need a) the default locale and b) the information if we use prefixed\n // routing. During the server side render (both in RSC as well as SSR),\n // we don't have this information. Therefore we always prefix the href\n // since this will always result in a valid URL, even if it might cause\n // a redirect. This is better than pointing to a non-localized href\n // during the server render, which would potentially be wrong. The final\n // href is determined in the effect below.\n prefixHref(href, locale)\n : href\n );\n\n useEffect(() => {\n setLocalizedHref(\n localizeHref(href, locale, defaultLocale, pathname ?? undefined)\n );\n }, [defaultLocale, href, locale, pathname]);\n\n if (isChangingLocale) {\n if (prefetch && process.env.NODE_ENV !== 'production') {\n console.error(\n 'The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`'\n );\n }\n prefetch = false;\n }\n\n return (\n <NextLink ref={ref} href={localizedHref} prefetch={prefetch} {...rest} />\n );\n}\n\nexport default forwardRef(BaseLink);\n","import React, {ComponentProps, forwardRef} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport BaseLink from '../shared/BaseLink';\n\ntype Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {\n locale?: string;\n};\n\nfunction Link({locale, ...rest}: Props, ref: Props['ref']) {\n const defaultLocale = useClientLocale();\n return <BaseLink ref={ref} locale={locale || defaultLocale} {...rest} />;\n}\n\n/**\n * Wraps `next/link` and prefixes the `href` with the current locale if\n * necessary.\n *\n * @example\n * ```tsx\n * import {Link} from 'next-intl';\n *\n * // When the user is on `/en`, the link will point to `/en/about`\n * <Link href=\"/about\">About</Link>\n *\n * // You can override the `locale` to switch to another language\n * <Link href=\"/\" locale=\"de\">Switch to German</Link>\n * ```\n *\n * Note that when a `locale` prop is passed to switch the locale, the `prefetch`\n * prop is not supported. This is because Next.js would prefetch the page and\n * the `set-cookie` response header would cause the locale cookie on the current\n * page to be overwritten before the user even decides to change the locale.\n */\nexport default forwardRef(Link);\n","import React, {ComponentProps} from 'react';\nimport Link from '../link';\n\n// TODO: Only available for backwards compatibility\n// during the beta, remove for stable release\n\nlet hasWarned = false;\n\n/** @deprecated Is available as `import Link from 'next-intl/link'` now. */\nexport default function LinkDeprecated(props: ComponentProps<typeof Link>) {\n if (!hasWarned) {\n console.warn(\n `\\n\\nDEPRECATION WARNING: The import for \\`Link\\` from next-intl has changed.\n\nPreviously: import {Link} from 'next-intl';\nNow: import Link from 'next-intl/link';\n\nPlease upgrade your import accordingly. See also https://next-intl-docs.vercel.app/docs/next-13/navigation#link\\n\\n`\n );\n hasWarned = true;\n }\n\n return <Link {...props} />;\n}\n","'use client';\n\nimport {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale' | 'now'> & {\n locale?: string;\n /** If a string is supplied, make sure this conforms to the ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ */\n now?: Date | string;\n};\n\nexport default function NextIntlClientProvider({\n children,\n locale,\n now,\n ...rest\n}: Props) {\n let router;\n try {\n // Reading from context is practically ok to do conditionally\n // eslint-disable-next-line react-hooks/rules-of-hooks\n router = useRouter();\n } catch (error) {\n // Calling `useRouter` is not supported in the app folder\n }\n\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n if (!locale && router) {\n locale = router.locale;\n }\n\n // Currently RSC serialize dates to strings, therefore make sure we have\n // a date object. We might be able to remove this once more types have\n // first-class serialization support (https://github.com/facebook/react/issues/25687)\n if (typeof now === 'string') {\n now = new Date(now);\n }\n\n if (!locale) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? \"Couldn't determine locale. Please pass an explicit `locale` prop the provider, or if you're using the `pages` folder, use internationalized routing (https://nextjs.org/docs/advanced-features/i18n-routing).\"\n : undefined\n );\n }\n\n return (\n <IntlProvider locale={locale} now={now} {...rest}>\n {children}\n </IntlProvider>\n );\n}\n","import useRouter from '../client/useRouter';\n\n// TODO: Only available for backwards compatibility\n// during the beta, remove for stable release\n\nlet hasWarned = false;\n\nexport default function useLocalizedRouterDeprecated() {\n if (!hasWarned) {\n console.warn(\n `\\n\\nDEPRECATION WARNING: The \\`useLocalizedRouter\\` import from \\`next-intl\\` is deprecated and will be removed in the stable release of next-intl. Please import \\`useLocalizedRouter\\` from \\`next-intl/client\\` instead. See https://next-intl-docs.vercel.app/docs/next-13/server-components\\n\\n`\n );\n hasWarned = true;\n }\n\n return useRouter();\n}\n","/**\n * This is the main entry file when non-'react-server'\n * environments import from 'next-intl'.\n *\n * Maintainer notes:\n * - Make sure this mirrors the API from 'react-server'.\n * - Make sure everything exported from this module is\n * supported in all Next.js versions that are supported.\n */\n\nimport Link from './Link';\n\nexport * from 'use-intl';\nexport {default as NextIntlClientProvider} from '../shared/NextIntlClientProvider';\n\n// Legacy export (TBD if we'll deprecate this in favour of `NextIntlClientProvider`)\nexport {default as NextIntlProvider} from '../shared/NextIntlClientProvider';\n\n/** @deprecated Is available as `import Link from 'next-intl/link'` now. */\nexport const LocalizedLink = Link;\nexport {default as Link} from './Link';\n\nexport {default as useLocalizedRouter} from './useLocalizedRouter';\n","import {useRouter as useNextRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {localizeHref} from '../shared/utils';\nimport useClientLocale from './useClientLocale';\n\n/**\n * Returns a wrapped instance of `useRouter` from `next/navigation` that\n * will automatically localize the `href` parameters it receives.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import {useRouter} from 'next-intl/client';\n *\n * const router = useRouter();\n *\n * // When the user is on `/en`, the router will navigate to `/en/about`\n * router.push('/about');\n * ```\n */\nexport default function useRouter() {\n const router = useNextRouter();\n const locale = useClientLocale();\n\n return useMemo(() => {\n function localize(href: string) {\n return localizeHref(href, locale, locale, window.location.pathname);\n }\n\n return {\n ...router,\n push(href: string) {\n return router.push(localize(href));\n },\n replace(href: string) {\n return router.replace(localize(href));\n },\n prefetch(href: string) {\n return router.prefetch(localize(href));\n }\n };\n }, [locale, router]);\n}\n"],"names":["LOCALE_SEGMENT_NAME","useClientLocale","params","useParams","useLocale","isLocalHref","href","host","hostname","test","localizeHref","locale","defaultLocale","pathname","startsWith","isRelativeHref","isSwitchingLocale","isPathnamePrefixed","prefix","hasPathnamePrefixed","prefixHref","prefixedHref","localizePathname","_extends","localizedHref","_excluded","BaseLink","_ref","ref","prefetch","rest","_objectWithoutPropertiesLoose","usePathname","isChangingLocale","_useState","useState","setLocalizedHref","useEffect","undefined","React","createElement","NextLink","BaseLink$1","forwardRef","Link","Link$1","hasWarned","LinkDeprecated","props","console","warn","NextIntlClientProvider","router","children","now","useRouter","error","Date","Error","IntlProvider","LocalizedLink","useNextRouter","useMemo","localize","window","location","push","replace"],"mappings":"goBAQO,IAAMA,EAAsB,SCJrB,SAAUC,IACtB,IAEMC,EAASC,EAAAA,YAQf,OAPID,EAAOF,GACAE,EAAOF,GAGPI,EAASA,WAItB,CCLM,SAAUC,EAAYC,GAC1B,MAAoB,iBAATA,EACW,MAAbA,EAAKC,MAAiC,MAAjBD,EAAKE,UAEb,YAAYC,KAAKH,EAGzC,CAcM,SAAUI,EACdJ,EACAK,EACAC,EACAC,GAEA,QAHA,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QA,EAAQqD,OAAOC,SAASpD,SAC5D,CAEA,OAAAU,KACK6B,EAAM,CACTc,KAAI,SAAC5D,GACH,OAAO8C,EAAOc,KAAKH,EAASzD,GAC7B,EACD6D,QAAO,SAAC7D,GACN,OAAO8C,EAAOe,QAAQJ,EAASzD,GAChC,EACDuB,SAAQ,SAACvB,GACP,OAAO8C,EAAOvB,SAASkC,EAASzD,GAClC,GAEJ,GAAG,CAACK,EAAQyC,GACd,CF5BSG,EACT"}
|
|
1
|
+
{"version":3,"file":"next-intl.cjs.production.min.js","sources":["../src/shared/NextIntlClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale' | 'now'> & {\n locale?: string;\n /** If a string is supplied, make sure this conforms to the ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ */\n now?: Date | string;\n};\n\nexport default function NextIntlClientProvider({\n children,\n locale,\n now,\n ...rest\n}: Props) {\n let router;\n try {\n // Reading from context is practically ok to do conditionally\n // eslint-disable-next-line react-hooks/rules-of-hooks\n router = useRouter();\n } catch (error) {\n // Calling `useRouter` is not supported in the app folder\n }\n\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n if (!locale && router) {\n locale = router.locale;\n }\n\n // Currently RSC serialize dates to strings, therefore make sure we have\n // a date object. We might be able to remove this once more types have\n // first-class serialization support (https://github.com/facebook/react/issues/25687)\n if (typeof now === 'string') {\n now = new Date(now);\n }\n\n if (!locale) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? \"Couldn't determine locale. Please pass an explicit `locale` prop the provider, or if you're using the `pages` folder, use internationalized routing (https://nextjs.org/docs/advanced-features/i18n-routing).\"\n : undefined\n );\n }\n\n return (\n <IntlProvider locale={locale} now={now} {...rest}>\n {children}\n </IntlProvider>\n );\n}\n"],"names":["_excluded","NextIntlClientProvider","_ref","router","children","locale","now","rest","_objectWithoutPropertiesLoose","useRouter","error","Date","Error","undefined","React","createElement","IntlProvider","_extends"],"mappings":"6bAAa,IAAAA,EAAA,CAAA,WAAA,SAAA,OAYW,SAAAC,EAAsBC,GAKtC,IACFC,EALJC,EAAQF,EAARE,SACAC,EAAMH,EAANG,OACAC,EAAGJ,EAAHI,IACGC,oIAAIC,CAAAN,EAAAF,GAGP,IAGEG,EAASM,EAASA,WACnB,CAAC,MAAOC,GACP,CAgBF,IAXKL,GAAUF,IACbE,EAASF,EAAOE,QAMC,iBAARC,IACTA,EAAM,IAAIK,KAAKL,KAGZD,EACH,MAAM,IAAIO,WAGJC,GAIR,OACEC,UAACC,cAAAC,EAAYA,aAAAC,EAAA,CAACZ,OAAQA,EAAQC,IAAKA,GAASC,GACzCH,EAGP"}
|
package/dist/next-intl.esm.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export { LocalizedLink } from './react-client/next-intl.esm.js';
|
|
2
|
-
export { default as NextIntlClientProvider, default as NextIntlProvider } from './shared/next-intl.esm.js';
|
|
3
|
-
export { default as Link } from './react-client/next-intl.esm2.js';
|
|
4
|
-
export { default as useLocalizedRouter } from './react-client/next-intl.esm3.js';
|
|
5
1
|
export * from 'use-intl';
|
|
2
|
+
export { default as NextIntlClientProvider, default as NextIntlProvider } from './shared/next-intl.esm.js';
|
|
6
3
|
//# sourceMappingURL=next-intl.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"next-intl.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -7,11 +7,6 @@
|
|
|
7
7
|
* - Make sure everything exported from this module is
|
|
8
8
|
* supported in all Next.js versions that are supported.
|
|
9
9
|
*/
|
|
10
|
-
import Link from './Link';
|
|
11
10
|
export * from 'use-intl';
|
|
12
11
|
export { default as NextIntlClientProvider } from '../shared/NextIntlClientProvider';
|
|
13
12
|
export { default as NextIntlProvider } from '../shared/NextIntlClientProvider';
|
|
14
|
-
/** @deprecated Is available as `import Link from 'next-intl/link'` now. */
|
|
15
|
-
export declare const LocalizedLink: typeof Link;
|
|
16
|
-
export { default as Link } from './Link';
|
|
17
|
-
export { default as useLocalizedRouter } from './useLocalizedRouter';
|
|
@@ -5,15 +5,13 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Make sure this mirrors the API from '../react-client'.
|
|
7
7
|
*/
|
|
8
|
-
import Link from './Link';
|
|
9
|
-
export { default as useLocale } from './useLocale';
|
|
10
|
-
export { default as useTranslations } from './useTranslations';
|
|
11
|
-
export { default as useIntl } from './useIntl';
|
|
12
|
-
export { default as useFormatter } from './useFormatter';
|
|
13
|
-
export { default as useNow } from './useNow';
|
|
14
|
-
export { default as useTimeZone } from './useTimeZone';
|
|
15
|
-
export { default as NextIntlClientProvider } from '../shared/NextIntlClientProvider';
|
|
16
8
|
export * from 'use-intl/dist/src/core';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export
|
|
9
|
+
export { default as NextIntlClientProvider } from '../shared/NextIntlClientProvider';
|
|
10
|
+
declare function notSupported(): void;
|
|
11
|
+
export declare const IntlProvider: typeof notSupported;
|
|
12
|
+
export declare const useTranslations: typeof notSupported;
|
|
13
|
+
export declare const useIntl: typeof notSupported;
|
|
14
|
+
export declare const useLocale: typeof notSupported;
|
|
15
|
+
export declare const useNow: typeof notSupported;
|
|
16
|
+
export declare const useTimeZone: typeof notSupported;
|
|
17
|
+
export declare const Link: typeof notSupported;
|
package/dist/server/index.d.ts
CHANGED
|
@@ -3,12 +3,4 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import MiddlewareConfig from '../middleware/NextIntlMiddlewareConfig';
|
|
5
5
|
/** @deprecated Should be imported as `import createMiddleware from 'next-intl/middleware', not from `next-intl/server`. */
|
|
6
|
-
export declare function createIntlMiddleware(config: MiddlewareConfig): (request: import("next/server").NextRequest) => import("next/server").NextResponse
|
|
7
|
-
export { default as getRequestConfig } from './getRequestConfig';
|
|
8
|
-
export { default as getIntl } from './getIntl';
|
|
9
|
-
export { default as getFormatter } from './getFormatter';
|
|
10
|
-
export { default as getLocale } from './getLocale';
|
|
11
|
-
export { default as getNow } from './getNow';
|
|
12
|
-
export { default as getTimeZone } from './getTimeZone';
|
|
13
|
-
export { default as getTranslations } from './getTranslations';
|
|
14
|
-
export { default as redirect } from './redirect';
|
|
6
|
+
export declare function createIntlMiddleware(config: MiddlewareConfig): (request: import("next/server").NextRequest) => import("next/server").NextResponse<unknown>;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Client-only APIs available via `next-intl/client`.
|
|
3
3
|
*/
|
|
4
|
-
import usePathname from './usePathname';
|
|
5
|
-
import useRouter from './useRouter';
|
|
6
4
|
export { default as useRouter } from './useRouter';
|
|
7
5
|
export { default as usePathname } from './usePathname';
|
|
8
|
-
/** @deprecated Is called `usePathname` now. */
|
|
9
|
-
export declare const useUnlocalizedPathname: typeof usePathname;
|
|
10
|
-
/** @deprecated Is called `useRouter` now. */
|
|
11
|
-
export declare const useLocalizedRouter: typeof useRouter;
|
|
12
6
|
export { default as NextIntlClientProvider } from './NextIntlClientProvider';
|
package/dist/src/client/index.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Client-only APIs available via `next-intl/client`.
|
|
3
3
|
*/
|
|
4
|
-
import usePathname from './usePathname';
|
|
5
|
-
import useRouter from './useRouter';
|
|
6
4
|
export { default as useRouter } from './useRouter';
|
|
7
5
|
export { default as usePathname } from './usePathname';
|
|
8
|
-
/** @deprecated Is called `usePathname` now. */
|
|
9
|
-
export const useUnlocalizedPathname = usePathname;
|
|
10
|
-
/** @deprecated Is called `useRouter` now. */
|
|
11
|
-
export const useLocalizedRouter = useRouter;
|
|
12
6
|
// Legacy export (deprecation is handled by component)
|
|
13
7
|
export { default as NextIntlClientProvider } from './NextIntlClientProvider';
|
|
14
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,aAAa,CAAC;AACjD,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,eAAe,CAAC;AAErD,sDAAsD;AACtD,OAAO,EAAC,OAAO,IAAI,sBAAsB,EAAC,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
type RoutingConfigPrefix = {
|
|
2
|
-
type: 'prefix';
|
|
3
|
-
/** The default locale can be used without a prefix (e.g. `/about`). If you prefer to have a prefix for the default locale as well (e.g. `/en/about`), you can switch this option to `always`.
|
|
4
|
-
*/
|
|
5
|
-
prefix?: 'as-needed' | 'always';
|
|
6
|
-
};
|
|
7
|
-
type RoutingConfigDomain = {
|
|
8
|
-
type: 'domain';
|
|
9
|
-
/** Provide a list of mappings between domains and locales. Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
|
|
10
|
-
domains: Array<{
|
|
11
|
-
domain: string;
|
|
12
|
-
locale: string;
|
|
13
|
-
}>;
|
|
14
|
-
};
|
|
15
1
|
type LocalePrefix = 'as-needed' | 'always';
|
|
16
2
|
type RoutingBaseConfig = {
|
|
17
3
|
/** A list of all locales that are supported. */
|
|
@@ -25,8 +11,6 @@ export type DomainConfig = Omit<RoutingBaseConfig, 'locales' | 'localePrefix'> &
|
|
|
25
11
|
/** The domain name (e.g. "example.com", "www.example.com" or "fr.example.com"). Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
|
|
26
12
|
domain: string;
|
|
27
13
|
locales?: RoutingBaseConfig['locales'];
|
|
28
|
-
/** @deprecated Use `defaultLocale` instead. */
|
|
29
|
-
locale?: string;
|
|
30
14
|
};
|
|
31
15
|
type MiddlewareConfig = RoutingBaseConfig & {
|
|
32
16
|
/** Can be used to change the locale handling per domain. */
|
|
@@ -35,8 +19,6 @@ type MiddlewareConfig = RoutingBaseConfig & {
|
|
|
35
19
|
localeDetection?: boolean;
|
|
36
20
|
/** Sets the `Link` response header to notify search engines about content in other languages (defaults to `true`). See https://developers.google.com/search/docs/specialty/international/localized-versions#http */
|
|
37
21
|
alternateLinks?: boolean;
|
|
38
|
-
/** @deprecated Deprecated in favor of `localePrefix` and `domains`. */
|
|
39
|
-
routing?: RoutingConfigPrefix | RoutingConfigDomain;
|
|
40
22
|
};
|
|
41
23
|
export type MiddlewareConfigWithDefaults = MiddlewareConfig & {
|
|
42
24
|
alternateLinks: boolean;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import MiddlewareConfig from './NextIntlMiddlewareConfig';
|
|
3
|
-
export default function createMiddleware(config: MiddlewareConfig): (request: NextRequest) => NextResponse
|
|
3
|
+
export default function createMiddleware(config: MiddlewareConfig): (request: NextRequest) => NextResponse<unknown>;
|