next-intl 3.21.0-canary.0 → 3.21.2-canary.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.
Files changed (63) hide show
  1. package/dist/development/middleware/middleware.js +13 -11
  2. package/dist/development/middleware/resolveLocale.js +19 -28
  3. package/dist/development/middleware/syncCookie.js +8 -7
  4. package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +6 -1
  5. package/dist/development/navigation/react-client/createNavigation.js +1 -1
  6. package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +6 -1
  7. package/dist/development/navigation/react-client/useBaseRouter.js +3 -3
  8. package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -0
  9. package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +2 -0
  10. package/dist/development/navigation/shared/BaseLink.js +2 -1
  11. package/dist/development/navigation/shared/LegacyBaseLink.js +3 -1
  12. package/dist/development/navigation/shared/createSharedNavigationFns.js +2 -1
  13. package/dist/development/navigation/shared/syncLocaleCookie.js +26 -5
  14. package/dist/development/routing/config.js +18 -1
  15. package/dist/development/shared/constants.js +0 -9
  16. package/dist/esm/middleware/middleware.js +1 -1
  17. package/dist/esm/middleware/resolveLocale.js +1 -1
  18. package/dist/esm/middleware/syncCookie.js +1 -1
  19. package/dist/esm/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
  20. package/dist/esm/navigation/react-client/createNavigation.js +1 -1
  21. package/dist/esm/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
  22. package/dist/esm/navigation/react-client/useBaseRouter.js +1 -1
  23. package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  24. package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
  25. package/dist/esm/navigation/shared/BaseLink.js +1 -1
  26. package/dist/esm/navigation/shared/LegacyBaseLink.js +1 -1
  27. package/dist/esm/navigation/shared/createSharedNavigationFns.js +1 -1
  28. package/dist/esm/navigation/shared/syncLocaleCookie.js +1 -1
  29. package/dist/esm/routing/config.js +1 -1
  30. package/dist/esm/shared/constants.js +1 -1
  31. package/dist/production/middleware/middleware.js +1 -1
  32. package/dist/production/middleware/resolveLocale.js +1 -1
  33. package/dist/production/middleware/syncCookie.js +1 -1
  34. package/dist/production/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
  35. package/dist/production/navigation/react-client/createNavigation.js +1 -1
  36. package/dist/production/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
  37. package/dist/production/navigation/react-client/useBaseRouter.js +1 -1
  38. package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  39. package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
  40. package/dist/production/navigation/shared/BaseLink.js +1 -1
  41. package/dist/production/navigation/shared/LegacyBaseLink.js +1 -1
  42. package/dist/production/navigation/shared/createSharedNavigationFns.js +1 -1
  43. package/dist/production/navigation/shared/syncLocaleCookie.js +1 -1
  44. package/dist/production/routing/config.js +1 -1
  45. package/dist/production/shared/constants.js +1 -1
  46. package/dist/types/src/middleware/middleware.d.ts +10 -2
  47. package/dist/types/src/middleware/resolveLocale.d.ts +1 -2
  48. package/dist/types/src/middleware/syncCookie.d.ts +2 -1
  49. package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.d.ts +5 -1
  50. package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +5 -1
  51. package/dist/types/src/navigation/react-client/useBaseRouter.d.ts +2 -1
  52. package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +2 -1
  53. package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +1 -1
  54. package/dist/types/src/navigation/shared/BaseLink.d.ts +2 -0
  55. package/dist/types/src/navigation/shared/LegacyBaseLink.d.ts +2 -0
  56. package/dist/types/src/navigation/shared/createSharedNavigationFns.d.ts +4 -1
  57. package/dist/types/src/navigation/shared/syncLocaleCookie.d.ts +2 -1
  58. package/dist/types/src/react-server/getTranslator.d.ts +9 -0
  59. package/dist/types/src/routing/config.d.ts +29 -2
  60. package/dist/types/src/server/react-server/getTranslations.d.ts +9 -0
  61. package/dist/types/src/shared/constants.d.ts +0 -3
  62. package/package.json +3 -3
  63. package/dist/types/src/middleware/config.d.ts +0 -7
@@ -11,13 +11,15 @@ var resolveLocale = require('./resolveLocale.js');
11
11
  var syncCookie = require('./syncCookie.js');
12
12
  var utils = require('./utils.js');
13
13
 
14
- function createMiddleware(routing, options) {
15
- var _ref, _options$alternateLin, _ref2, _options$localeDetect;
16
- const resolvedRouting = config.receiveRoutingConfig(routing);
17
- const resolvedOptions = {
18
- alternateLinks: (_ref = (_options$alternateLin = options === null || options === void 0 ? void 0 : options.alternateLinks) !== null && _options$alternateLin !== void 0 ? _options$alternateLin : routing.alternateLinks) !== null && _ref !== void 0 ? _ref : true,
19
- localeDetection: (_ref2 = (_options$localeDetect = options === null || options === void 0 ? void 0 : options.localeDetection) !== null && _options$localeDetect !== void 0 ? _options$localeDetect : routing === null || routing === void 0 ? void 0 : routing.localeDetection) !== null && _ref2 !== void 0 ? _ref2 : true
20
- };
14
+ function createMiddleware(routing, /** @deprecated Should be passed via the first parameter `routing` instead (ideally defined with `defineRouting`) */
15
+ options) {
16
+ var _options$alternateLin, _options$localeDetect, _options$localeCookie;
17
+ const resolvedRouting = config.receiveRoutingConfig({
18
+ ...routing,
19
+ alternateLinks: (_options$alternateLin = options === null || options === void 0 ? void 0 : options.alternateLinks) !== null && _options$alternateLin !== void 0 ? _options$alternateLin : routing.alternateLinks,
20
+ localeDetection: (_options$localeDetect = options === null || options === void 0 ? void 0 : options.localeDetection) !== null && _options$localeDetect !== void 0 ? _options$localeDetect : routing.localeDetection,
21
+ localeCookie: (_options$localeCookie = options === null || options === void 0 ? void 0 : options.localeCookie) !== null && _options$localeCookie !== void 0 ? _options$localeCookie : routing.localeCookie
22
+ });
21
23
  return function middleware(request) {
22
24
  var _resolvedRouting$doma;
23
25
  let unsafeExternalPathname;
@@ -36,7 +38,7 @@ function createMiddleware(routing, options) {
36
38
  const {
37
39
  domain,
38
40
  locale
39
- } = resolveLocale.default(resolvedRouting, resolvedOptions, request.headers, request.cookies, externalPathname);
41
+ } = resolveLocale.default(resolvedRouting, request.headers, request.cookies, externalPathname);
40
42
  const hasMatchedDefaultLocale = domain ? domain.defaultLocale === locale : locale === resolvedRouting.defaultLocale;
41
43
  const domainsConfig = ((_resolvedRouting$doma = resolvedRouting.domains) === null || _resolvedRouting$doma === void 0 ? void 0 : _resolvedRouting$doma.filter(curDomain => utils.isLocaleSupportedOnDomain(locale, curDomain))) || [];
42
44
  const hasUnknownHost = resolvedRouting.domains != null && !domain;
@@ -153,10 +155,10 @@ function createMiddleware(routing, options) {
153
155
  }
154
156
  }
155
157
  }
156
- if (resolvedOptions.localeDetection) {
157
- syncCookie.default(request, response, locale);
158
+ if (resolvedRouting.localeDetection && resolvedRouting.localeCookie) {
159
+ syncCookie.default(request, response, locale, resolvedRouting.localeCookie);
158
160
  }
159
- if (resolvedRouting.localePrefix.mode !== 'never' && resolvedOptions.alternateLinks && resolvedRouting.locales.length > 1) {
161
+ if (resolvedRouting.localePrefix.mode !== 'never' && resolvedRouting.alternateLinks && resolvedRouting.locales.length > 1) {
160
162
  response.headers.set('Link', getAlternateLinksHeaderValue.default({
161
163
  routing: resolvedRouting,
162
164
  localizedPathnames: internalTemplateName != null && pathnames ? pathnames === null || pathnames === void 0 ? void 0 : pathnames[internalTemplateName] : undefined,
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var intlLocalematcher = require('@formatjs/intl-localematcher');
6
6
  var Negotiator = require('negotiator');
7
- var constants = require('../shared/constants.js');
8
7
  var utils = require('./utils.js');
9
8
 
10
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -37,54 +36,46 @@ function getAcceptLanguageLocale(requestHeaders, locales, defaultLocale) {
37
36
  }
38
37
  return locale;
39
38
  }
40
- function getLocaleFromCookie(requestCookies, locales) {
41
- if (requestCookies.has(constants.COOKIE_LOCALE_NAME)) {
39
+ function getLocaleFromCookie(routing, requestCookies) {
40
+ if (routing.localeCookie && requestCookies.has(routing.localeCookie.name)) {
42
41
  var _requestCookies$get;
43
- const value = (_requestCookies$get = requestCookies.get(constants.COOKIE_LOCALE_NAME)) === null || _requestCookies$get === void 0 ? void 0 : _requestCookies$get.value;
44
- if (value && locales.includes(value)) {
42
+ const value = (_requestCookies$get = requestCookies.get(routing.localeCookie.name)) === null || _requestCookies$get === void 0 ? void 0 : _requestCookies$get.value;
43
+ if (value && routing.locales.includes(value)) {
45
44
  return value;
46
45
  }
47
46
  }
48
47
  }
49
- function resolveLocaleFromPrefix(_ref, _ref2, requestHeaders, requestCookies, pathname) {
50
- let {
51
- defaultLocale,
52
- localePrefix,
53
- locales
54
- } = _ref;
55
- let {
56
- localeDetection
57
- } = _ref2;
48
+ function resolveLocaleFromPrefix(routing, requestHeaders, requestCookies, pathname) {
58
49
  let locale;
59
50
 
60
51
  // Prio 1: Use route prefix
61
52
  if (pathname) {
62
53
  var _getPathnameMatch;
63
- locale = (_getPathnameMatch = utils.getPathnameMatch(pathname, locales, localePrefix)) === null || _getPathnameMatch === void 0 ? void 0 : _getPathnameMatch.locale;
54
+ locale = (_getPathnameMatch = utils.getPathnameMatch(pathname, routing.locales, routing.localePrefix)) === null || _getPathnameMatch === void 0 ? void 0 : _getPathnameMatch.locale;
64
55
  }
65
56
 
66
57
  // Prio 2: Use existing cookie
67
- if (!locale && localeDetection && requestCookies) {
68
- locale = getLocaleFromCookie(requestCookies, locales);
58
+ if (!locale && routing.localeDetection && requestCookies) {
59
+ locale = getLocaleFromCookie(routing, requestCookies);
69
60
  }
70
61
 
71
62
  // Prio 3: Use the `accept-language` header
72
- if (!locale && localeDetection && requestHeaders) {
73
- locale = getAcceptLanguageLocale(requestHeaders, locales, defaultLocale);
63
+ if (!locale && routing.localeDetection && requestHeaders) {
64
+ locale = getAcceptLanguageLocale(requestHeaders, routing.locales, routing.defaultLocale);
74
65
  }
75
66
 
76
67
  // Prio 4: Use default locale
77
68
  if (!locale) {
78
- locale = defaultLocale;
69
+ locale = routing.defaultLocale;
79
70
  }
80
71
  return locale;
81
72
  }
82
- function resolveLocaleFromDomain(routing, options, requestHeaders, requestCookies, pathname) {
73
+ function resolveLocaleFromDomain(routing, requestHeaders, requestCookies, pathname) {
83
74
  const domains = routing.domains;
84
75
  const domain = findDomainFromHost(requestHeaders, domains);
85
76
  if (!domain) {
86
77
  return {
87
- locale: resolveLocaleFromPrefix(routing, options, requestHeaders, requestCookies, pathname)
78
+ locale: resolveLocaleFromPrefix(routing, requestHeaders, requestCookies, pathname)
88
79
  };
89
80
  }
90
81
  let locale;
@@ -107,8 +98,8 @@ function resolveLocaleFromDomain(routing, options, requestHeaders, requestCookie
107
98
  }
108
99
 
109
100
  // Prio 2: Use existing cookie
110
- if (!locale && options.localeDetection && requestCookies) {
111
- const cookieLocale = getLocaleFromCookie(requestCookies, routing.locales);
101
+ if (!locale && routing.localeDetection && requestCookies) {
102
+ const cookieLocale = getLocaleFromCookie(routing, requestCookies);
112
103
  if (cookieLocale) {
113
104
  if (utils.isLocaleSupportedOnDomain(cookieLocale, domain)) {
114
105
  locale = cookieLocale;
@@ -117,7 +108,7 @@ function resolveLocaleFromDomain(routing, options, requestHeaders, requestCookie
117
108
  }
118
109
 
119
110
  // Prio 3: Use the `accept-language` header
120
- if (!locale && options.localeDetection && requestHeaders) {
111
+ if (!locale && routing.localeDetection && requestHeaders) {
121
112
  const headerLocale = getAcceptLanguageLocale(requestHeaders, domain.locales || routing.locales, domain.defaultLocale);
122
113
  if (headerLocale) {
123
114
  locale = headerLocale;
@@ -133,12 +124,12 @@ function resolveLocaleFromDomain(routing, options, requestHeaders, requestCookie
133
124
  domain
134
125
  };
135
126
  }
136
- function resolveLocale(routing, options, requestHeaders, requestCookies, pathname) {
127
+ function resolveLocale(routing, requestHeaders, requestCookies, pathname) {
137
128
  if (routing.domains) {
138
- return resolveLocaleFromDomain(routing, options, requestHeaders, requestCookies, pathname);
129
+ return resolveLocaleFromDomain(routing, requestHeaders, requestCookies, pathname);
139
130
  } else {
140
131
  return {
141
- locale: resolveLocaleFromPrefix(routing, options, requestHeaders, requestCookies, pathname)
132
+ locale: resolveLocaleFromPrefix(routing, requestHeaders, requestCookies, pathname)
142
133
  };
143
134
  }
144
135
  }
@@ -2,16 +2,17 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var constants = require('../shared/constants.js');
6
-
7
- function syncCookie(request, response, locale) {
5
+ function syncCookie(request, response, locale, localeCookie) {
8
6
  var _request$cookies$get;
9
- const hasOutdatedCookie = ((_request$cookies$get = request.cookies.get(constants.COOKIE_LOCALE_NAME)) === null || _request$cookies$get === void 0 ? void 0 : _request$cookies$get.value) !== locale;
7
+ const {
8
+ name,
9
+ ...rest
10
+ } = localeCookie;
11
+ const hasOutdatedCookie = ((_request$cookies$get = request.cookies.get(name)) === null || _request$cookies$get === void 0 ? void 0 : _request$cookies$get.value) !== locale;
10
12
  if (hasOutdatedCookie) {
11
- response.cookies.set(constants.COOKIE_LOCALE_NAME, locale, {
13
+ response.cookies.set(name, locale, {
12
14
  path: request.nextUrl.basePath || undefined,
13
- sameSite: constants.COOKIE_SAME_SITE,
14
- maxAge: constants.COOKIE_MAX_AGE
15
+ ...rest
15
16
  });
16
17
  }
17
18
  }
@@ -16,8 +16,12 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
16
 
17
17
  var React__default = /*#__PURE__*/_interopDefault(React);
18
18
 
19
+ /**
20
+ * @deprecated Consider switching to `createNavigation` (see https://github.com/amannn/next-intl/pull/1316)
21
+ **/
19
22
  function createLocalizedPathnamesNavigation(routing) {
20
23
  const config$1 = config.receiveRoutingConfig(routing);
24
+ const localeCookie = config.receiveLocaleCookie(routing === null || routing === void 0 ? void 0 : routing.localeCookie);
21
25
  function useTypedLocale() {
22
26
  const locale = useLocale.default();
23
27
  const isValid = config$1.locales.includes(locale);
@@ -45,6 +49,7 @@ function createLocalizedPathnamesNavigation(routing) {
45
49
  pathnames: config$1.pathnames
46
50
  }),
47
51
  locale: locale,
52
+ localeCookie: localeCookie,
48
53
  localePrefix: config$1.localePrefix
49
54
  }, rest));
50
55
  }
@@ -81,7 +86,7 @@ function createLocalizedPathnamesNavigation(routing) {
81
86
  }, ...args);
82
87
  }
83
88
  function useRouter() {
84
- const baseRouter = useBaseRouter.default(config$1.localePrefix);
89
+ const baseRouter = useBaseRouter.default(config$1.localePrefix, localeCookie);
85
90
  const defaultLocale = useTypedLocale();
86
91
  return React.useMemo(() => ({
87
92
  ...baseRouter,
@@ -57,7 +57,7 @@ function createNavigation(routing) {
57
57
  args.push(rest);
58
58
  }
59
59
  fn(...args);
60
- syncLocaleCookie.default(nextPathname, curLocale, nextLocale);
60
+ syncLocaleCookie.default(config.localeCookie, nextPathname, curLocale, nextLocale);
61
61
  };
62
62
  }
63
63
  return {
@@ -14,11 +14,16 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
15
  var React__default = /*#__PURE__*/_interopDefault(React);
16
16
 
17
+ /**
18
+ * @deprecated Consider switching to `createNavigation` (see https://github.com/amannn/next-intl/pull/1316)
19
+ **/
17
20
  function createSharedPathnamesNavigation(routing) {
18
21
  const localePrefix = config.receiveLocalePrefixConfig(routing === null || routing === void 0 ? void 0 : routing.localePrefix);
22
+ const localeCookie = config.receiveLocaleCookie(routing === null || routing === void 0 ? void 0 : routing.localeCookie);
19
23
  function Link(props, ref) {
20
24
  return /*#__PURE__*/React__default.default.createElement(ClientLink.default, _rollupPluginBabelHelpers.extends({
21
25
  ref: ref,
26
+ localeCookie: localeCookie,
22
27
  localePrefix: localePrefix
23
28
  }, props));
24
29
  }
@@ -48,7 +53,7 @@ function createSharedPathnamesNavigation(routing) {
48
53
  return result;
49
54
  }
50
55
  function useRouter() {
51
- return useBaseRouter.default(localePrefix);
56
+ return useBaseRouter.default(localePrefix, localeCookie);
52
57
  }
53
58
  return {
54
59
  Link: LinkWithRef,
@@ -28,7 +28,7 @@ var utils = require('../shared/utils.js');
28
28
  * router.push('/about', {locale: 'de'});
29
29
  * ```
30
30
  */
31
- function useBaseRouter(localePrefix) {
31
+ function useBaseRouter(localePrefix, localeCookie) {
32
32
  const router = navigation.useRouter();
33
33
  const locale = useLocale.default();
34
34
  const pathname = navigation.usePathname();
@@ -50,7 +50,7 @@ function useBaseRouter(localePrefix) {
50
50
  locale: nextLocale,
51
51
  ...rest
52
52
  } = options || {};
53
- syncLocaleCookie.default(pathname, locale, nextLocale);
53
+ syncLocaleCookie.default(localeCookie, pathname, locale, nextLocale);
54
54
  const args = [localize(href, nextLocale)];
55
55
  if (Object.keys(rest).length > 0) {
56
56
  args.push(rest);
@@ -66,7 +66,7 @@ function useBaseRouter(localePrefix) {
66
66
  replace: createHandler(router.replace),
67
67
  prefetch: createHandler(router.prefetch)
68
68
  };
69
- }, [locale, localePrefix, pathname, router]);
69
+ }, [locale, localeCookie, localePrefix, pathname, router]);
70
70
  }
71
71
 
72
72
  exports.default = useBaseRouter;
@@ -34,6 +34,7 @@ function createLocalizedPathnamesNavigation(routing) {
34
34
  pathnames: config$1.pathnames
35
35
  }),
36
36
  locale: locale,
37
+ localeCookie: config$1.localeCookie,
37
38
  localePrefix: config$1.localePrefix
38
39
  }, rest));
39
40
  }
@@ -14,6 +14,7 @@ var React__default = /*#__PURE__*/_interopDefault(React);
14
14
 
15
15
  function createSharedPathnamesNavigation(routing) {
16
16
  const localePrefix = config.receiveLocalePrefixConfig(routing === null || routing === void 0 ? void 0 : routing.localePrefix);
17
+ const localeCookie = config.receiveLocaleCookie(routing === null || routing === void 0 ? void 0 : routing.localeCookie);
17
18
  function notSupported(hookName) {
18
19
  return () => {
19
20
  throw new Error("`".concat(hookName, "` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."));
@@ -21,6 +22,7 @@ function createSharedPathnamesNavigation(routing) {
21
22
  }
22
23
  function Link(props) {
23
24
  return /*#__PURE__*/React__default.default.createElement(ServerLink.default, _rollupPluginBabelHelpers.extends({
25
+ localeCookie: localeCookie,
24
26
  localePrefix: localePrefix
25
27
  }, props));
26
28
  }
@@ -20,6 +20,7 @@ function BaseLink(_ref, ref) {
20
20
  defaultLocale,
21
21
  href,
22
22
  locale,
23
+ localeCookie,
23
24
  onClick,
24
25
  prefetch,
25
26
  unprefixed,
@@ -45,7 +46,7 @@ function BaseLink(_ref, ref) {
45
46
  // `useParams` can be called, but the return type is `null`.
46
47
  const pathname = navigation.usePathname();
47
48
  function onLinkClick(event) {
48
- syncLocaleCookie.default(pathname, curLocale, locale);
49
+ syncLocaleCookie.default(localeCookie, pathname, curLocale, locale);
49
50
  if (onClick) onClick(event);
50
51
  }
51
52
  if (isChangingLocale) {
@@ -18,6 +18,7 @@ function LegacyBaseLink(_ref, ref) {
18
18
  let {
19
19
  href,
20
20
  locale,
21
+ localeCookie,
21
22
  localePrefixMode,
22
23
  prefix,
23
24
  ...rest
@@ -46,7 +47,8 @@ function LegacyBaseLink(_ref, ref) {
46
47
  return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
47
48
  ref: ref,
48
49
  href: localizedHref,
49
- locale: locale
50
+ locale: locale,
51
+ localeCookie: localeCookie
50
52
  }, rest));
51
53
  }
52
54
  const LegacyBaseLinkWithRef = /*#__PURE__*/React.forwardRef(LegacyBaseLink);
@@ -69,7 +69,8 @@ function createSharedNavigationFns(getLocale, routing) {
69
69
  // @ts-expect-error -- This is ok
70
70
  pathname: finalPathname
71
71
  },
72
- locale: locale
72
+ locale: locale,
73
+ localeCookie: config$1.localeCookie
73
74
  // Provide the minimal relevant information to the client side in order
74
75
  // to potentially remove the prefix in case of the `forcePrefixSsr` case
75
76
  ,
@@ -2,7 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var constants = require('../../shared/constants.js');
6
5
  var utils = require('./utils.js');
7
6
 
8
7
  /**
@@ -10,9 +9,9 @@ var utils = require('./utils.js');
10
9
  * skip a request to the server due to its router cache.
11
10
  * See https://github.com/amannn/next-intl/issues/786.
12
11
  */
13
- function syncLocaleCookie(pathname, locale, nextLocale) {
12
+ function syncLocaleCookie(localeCookie, pathname, locale, nextLocale) {
14
13
  const isSwitchingLocale = nextLocale !== locale && nextLocale != null;
15
- if (!isSwitchingLocale ||
14
+ if (!localeCookie || !isSwitchingLocale ||
16
15
  // Theoretical case, we always have a pathname in a real app,
17
16
  // only not when running e.g. in a simulated test environment
18
17
  !pathname) {
@@ -20,11 +19,33 @@ function syncLocaleCookie(pathname, locale, nextLocale) {
20
19
  }
21
20
  const basePath = utils.getBasePath(pathname);
22
21
  const hasBasePath = basePath !== '';
23
- const path = hasBasePath ? basePath : '/';
22
+ const defaultPath = hasBasePath ? basePath : '/';
23
+ const {
24
+ name,
25
+ ...rest
26
+ } = localeCookie;
27
+ if (!rest.path) {
28
+ rest.path = defaultPath;
29
+ }
30
+ let localeCookieString = "".concat(name, "=").concat(nextLocale, ";");
31
+ for (const [key, value] of Object.entries(rest)) {
32
+ // Map object properties to cookie properties.
33
+ // Interestingly, `maxAge` corresponds to `max-age`,
34
+ // while `sameSite` corresponds to `SameSite`.
35
+ // Also, keys are case-insensitive.
36
+ const targetKey = key === 'maxAge' ? 'max-age' : key;
37
+ localeCookieString += "".concat(targetKey);
38
+ if (typeof value !== 'boolean') {
39
+ localeCookieString += '=' + value;
40
+ }
41
+
42
+ // A trailing ";" is allowed by browsers
43
+ localeCookieString += ';';
44
+ }
24
45
 
25
46
  // Note that writing to `document.cookie` doesn't overwrite all
26
47
  // cookies, but only the ones referenced via the name here.
27
- document.cookie = "".concat(constants.COOKIE_LOCALE_NAME, "=").concat(nextLocale, "; path=").concat(path, "; max-age=").concat(constants.COOKIE_MAX_AGE, "; sameSite=").concat(constants.COOKIE_SAME_SITE);
48
+ document.cookie = localeCookieString;
28
49
  }
29
50
 
30
51
  exports.default = syncLocaleCookie;
@@ -3,16 +3,33 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function receiveRoutingConfig(input) {
6
+ var _input$localeDetectio, _input$alternateLinks;
6
7
  return {
7
8
  ...input,
8
- localePrefix: receiveLocalePrefixConfig(input === null || input === void 0 ? void 0 : input.localePrefix)
9
+ localePrefix: receiveLocalePrefixConfig(input === null || input === void 0 ? void 0 : input.localePrefix),
10
+ localeCookie: receiveLocaleCookie(input.localeCookie),
11
+ localeDetection: (_input$localeDetectio = input.localeDetection) !== null && _input$localeDetectio !== void 0 ? _input$localeDetectio : true,
12
+ alternateLinks: (_input$alternateLinks = input.alternateLinks) !== null && _input$alternateLinks !== void 0 ? _input$alternateLinks : true
9
13
  };
10
14
  }
15
+ function receiveLocaleCookie(localeCookie) {
16
+ return (localeCookie !== null && localeCookie !== void 0 ? localeCookie : true) ? {
17
+ name: 'NEXT_LOCALE',
18
+ maxAge: 31536000,
19
+ // 1 year
20
+ sameSite: 'lax',
21
+ ...(typeof localeCookie === 'object' && localeCookie)
22
+
23
+ // `path` needs to be provided based on a detected base path
24
+ // that depends on the environment when setting a cookie
25
+ } : false;
26
+ }
11
27
  function receiveLocalePrefixConfig(localePrefix) {
12
28
  return typeof localePrefix === 'object' ? localePrefix : {
13
29
  mode: localePrefix || 'always'
14
30
  };
15
31
  }
16
32
 
33
+ exports.receiveLocaleCookie = receiveLocaleCookie;
17
34
  exports.receiveLocalePrefixConfig = receiveLocalePrefixConfig;
18
35
  exports.receiveRoutingConfig = receiveRoutingConfig;
@@ -2,20 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- // Reuse the legacy cookie name
6
- // https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie
7
- const COOKIE_LOCALE_NAME = 'NEXT_LOCALE';
8
- const COOKIE_MAX_AGE = 31536000; // 1 year
9
- const COOKIE_SAME_SITE = 'lax';
10
-
11
5
  // Should take precedence over the cookie
12
6
  const HEADER_LOCALE_NAME = 'X-NEXT-INTL-LOCALE';
13
7
 
14
8
  // In a URL like "/en-US/about", the locale segment is "en-US"
15
9
  const LOCALE_SEGMENT_NAME = 'locale';
16
10
 
17
- exports.COOKIE_LOCALE_NAME = COOKIE_LOCALE_NAME;
18
- exports.COOKIE_MAX_AGE = COOKIE_MAX_AGE;
19
- exports.COOKIE_SAME_SITE = COOKIE_SAME_SITE;
20
11
  exports.HEADER_LOCALE_NAME = HEADER_LOCALE_NAME;
21
12
  exports.LOCALE_SEGMENT_NAME = LOCALE_SEGMENT_NAME;
@@ -1 +1 @@
1
- import{NextResponse as e}from"next/server";import{receiveRoutingConfig as l}from"../routing/config.js";import{HEADER_LOCALE_NAME as o}from"../shared/constants.js";import{matchesPathname as t,normalizeTrailingSlash as r,getLocalePrefix as n}from"../shared/utils.js";import a from"./getAlternateLinksHeaderValue.js";import i from"./resolveLocale.js";import s from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as u,getInternalTemplate as m,formatTemplatePathname as h,formatPathname as x,getBestMatchingDomain as v,applyBasePath as p,getLocaleAsPrefix as U}from"./utils.js";function P(P,L){var g,k,j,w;const b=l(P),y={alternateLinks:null===(g=null!==(k=null==L?void 0:L.alternateLinks)&&void 0!==k?k:P.alternateLinks)||void 0===g||g,localeDetection:null===(j=null!==(w=null==L?void 0:L.localeDetection)&&void 0!==w?w:null==P?void 0:P.localeDetection)||void 0===j||j};return function(l){var P;let L;try{L=decodeURI(l.nextUrl.pathname)}catch(l){return e.next()}const g=c(L),{domain:k,locale:j}=i(b,y,l.headers,l.cookies,g),w=k?k.defaultLocale===j:j===b.defaultLocale,D=(null===(P=b.domains)||void 0===P?void 0:P.filter((e=>d(j,e))))||[],R=null!=b.domains&&!k;function q(t){const r=new URL(t,l.url);l.nextUrl.basePath&&(r.pathname=p(r.pathname,l.nextUrl.basePath));const n=new Headers(l.headers);return n.set(o,j),e.rewrite(r,{request:{headers:n}})}function H(o,t){const n=new URL(r(o),l.url);if(D.length>0&&!t&&k){const e=v(k,j,D);e&&(t=e.domain,e.defaultLocale===j&&"as-needed"===b.localePrefix.mode&&(n.pathname=f(n.pathname,b.locales,b.localePrefix)))}var a,i;t&&(n.host=t,l.headers.get("x-forwarded-host")&&(n.protocol=null!==(a=l.headers.get("x-forwarded-proto"))&&void 0!==a?a:l.nextUrl.protocol,n.port=null!==(i=l.headers.get("x-forwarded-port"))&&void 0!==i?i:""));return l.nextUrl.basePath&&(n.pathname=p(n.pathname,l.nextUrl.basePath)),e.redirect(n.toString())}const z=f(g,b.locales,b.localePrefix),A=u(g,b.locales,b.localePrefix),C=null!=A,I="never"===b.localePrefix.mode||w&&"as-needed"===b.localePrefix.mode;let S,V,B=z;const E=b.pathnames;if(E){let e;if([e,V]=m(E,z,j),V){const o=E[V],r="string"==typeof o?o:o[j];if(t(r,z))B=h(z,r,V);else{let t;t=e?"string"==typeof o?o:o[e]:V;const a=I?void 0:n(j,b.localePrefix),i=h(z,t,r);S=H(x(i,a,l.nextUrl.search))}}}if(!S)if("/"!==B||C){const e=x(B,U(j),l.nextUrl.search);if(C){const o=x(z,A.prefix,l.nextUrl.search);if("never"===b.localePrefix.mode)S=H(x(z,void 0,l.nextUrl.search));else if(A.exact)if(w&&I)S=H(x(z,void 0,l.nextUrl.search));else if(b.domains){const l=v(k,A.locale,D);S=(null==k?void 0:k.domain)===(null==l?void 0:l.domain)||R?q(e):H(o,null==l?void 0:l.domain)}else S=q(e);else S=H(o)}else S=I?q(e):H(x(z,n(j,b.localePrefix),l.nextUrl.search))}else S=I?q(x(B,U(j),l.nextUrl.search)):H(x(z,n(j,b.localePrefix),l.nextUrl.search));return y.localeDetection&&s(l,S,j),"never"!==b.localePrefix.mode&&y.alternateLinks&&b.locales.length>1&&S.headers.set("Link",a({routing:b,localizedPathnames:null!=V&&E?null==E?void 0:E[V]:void 0,request:l,resolvedLocale:j})),S}}export{P as default};
1
+ import{NextResponse as e}from"next/server";import{receiveRoutingConfig as o}from"../routing/config.js";import{HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as t,normalizeTrailingSlash as r,getLocalePrefix as a}from"../shared/utils.js";import n from"./getAlternateLinksHeaderValue.js";import i from"./resolveLocale.js";import s from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as m,getInternalTemplate as u,formatTemplatePathname as h,formatPathname as x,getBestMatchingDomain as v,applyBasePath as p,getLocaleAsPrefix as U}from"./utils.js";function P(P,k){var L,g,j;const w=o({...P,alternateLinks:null!==(L=null==k?void 0:k.alternateLinks)&&void 0!==L?L:P.alternateLinks,localeDetection:null!==(g=null==k?void 0:k.localeDetection)&&void 0!==g?g:P.localeDetection,localeCookie:null!==(j=null==k?void 0:k.localeCookie)&&void 0!==j?j:P.localeCookie});return function(o){var P;let k;try{k=decodeURI(o.nextUrl.pathname)}catch(o){return e.next()}const L=c(k),{domain:g,locale:j}=i(w,o.headers,o.cookies,L),C=g?g.defaultLocale===j:j===w.defaultLocale,b=(null===(P=w.domains)||void 0===P?void 0:P.filter((e=>d(j,e))))||[],y=null!=w.domains&&!g;function D(t){const r=new URL(t,o.url);o.nextUrl.basePath&&(r.pathname=p(r.pathname,o.nextUrl.basePath));const a=new Headers(o.headers);return a.set(l,j),e.rewrite(r,{request:{headers:a}})}function R(l,t){const a=new URL(r(l),o.url);if(b.length>0&&!t&&g){const e=v(g,j,b);e&&(t=e.domain,e.defaultLocale===j&&"as-needed"===w.localePrefix.mode&&(a.pathname=f(a.pathname,w.locales,w.localePrefix)))}var n,i;t&&(a.host=t,o.headers.get("x-forwarded-host")&&(a.protocol=null!==(n=o.headers.get("x-forwarded-proto"))&&void 0!==n?n:o.nextUrl.protocol,a.port=null!==(i=o.headers.get("x-forwarded-port"))&&void 0!==i?i:""));return o.nextUrl.basePath&&(a.pathname=p(a.pathname,o.nextUrl.basePath)),e.redirect(a.toString())}const q=f(L,w.locales,w.localePrefix),H=m(L,w.locales,w.localePrefix),z=null!=H,A="never"===w.localePrefix.mode||C&&"as-needed"===w.localePrefix.mode;let I,S,V=q;const B=w.pathnames;if(B){let e;if([e,S]=u(B,q,j),S){const l=B[S],r="string"==typeof l?l:l[j];if(t(r,q))V=h(q,r,S);else{let t;t=e?"string"==typeof l?l:l[e]:S;const n=A?void 0:a(j,w.localePrefix),i=h(q,t,r);I=R(x(i,n,o.nextUrl.search))}}}if(!I)if("/"!==V||z){const e=x(V,U(j),o.nextUrl.search);if(z){const l=x(q,H.prefix,o.nextUrl.search);if("never"===w.localePrefix.mode)I=R(x(q,void 0,o.nextUrl.search));else if(H.exact)if(C&&A)I=R(x(q,void 0,o.nextUrl.search));else if(w.domains){const o=v(g,H.locale,b);I=(null==g?void 0:g.domain)===(null==o?void 0:o.domain)||y?D(e):R(l,null==o?void 0:o.domain)}else I=D(e);else I=R(l)}else I=A?D(e):R(x(q,a(j,w.localePrefix),o.nextUrl.search))}else I=A?D(x(V,U(j),o.nextUrl.search)):R(x(q,a(j,w.localePrefix),o.nextUrl.search));return w.localeDetection&&w.localeCookie&&s(o,I,j,w.localeCookie),"never"!==w.localePrefix.mode&&w.alternateLinks&&w.locales.length>1&&I.headers.set("Link",n({routing:w,localizedPathnames:null!=S&&B?null==B?void 0:B[S]:void 0,request:o,resolvedLocale:j})),I}}export{P as default};
@@ -1 +1 @@
1
- import{match as o}from"@formatjs/intl-localematcher";import e from"negotiator";import{COOKIE_LOCALE_NAME as l}from"../shared/constants.js";import{getPathnameMatch as t,isLocaleSupportedOnDomain as n,getHost as a}from"./utils.js";function c(l,t,n){let a;const c=new e({headers:{"accept-language":l.get("accept-language")||void 0}}).languages();try{const e=function(o){return o.slice().sort(((o,e)=>e.length-o.length))}(t);a=o(c,e,n)}catch(o){}return a}function i(o,e){if(o.has(l)){var t;const n=null===(t=o.get(l))||void 0===t?void 0:t.value;if(n&&e.includes(n))return n}}function r(o,e,l,n,a){let r,{defaultLocale:s,localePrefix:u,locales:f}=o,{localeDetection:d}=e;var m;a&&(r=null===(m=t(a,f,u))||void 0===m?void 0:m.locale);return!r&&d&&n&&(r=i(n,f)),!r&&d&&l&&(r=c(l,f,s)),r||(r=s),r}function s(o,e,l,s,u){const f=function(o,e){const l=a(o);if(l&&e)return e.find((o=>o.domain===l))}(l,o.domains);if(!f)return{locale:r(o,e,l,s,u)};let d;if(u){var m;const e=null===(m=t(u,o.locales,o.localePrefix))||void 0===m?void 0:m.locale;if(e){if(!n(e,f))return{locale:e,domain:f};d=e}}if(!d&&e.localeDetection&&s){const e=i(s,o.locales);e&&n(e,f)&&(d=e)}if(!d&&e.localeDetection&&l){const e=c(l,f.locales||o.locales,f.defaultLocale);e&&(d=e)}return d||(d=f.defaultLocale),{locale:d,domain:f}}function u(o,e,l,t,n){return o.domains?s(o,e,l,t,n):{locale:r(o,e,l,t,n)}}export{u as default,c as getAcceptLanguageLocale};
1
+ import{match as e}from"@formatjs/intl-localematcher";import o from"negotiator";import{getPathnameMatch as l,isLocaleSupportedOnDomain as t,getHost as a}from"./utils.js";function n(l,t,a){let n;const c=new o({headers:{"accept-language":l.get("accept-language")||void 0}}).languages();try{const o=function(e){return e.slice().sort(((e,o)=>o.length-e.length))}(t);n=e(c,o,a)}catch(e){}return n}function c(e,o){if(e.localeCookie&&o.has(e.localeCookie.name)){var l;const t=null===(l=o.get(e.localeCookie.name))||void 0===l?void 0:l.value;if(t&&e.locales.includes(t))return t}}function i(e,o,t,a){let i;var r;a&&(i=null===(r=l(a,e.locales,e.localePrefix))||void 0===r?void 0:r.locale);return!i&&e.localeDetection&&t&&(i=c(e,t)),!i&&e.localeDetection&&o&&(i=n(o,e.locales,e.defaultLocale)),i||(i=e.defaultLocale),i}function r(e,o,r,u){const f=function(e,o){const l=a(e);if(l&&o)return o.find((e=>e.domain===l))}(o,e.domains);if(!f)return{locale:i(e,o,r,u)};let s;if(u){var d;const o=null===(d=l(u,e.locales,e.localePrefix))||void 0===d?void 0:d.locale;if(o){if(!t(o,f))return{locale:o,domain:f};s=o}}if(!s&&e.localeDetection&&r){const o=c(e,r);o&&t(o,f)&&(s=o)}if(!s&&e.localeDetection&&o){const l=n(o,f.locales||e.locales,f.defaultLocale);l&&(s=l)}return s||(s=f.defaultLocale),{locale:s,domain:f}}function u(e,o,l,t){return e.domains?r(e,o,l,t):{locale:i(e,o,l,t)}}export{u as default,n as getAcceptLanguageLocale};
@@ -1 +1 @@
1
- import{COOKIE_LOCALE_NAME as e,COOKIE_SAME_SITE as o,COOKIE_MAX_AGE as t}from"../shared/constants.js";function a(a,s,i){var n;(null===(n=a.cookies.get(e))||void 0===n?void 0:n.value)!==i&&s.cookies.set(e,i,{path:a.nextUrl.basePath||void 0,sameSite:o,maxAge:t})}export{a as default};
1
+ function e(e,o,t,a){var i;const{name:n,...s}=a;(null===(i=e.cookies.get(n))||void 0===i?void 0:i.value)!==t&&o.cookies.set(n,t,{path:e.nextUrl.basePath||void 0,...s})}export{e as default};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o,useMemo as t}from"react";import n from"../../react-client/useLocale.js";import{receiveRoutingConfig as a}from"../../routing/config.js";import{getRoute as l,compileLocalizedPathname as c,normalizeNameOrNameWithParams as i}from"../shared/utils.js";import s from"./ClientLink.js";import{clientRedirect as f,clientPermanentRedirect as u}from"./redirects.js";import m from"./useBasePathname.js";import h from"./useBaseRouter.js";function p(p){const d=a(p);function v(){const e=n();if(!d.locales.includes(e))throw new Error('Unknown locale encountered: "'.concat(e,'". Make sure to validate the locale in `i18n.ts`.'));return e}function P(o,t){let{href:n,locale:a,...l}=o;const i=v(),f=a||i;return r.createElement(s,e({ref:t,href:c({locale:f,pathname:n,params:"object"==typeof n?n.params:void 0,pathnames:d.pathnames}),locale:a,localePrefix:d.localePrefix},l))}const x=o(P);function g(e){let{href:r,locale:o}=e;return c({...i(r),locale:o,pathnames:d.pathnames})}return x.displayName="Link",{Link:x,redirect:function(e){const r=g({href:e,locale:v()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return f({pathname:r,localePrefix:d.localePrefix},...t)},permanentRedirect:function(e){const r=g({href:e,locale:v()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return u({pathname:r,localePrefix:d.localePrefix},...t)},usePathname:function(){const e=m(d.localePrefix),r=v();return t((()=>e?l(r,e,d.pathnames):e),[r,e])},useRouter:function(){const e=h(d.localePrefix),r=v();return t((()=>({...e,push(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=g({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.push(c,...a)},replace(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=g({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.replace(c,...a)},prefetch(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=g({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(c,...a)}})),[e,r])},getPathname:g}}export{p as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o,useMemo as t}from"react";import n from"../../react-client/useLocale.js";import{receiveRoutingConfig as l,receiveLocaleCookie as a}from"../../routing/config.js";import{getRoute as c,compileLocalizedPathname as i,normalizeNameOrNameWithParams as s}from"../shared/utils.js";import f from"./ClientLink.js";import{clientRedirect as u,clientPermanentRedirect as m}from"./redirects.js";import h from"./useBasePathname.js";import p from"./useBaseRouter.js";function d(d){const v=l(d),P=a(null==d?void 0:d.localeCookie);function x(){const e=n();if(!v.locales.includes(e))throw new Error('Unknown locale encountered: "'.concat(e,'". Make sure to validate the locale in `i18n.ts`.'));return e}function g(o,t){let{href:n,locale:l,...a}=o;const c=x(),s=l||c;return r.createElement(f,e({ref:t,href:i({locale:s,pathname:n,params:"object"==typeof n?n.params:void 0,pathnames:v.pathnames}),locale:l,localeCookie:P,localePrefix:v.localePrefix},a))}const j=o(g);function w(e){let{href:r,locale:o}=e;return i({...s(r),locale:o,pathnames:v.pathnames})}return j.displayName="Link",{Link:j,redirect:function(e){const r=w({href:e,locale:x()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return u({pathname:r,localePrefix:v.localePrefix},...t)},permanentRedirect:function(e){const r=w({href:e,locale:x()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return m({pathname:r,localePrefix:v.localePrefix},...t)},usePathname:function(){const e=h(v.localePrefix),r=x();return t((()=>e?c(r,e,v.pathnames):e),[r,e])},useRouter:function(){const e=p(v.localePrefix,P),r=x();return t((()=>({...e,push(o){for(var t,n=arguments.length,l=new Array(n>1?n-1:0),a=1;a<n;a++)l[a-1]=arguments[a];const c=w({href:o,locale:(null===(t=l[0])||void 0===t?void 0:t.locale)||r});return e.push(c,...l)},replace(o){for(var t,n=arguments.length,l=new Array(n>1?n-1:0),a=1;a<n;a++)l[a-1]=arguments[a];const c=w({href:o,locale:(null===(t=l[0])||void 0===t?void 0:t.locale)||r});return e.replace(c,...l)},prefetch(o){for(var t,n=arguments.length,l=new Array(n>1?n-1:0),a=1;a<n;a++)l[a-1]=arguments[a];const c=w({href:o,locale:(null===(t=l[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(c,...l)}})),[e,r])},getPathname:w}}export{d as default};
@@ -1 +1 @@
1
- import{useRouter as e,usePathname as t}from"next/navigation";import{useMemo as n}from"react";import o from"../../react-client/useLocale.js";import r from"../shared/createSharedNavigationFns.js";import a from"../shared/syncLocaleCookie.js";import{getRoute as s}from"../shared/utils.js";import c from"./useBasePathname.js";function i(i){function u(){return o()}const{Link:m,config:f,getPathname:h,...p}=r(u,i);return{...p,Link:m,usePathname:function(){const e=c(f.localePrefix),t=u();return n((()=>e&&f.pathnames?s(t,e,f.pathnames):e),[t,e])},useRouter:function(){const o=e(),r=u(),s=t();return n((()=>{function e(e){return function(t,n){const{locale:o,...c}=n||{},i=[h({href:t,locale:o||r,domain:window.location.host})];Object.keys(c).length>0&&i.push(c),e(...i),a(s,r,o)}}return{...o,push:e(o.push),replace:e(o.replace),prefetch:e(o.prefetch)}}),[r,s,o])},getPathname:h}}export{i as default};
1
+ import{useRouter as e,usePathname as t}from"next/navigation";import{useMemo as o}from"react";import n from"../../react-client/useLocale.js";import r from"../shared/createSharedNavigationFns.js";import a from"../shared/syncLocaleCookie.js";import{getRoute as c}from"../shared/utils.js";import i from"./useBasePathname.js";function s(s){function u(){return n()}const{Link:m,config:f,getPathname:h,...l}=r(u,s);return{...l,Link:m,usePathname:function(){const e=i(f.localePrefix),t=u();return o((()=>e&&f.pathnames?c(t,e,f.pathnames):e),[t,e])},useRouter:function(){const n=e(),r=u(),c=t();return o((()=>{function e(e){return function(t,o){const{locale:n,...i}=o||{},s=[h({href:t,locale:n||r,domain:window.location.host})];Object.keys(i).length>0&&s.push(i),e(...s),a(f.localeCookie,c,r,n)}}return{...n,push:e(n.push),replace:e(n.replace),prefetch:e(n.prefetch)}}),[r,c,n])},getPathname:h}}export{s as default};
@@ -1 +1 @@
1
- import{extends as r}from"../../_virtual/_rollupPluginBabelHelpers.js";import e,{forwardRef as t}from"react";import{receiveLocalePrefixConfig as n}from"../../routing/config.js";import o from"./ClientLink.js";import{clientRedirect as i,clientPermanentRedirect as a}from"./redirects.js";import u from"./useBasePathname.js";import f from"./useBaseRouter.js";function l(l){const m=n(null==l?void 0:l.localePrefix);function s(t,n){return e.createElement(o,r({ref:n,localePrefix:m},t))}const c=t(s);return c.displayName="Link",{Link:c,redirect:function(r){for(var e=arguments.length,t=new Array(e>1?e-1:0),n=1;n<e;n++)t[n-1]=arguments[n];return i({pathname:r,localePrefix:m},...t)},permanentRedirect:function(r){for(var e=arguments.length,t=new Array(e>1?e-1:0),n=1;n<e;n++)t[n-1]=arguments[n];return a({pathname:r,localePrefix:m},...t)},usePathname:function(){return u(m)},useRouter:function(){return f(m)}}}export{l as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o}from"react";import{receiveLocalePrefixConfig as t,receiveLocaleCookie as n}from"../../routing/config.js";import i from"./ClientLink.js";import{clientRedirect as a,clientPermanentRedirect as l}from"./redirects.js";import u from"./useBasePathname.js";import f from"./useBaseRouter.js";function m(m){const c=t(null==m?void 0:m.localePrefix),s=n(null==m?void 0:m.localeCookie);function p(o,t){return r.createElement(i,e({ref:t,localeCookie:s,localePrefix:c},o))}const d=o(p);return d.displayName="Link",{Link:d,redirect:function(e){for(var r=arguments.length,o=new Array(r>1?r-1:0),t=1;t<r;t++)o[t-1]=arguments[t];return a({pathname:e,localePrefix:c},...o)},permanentRedirect:function(e){for(var r=arguments.length,o=new Array(r>1?r-1:0),t=1;t<r;t++)o[t-1]=arguments[t];return l({pathname:e,localePrefix:c},...o)},usePathname:function(){return u(c)},useRouter:function(){return f(c,s)}}}export{m as default};
@@ -1 +1 @@
1
- import{useRouter as t,usePathname as e}from"next/navigation";import{useMemo as r}from"react";import o from"../../react-client/useLocale.js";import{getLocalePrefix as n,localizeHref as c}from"../../shared/utils.js";import s from"../shared/syncLocaleCookie.js";import{getBasePath as a}from"../shared/utils.js";function i(i){const p=t(),u=o(),l=e();return r((()=>{function t(t,e){let r=window.location.pathname;const o=a(l);o&&(r=r.replace(o,""));const s=e||u,p=n(s,i);return c(t,s,u,r,p)}function e(e){return function(r,o){const{locale:n,...c}=o||{};s(l,u,n);const a=[t(r,n)];return Object.keys(c).length>0&&a.push(c),e(...a)}}return{...p,push:e(p.push),replace:e(p.replace),prefetch:e(p.prefetch)}}),[u,i,l,p])}export{i as default};
1
+ import{useRouter as t,usePathname as e}from"next/navigation";import{useMemo as r}from"react";import o from"../../react-client/useLocale.js";import{getLocalePrefix as n,localizeHref as c}from"../../shared/utils.js";import s from"../shared/syncLocaleCookie.js";import{getBasePath as a}from"../shared/utils.js";function i(i,p){const u=t(),l=o(),f=e();return r((()=>{function t(t,e){let r=window.location.pathname;const o=a(f);o&&(r=r.replace(o,""));const s=e||l,p=n(s,i);return c(t,s,l,r,p)}function e(e){return function(r,o){const{locale:n,...c}=o||{};s(p,f,l,n);const a=[t(r,n)];return Object.keys(c).length>0&&a.push(c),e(...a)}}return{...u,push:e(u.push),replace:e(u.replace),prefetch:e(u.prefetch)}}),[l,p,i,f,u])}export{i as default};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import{receiveRoutingConfig as t}from"../../routing/config.js";import{getRequestLocale as o}from"../../server/react-server/RequestLocaleLegacy.js";import{compileLocalizedPathname as n,normalizeNameOrNameWithParams as a}from"../shared/utils.js";import l from"./ServerLink.js";import{serverRedirect as c,serverPermanentRedirect as i}from"./redirects.js";function s(s){const m=t(s);function f(e){let{href:r,locale:t}=e;return n({...a(r),locale:t,pathnames:m.pathnames})}function u(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(t){let{href:a,locale:c,...i}=t;const s=o(),f=c||s;return r.createElement(l,e({href:n({locale:f,pathname:a,params:"object"==typeof a?a.params:void 0,pathnames:m.pathnames}),locale:c,localePrefix:m.localePrefix},i))},redirect:function(e){const r=f({href:e,locale:o()});for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return c({localePrefix:m.localePrefix,pathname:r},...n)},permanentRedirect:function(e){const r=f({href:e,locale:o()});for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return i({localePrefix:m.localePrefix,pathname:r},...n)},getPathname:f,usePathname:u("usePathname"),useRouter:u("useRouter")}}export{s as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import{receiveRoutingConfig as o}from"../../routing/config.js";import{getRequestLocale as t}from"../../server/react-server/RequestLocaleLegacy.js";import{compileLocalizedPathname as a,normalizeNameOrNameWithParams as n}from"../shared/utils.js";import l from"./ServerLink.js";import{serverRedirect as c,serverPermanentRedirect as i}from"./redirects.js";function s(s){const m=o(s);function f(e){let{href:r,locale:o}=e;return a({...n(r),locale:o,pathnames:m.pathnames})}function u(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(o){let{href:n,locale:c,...i}=o;const s=t(),f=c||s;return r.createElement(l,e({href:a({locale:f,pathname:n,params:"object"==typeof n?n.params:void 0,pathnames:m.pathnames}),locale:c,localeCookie:m.localeCookie,localePrefix:m.localePrefix},i))},redirect:function(e){const r=f({href:e,locale:t()});for(var o=arguments.length,a=new Array(o>1?o-1:0),n=1;n<o;n++)a[n-1]=arguments[n];return c({localePrefix:m.localePrefix,pathname:r},...a)},permanentRedirect:function(e){const r=f({href:e,locale:t()});for(var o=arguments.length,a=new Array(o>1?o-1:0),n=1;n<o;n++)a[n-1]=arguments[n];return i({localePrefix:m.localePrefix,pathname:r},...a)},getPathname:f,usePathname:u("usePathname"),useRouter:u("useRouter")}}export{s as default};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import{receiveLocalePrefixConfig as t}from"../../routing/config.js";import n from"./ServerLink.js";import{serverRedirect as o,serverPermanentRedirect as i}from"./redirects.js";function a(a){const u=t(null==a?void 0:a.localePrefix);function c(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(t){return r.createElement(n,e({localePrefix:u},t))},redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return o({pathname:e,localePrefix:u},...t)},permanentRedirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return i({pathname:e,localePrefix:u},...t)},usePathname:c("usePathname"),useRouter:c("useRouter")}}export{a as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import{receiveLocalePrefixConfig as o,receiveLocaleCookie as n}from"../../routing/config.js";import t from"./ServerLink.js";import{serverRedirect as i,serverPermanentRedirect as a}from"./redirects.js";function l(l){const u=o(null==l?void 0:l.localePrefix),c=n(null==l?void 0:l.localeCookie);function f(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(o){return r.createElement(t,e({localeCookie:c,localePrefix:u},o))},redirect:function(e){for(var r=arguments.length,o=new Array(r>1?r-1:0),n=1;n<r;n++)o[n-1]=arguments[n];return i({pathname:e,localePrefix:u},...o)},permanentRedirect:function(e){for(var r=arguments.length,o=new Array(r>1?r-1:0),n=1;n<r;n++)o[n-1]=arguments[n];return a({pathname:e,localePrefix:u},...o)},usePathname:f("usePathname"),useRouter:f("useRouter")}}export{l as default};
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import o from"next/link";import{usePathname as t}from"next/navigation";import r,{forwardRef as n,useState as i,useEffect as c}from"react";import l from"../../react-client/useLocale.js";import a from"./syncLocaleCookie.js";function s(n,s){let{defaultLocale:p,href:f,locale:m,onClick:u,prefetch:h,unprefixed:d,...k}=n;const x=l(),L=m!==x,g=m||x,j=function(){const[e,o]=i();return c((()=>{o(window.location.host)}),[]),e}(),v=j&&d&&(d.domains[j]===g||!Object.keys(d.domains).includes(j)&&x===p&&!m)?d.pathname:f,w=t();return L&&(h&&console.error("The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`"),h=!1),r.createElement(o,e({ref:s,href:v,hrefLang:L?m:void 0,onClick:function(e){a(w,x,m),u&&u(e)},prefetch:h},k))}var p=n(s);export{p as default};
2
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import o from"next/link";import{usePathname as t}from"next/navigation";import r,{forwardRef as n,useState as i,useEffect as l}from"react";import c from"../../react-client/useLocale.js";import a from"./syncLocaleCookie.js";function s(n,s){let{defaultLocale:p,href:f,locale:m,localeCookie:u,onClick:h,prefetch:d,unprefixed:k,...x}=n;const L=c(),g=m!==L,j=m||L,v=function(){const[e,o]=i();return l((()=>{o(window.location.host)}),[]),e}(),w=v&&k&&(k.domains[v]===j||!Object.keys(k.domains).includes(v)&&L===p&&!m)?k.pathname:f,C=t();return g&&(d&&console.error("The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`"),d=!1),r.createElement(o,e({ref:s,href:w,hrefLang:g?m:void 0,onClick:function(e){a(u,C,L,m),h&&h(e)},prefetch:d},x))}var p=n(s);export{p as default};
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import{usePathname as r}from"next/navigation";import t,{forwardRef as o,useState as l,useEffect as i}from"react";import a from"../../react-client/useLocale.js";import{isLocalizableHref as n,prefixHref as s,localizeHref as m}from"../../shared/utils.js";import f from"./BaseLink.js";function c(o,c){let{href:p,locale:u,localePrefixMode:d,prefix:x,...j}=o;const h=r(),v=a(),L=u!==v,[g,k]=l((()=>n(p)&&("never"!==d||L)?s(p,x):p));return i((()=>{h&&k(m(p,u,v,h,x))}),[v,p,u,h,x]),t.createElement(f,e({ref:c,href:g,locale:u},j))}const p=o(c);p.displayName="ClientLink";export{p as default};
2
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import{usePathname as o}from"next/navigation";import r,{forwardRef as l,useState as t,useEffect as i}from"react";import a from"../../react-client/useLocale.js";import{isLocalizableHref as n,prefixHref as s,localizeHref as m}from"../../shared/utils.js";import c from"./BaseLink.js";function f(l,f){let{href:p,locale:u,localeCookie:d,localePrefixMode:x,prefix:j,...k}=l;const h=o(),v=a(),C=u!==v,[L,g]=t((()=>n(p)&&("never"!==x||C)?s(p,j):p));return i((()=>{h&&g(m(p,u,v,h,j))}),[v,p,u,h,j]),r.createElement(c,e({ref:f,href:L,locale:u,localeCookie:d},k))}const p=l(f);p.displayName="ClientLink";export{p as default};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import{redirect as t,permanentRedirect as a}from"next/navigation";import o,{forwardRef as n,use as r}from"react";import{receiveRoutingConfig as l}from"../../routing/config.js";import{isLocalizableHref as i}from"../../shared/utils.js";import m from"./BaseLink.js";import{validateReceivedConfig as c,serializeSearchParams as f,compileLocalizedPathname as s,applyPathnamePrefix as u,normalizeNameOrNameWithParams as p}from"./utils.js";function d(d,h){const j=l(h||{});c(j);const g=j.pathnames,v="as-needed"===j.localePrefix.mode&&j.domains||void 0;function y(t,a){let n,l,{href:c,locale:f,...s}=t;"object"==typeof c?(n=c.pathname,l=c.params):n=c;const u=i(c),p=d(),h=p instanceof Promise?r(p):p,y=u?L({locale:f||h,href:null==g?n:{pathname:n,params:l}},null!=f||v||void 0):n;return o.createElement(m,e({ref:a,defaultLocale:j.defaultLocale,href:{..."object"==typeof c&&c,pathname:y},locale:f,unprefixed:v&&u?{domains:j.domains.reduce(((e,t)=>(e[t.domain]=t.defaultLocale,e)),{}),pathname:L({locale:h,href:null==g?n:{pathname:n,params:l}},!1)}:void 0},s))}const x=n(y);function L(e,t){const{href:a,locale:o}=e;let n;return null==g?"object"==typeof a?(n=a.pathname,a.query&&(n+=f(a.query))):n=a:n=s({locale:o,...p(a),pathnames:j.pathnames}),u(n,o,j,e.domain,t)}function b(e){return function(t){for(var a=arguments.length,o=new Array(a>1?a-1:0),n=1;n<a;n++)o[n-1]=arguments[n];return e(L(t,t.domain?void 0:v),...o)}}const P=b(t),k=b(a);return{config:j,Link:x,redirect:P,permanentRedirect:k,getPathname:L}}export{d as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import{redirect as o,permanentRedirect as a}from"next/navigation";import t,{forwardRef as n,use as r}from"react";import{receiveRoutingConfig as l}from"../../routing/config.js";import{isLocalizableHref as i}from"../../shared/utils.js";import m from"./BaseLink.js";import{validateReceivedConfig as c,serializeSearchParams as f,compileLocalizedPathname as s,applyPathnamePrefix as u,normalizeNameOrNameWithParams as p}from"./utils.js";function d(d,h){const j=l(h||{});c(j);const g=j.pathnames,v="as-needed"===j.localePrefix.mode&&j.domains||void 0;function y(o,a){let n,l,{href:c,locale:f,...s}=o;"object"==typeof c?(n=c.pathname,l=c.params):n=c;const u=i(c),p=d(),h=p instanceof Promise?r(p):p,y=u?L({locale:f||h,href:null==g?n:{pathname:n,params:l}},null!=f||v||void 0):n;return t.createElement(m,e({ref:a,defaultLocale:j.defaultLocale,href:{..."object"==typeof c&&c,pathname:y},locale:f,localeCookie:j.localeCookie,unprefixed:v&&u?{domains:j.domains.reduce(((e,o)=>(e[o.domain]=o.defaultLocale,e)),{}),pathname:L({locale:h,href:null==g?n:{pathname:n,params:l}},!1)}:void 0},s))}const x=n(y);function L(e,o){const{href:a,locale:t}=e;let n;return null==g?"object"==typeof a?(n=a.pathname,a.query&&(n+=f(a.query))):n=a:n=s({locale:t,...p(a),pathnames:j.pathnames}),u(n,t,j,e.domain,o)}function b(e){return function(o){for(var a=arguments.length,t=new Array(a>1?a-1:0),n=1;n<a;n++)t[n-1]=arguments[n];return e(L(o,o.domain?void 0:v),...t)}}const k=b(o),P=b(a);return{config:j,Link:x,redirect:k,permanentRedirect:P,getPathname:L}}export{d as default};