next-intl 3.1.4 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/development/middleware/middleware.js +6 -6
  2. package/dist/development/navigation/react-client/{BaseLink.js → ClientLink.js} +7 -7
  3. package/dist/development/navigation/react-client/{baseRedirect.js → clientRedirect.js} +7 -4
  4. package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +18 -18
  5. package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +27 -4
  6. package/dist/development/navigation/react-server/{BaseLink.js → ServerLink.js} +4 -4
  7. package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +11 -6
  8. package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +24 -4
  9. package/dist/development/navigation/react-server/{baseRedirect.js → serverRedirect.js} +7 -4
  10. package/dist/development/{shared/BaseLinkWithLocale.js → navigation/shared/BaseLink.js} +21 -16
  11. package/dist/development/navigation/shared/baseRedirect.js +16 -0
  12. package/dist/development/shared/utils.js +7 -7
  13. package/dist/esm/middleware/middleware.js +1 -1
  14. package/dist/esm/navigation/react-client/ClientLink.js +1 -0
  15. package/dist/esm/navigation/react-client/clientRedirect.js +1 -0
  16. package/dist/esm/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
  17. package/dist/esm/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
  18. package/dist/esm/navigation/react-server/ServerLink.js +1 -0
  19. package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  20. package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
  21. package/dist/esm/navigation/react-server/serverRedirect.js +1 -0
  22. package/dist/esm/navigation/shared/BaseLink.js +2 -0
  23. package/dist/esm/navigation/shared/baseRedirect.js +1 -0
  24. package/dist/esm/shared/utils.js +1 -1
  25. package/dist/production/middleware/middleware.js +1 -1
  26. package/dist/production/navigation/react-client/ClientLink.js +1 -0
  27. package/dist/production/navigation/react-client/clientRedirect.js +1 -0
  28. package/dist/production/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
  29. package/dist/production/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
  30. package/dist/production/navigation/react-server/ServerLink.js +1 -0
  31. package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  32. package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
  33. package/dist/production/navigation/react-server/serverRedirect.js +1 -0
  34. package/dist/production/navigation/shared/BaseLink.js +2 -0
  35. package/dist/production/navigation/shared/baseRedirect.js +1 -0
  36. package/dist/production/shared/utils.js +1 -1
  37. package/dist/types/src/middleware/NextIntlMiddlewareConfig.d.ts +1 -2
  38. package/dist/types/src/navigation/react-client/{BaseLink.d.ts → ClientLink.d.ts} +5 -4
  39. package/dist/types/src/navigation/react-client/clientRedirect.d.ts +6 -0
  40. package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.d.ts +7 -5
  41. package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +43 -5
  42. package/dist/types/src/navigation/react-server/ServerLink.d.ts +8 -0
  43. package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +5 -3
  44. package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +6 -38
  45. package/dist/types/src/navigation/react-server/serverRedirect.d.ts +6 -0
  46. package/dist/types/src/navigation/shared/BaseLink.d.ts +9 -0
  47. package/dist/types/src/navigation/shared/baseRedirect.d.ts +7 -0
  48. package/dist/types/src/shared/types.d.ts +1 -0
  49. package/dist/types/src/shared/utils.d.ts +3 -3
  50. package/dist/types/test/navigation/createSharedPathnamesNavigation.test.d.ts +1 -0
  51. package/dist/types/test/navigation/react-client/ClientLink.test.d.ts +1 -0
  52. package/package.json +8 -7
  53. package/dist/development/shared/redirectWithLocale.js +0 -16
  54. package/dist/esm/navigation/react-client/BaseLink.js +0 -1
  55. package/dist/esm/navigation/react-client/baseRedirect.js +0 -1
  56. package/dist/esm/navigation/react-server/BaseLink.js +0 -1
  57. package/dist/esm/navigation/react-server/baseRedirect.js +0 -1
  58. package/dist/esm/shared/BaseLinkWithLocale.js +0 -2
  59. package/dist/esm/shared/redirectWithLocale.js +0 -1
  60. package/dist/production/navigation/react-client/BaseLink.js +0 -1
  61. package/dist/production/navigation/react-client/baseRedirect.js +0 -1
  62. package/dist/production/navigation/react-server/BaseLink.js +0 -1
  63. package/dist/production/navigation/react-server/baseRedirect.js +0 -1
  64. package/dist/production/shared/BaseLinkWithLocale.js +0 -2
  65. package/dist/production/shared/redirectWithLocale.js +0 -1
  66. package/dist/types/src/navigation/react-client/baseRedirect.d.ts +0 -3
  67. package/dist/types/src/navigation/react-server/BaseLink.d.ts +0 -8
  68. package/dist/types/src/navigation/react-server/baseRedirect.d.ts +0 -3
  69. package/dist/types/src/shared/BaseLinkWithLocale.d.ts +0 -7
  70. package/dist/types/src/shared/redirectWithLocale.d.ts +0 -3
  71. /package/dist/types/test/navigation/{react-client/BaseLink.test.d.ts → createLocalizedPathnamesNavigation.test.d.ts} +0 -0
@@ -94,9 +94,9 @@ function createMiddleware(config) {
94
94
  response = redirect(pathWithSearch);
95
95
  }
96
96
  } else {
97
- const pathWithSearch = utils.getPathWithSearch(pathname, request.nextUrl.search);
97
+ const internalPathWithSearch = utils.getPathWithSearch(pathname, request.nextUrl.search);
98
98
  if (hasLocalePrefix) {
99
- const basePath = utils.getBasePath(pathWithSearch, pathLocale);
99
+ const basePath = utils.getBasePath(utils.getPathWithSearch(normalizedPathname, request.nextUrl.search), pathLocale);
100
100
  if (configWithDefaults.localePrefix === 'never') {
101
101
  response = redirect(basePath);
102
102
  } else if (pathLocale === locale) {
@@ -108,10 +108,10 @@ function createMiddleware(config) {
108
108
  if ((domain === null || domain === void 0 ? void 0 : domain.domain) !== (pathDomain === null || pathDomain === void 0 ? void 0 : pathDomain.domain) && !hasUnknownHost) {
109
109
  response = redirect(basePath, pathDomain === null || pathDomain === void 0 ? void 0 : pathDomain.domain);
110
110
  } else {
111
- response = rewrite(pathWithSearch);
111
+ response = rewrite(internalPathWithSearch);
112
112
  }
113
113
  } else {
114
- response = rewrite(pathWithSearch);
114
+ response = rewrite(internalPathWithSearch);
115
115
  }
116
116
  }
117
117
  } else {
@@ -119,9 +119,9 @@ function createMiddleware(config) {
119
119
  }
120
120
  } else {
121
121
  if (configWithDefaults.localePrefix === 'never' || hasMatchedDefaultLocale && (configWithDefaults.localePrefix === 'as-needed' || configWithDefaults.domains)) {
122
- response = rewrite("/".concat(locale).concat(pathWithSearch));
122
+ response = rewrite("/".concat(locale).concat(internalPathWithSearch));
123
123
  } else {
124
- response = redirect("/".concat(locale).concat(pathWithSearch));
124
+ response = redirect("/".concat(locale).concat(internalPathWithSearch));
125
125
  }
126
126
  }
127
127
  }
@@ -5,20 +5,20 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
6
  var React = require('react');
7
7
  var useLocale = require('../../react-client/useLocale.js');
8
- var BaseLinkWithLocale = require('../../shared/BaseLinkWithLocale.js');
8
+ var BaseLink = require('../shared/BaseLink.js');
9
9
 
10
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
11
 
12
12
  var React__default = /*#__PURE__*/_interopDefault(React);
13
13
 
14
- function BaseLink(_ref, ref) {
14
+ function ClientLink(_ref, ref) {
15
15
  let {
16
16
  locale,
17
17
  ...rest
18
18
  } = _ref;
19
19
  const defaultLocale = useLocale.default();
20
20
  const linkLocale = locale || defaultLocale;
21
- return /*#__PURE__*/React__default.default.createElement(BaseLinkWithLocale.default, _rollupPluginBabelHelpers.extends({
21
+ return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
22
22
  ref: ref,
23
23
  hrefLang: linkLocale,
24
24
  locale: linkLocale
@@ -45,8 +45,8 @@ function BaseLink(_ref, ref) {
45
45
  * the `set-cookie` response header would cause the locale cookie on the current
46
46
  * page to be overwritten before the user even decides to change the locale.
47
47
  */
48
- const BaseLinkWithRef = /*#__PURE__*/React.forwardRef(BaseLink);
49
- BaseLinkWithRef.displayName = 'Link';
50
- var BaseLink$1 = BaseLinkWithRef;
48
+ const ClientLinkWithRef = /*#__PURE__*/React.forwardRef(ClientLink);
49
+ ClientLinkWithRef.displayName = 'ClientLink';
50
+ var ClientLink$1 = ClientLinkWithRef;
51
51
 
52
- exports.default = BaseLink$1;
52
+ exports.default = ClientLink$1;
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var useLocale = require('../../react-client/useLocale.js');
6
- var redirectWithLocale = require('../../shared/redirectWithLocale.js');
6
+ var baseRedirect = require('../shared/baseRedirect.js');
7
7
 
8
- function baseRedirect(pathname) {
8
+ function clientRedirect(params) {
9
9
  let locale;
10
10
  try {
11
11
  // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context here is fine, since `redirect` should be called during render
@@ -16,7 +16,10 @@ function baseRedirect(pathname) {
16
16
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
17
17
  args[_key - 1] = arguments[_key];
18
18
  }
19
- return redirectWithLocale.default(pathname, locale, ...args);
19
+ return baseRedirect.default({
20
+ ...params,
21
+ locale
22
+ }, ...args);
20
23
  }
21
24
 
22
- exports.default = baseRedirect;
25
+ exports.default = clientRedirect;
@@ -6,8 +6,8 @@ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelper
6
6
  var React = require('react');
7
7
  var useLocale = require('../../react-client/useLocale.js');
8
8
  var utils = require('../shared/utils.js');
9
- var BaseLink = require('./BaseLink.js');
10
- var baseRedirect = require('./baseRedirect.js');
9
+ var ClientLink = require('./ClientLink.js');
10
+ var clientRedirect = require('./clientRedirect.js');
11
11
  var useBasePathname = require('./useBasePathname.js');
12
12
  var useBaseRouter = require('./useBaseRouter.js');
13
13
 
@@ -15,28 +15,24 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
15
 
16
16
  var React__default = /*#__PURE__*/_interopDefault(React);
17
17
 
18
- function createLocalizedPathnamesNavigation(_ref) {
19
- let {
20
- locales,
21
- pathnames
22
- } = _ref;
18
+ function createLocalizedPathnamesNavigation(opts) {
23
19
  function useTypedLocale() {
24
20
  const locale = useLocale.default();
25
- const isValid = locales.includes(locale);
21
+ const isValid = opts.locales.includes(locale);
26
22
  if (!isValid) {
27
23
  throw new Error("Unknown locale encountered: \"".concat(locale, "\". Make sure to validate the locale in `app/[locale]/layout.tsx`.") );
28
24
  }
29
25
  return locale;
30
26
  }
31
- function Link(_ref2, ref) {
27
+ function Link(_ref, ref) {
32
28
  let {
33
29
  href,
34
30
  locale,
35
31
  ...rest
36
- } = _ref2;
32
+ } = _ref;
37
33
  const defaultLocale = useTypedLocale();
38
34
  const finalLocale = locale || defaultLocale;
39
- return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
35
+ return /*#__PURE__*/React__default.default.createElement(ClientLink.default, _rollupPluginBabelHelpers.extends({
40
36
  ref: ref,
41
37
  href: utils.compileLocalizedPathname({
42
38
  locale: finalLocale,
@@ -44,9 +40,10 @@ function createLocalizedPathnamesNavigation(_ref) {
44
40
  pathname: href,
45
41
  // @ts-expect-error -- This is ok
46
42
  params: typeof href === 'object' ? href.params : undefined,
47
- pathnames
43
+ pathnames: opts.pathnames
48
44
  }),
49
- locale: locale
45
+ locale: locale,
46
+ localePrefix: opts.localePrefix
50
47
  }, rest));
51
48
  }
52
49
  const LinkWithRef = /*#__PURE__*/React.forwardRef(Link);
@@ -61,7 +58,10 @@ function createLocalizedPathnamesNavigation(_ref) {
61
58
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
62
59
  args[_key - 1] = arguments[_key];
63
60
  }
64
- return baseRedirect.default(resolvedHref, ...args);
61
+ return clientRedirect.default({
62
+ ...opts,
63
+ pathname: resolvedHref
64
+ }, ...args);
65
65
  }
66
66
  function useRouter() {
67
67
  const baseRouter = useBaseRouter.default();
@@ -109,18 +109,18 @@ function createLocalizedPathnamesNavigation(_ref) {
109
109
  return utils.getRoute({
110
110
  pathname,
111
111
  locale,
112
- pathnames
112
+ pathnames: opts.pathnames
113
113
  });
114
114
  }
115
- function getPathname(_ref3) {
115
+ function getPathname(_ref2) {
116
116
  let {
117
117
  href,
118
118
  locale
119
- } = _ref3;
119
+ } = _ref2;
120
120
  return utils.compileLocalizedPathname({
121
121
  ...utils.normalizeNameOrNameWithParams(href),
122
122
  locale,
123
- pathnames
123
+ pathnames: opts.pathnames
124
124
  });
125
125
  }
126
126
  return {
@@ -2,15 +2,38 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var BaseLink = require('./BaseLink.js');
6
- var baseRedirect = require('./baseRedirect.js');
5
+ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
+ var React = require('react');
7
+ var ClientLink = require('./ClientLink.js');
8
+ var clientRedirect = require('./clientRedirect.js');
7
9
  var useBasePathname = require('./useBasePathname.js');
8
10
  var useBaseRouter = require('./useBaseRouter.js');
9
11
 
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
+
14
+ var React__default = /*#__PURE__*/_interopDefault(React);
15
+
10
16
  function createSharedPathnamesNavigation(opts) {
17
+ function Link(props, ref) {
18
+ return /*#__PURE__*/React__default.default.createElement(ClientLink.default, _rollupPluginBabelHelpers.extends({
19
+ ref: ref,
20
+ localePrefix: opts.localePrefix
21
+ }, props));
22
+ }
23
+ const LinkWithRef = /*#__PURE__*/React.forwardRef(Link);
24
+ LinkWithRef.displayName = 'Link';
25
+ function redirect(pathname) {
26
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
27
+ args[_key - 1] = arguments[_key];
28
+ }
29
+ return clientRedirect.default({
30
+ ...opts,
31
+ pathname
32
+ }, ...args);
33
+ }
11
34
  return {
12
- Link: BaseLink.default,
13
- redirect: baseRedirect.default,
35
+ Link: LinkWithRef,
36
+ redirect,
14
37
  usePathname: useBasePathname.default,
15
38
  useRouter: useBaseRouter.default
16
39
  };
@@ -4,21 +4,21 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
6
  var React = require('react');
7
- var BaseLinkWithLocale = require('../../shared/BaseLinkWithLocale.js');
7
+ var BaseLink = require('../shared/BaseLink.js');
8
8
  var getLocale = require('../../server/getLocale.js');
9
9
 
10
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
11
 
12
12
  var React__default = /*#__PURE__*/_interopDefault(React);
13
13
 
14
- async function BaseLink(_ref) {
14
+ async function ServerLink(_ref) {
15
15
  let {
16
16
  locale,
17
17
  ...rest
18
18
  } = _ref;
19
- return /*#__PURE__*/React__default.default.createElement(BaseLinkWithLocale.default, _rollupPluginBabelHelpers.extends({
19
+ return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
20
20
  locale: locale || (await getLocale.default())
21
21
  }, rest));
22
22
  }
23
23
 
24
- exports.default = BaseLink;
24
+ exports.default = ServerLink;
@@ -6,8 +6,8 @@ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelper
6
6
  var React = require('react');
7
7
  var RequestLocale = require('../../server/RequestLocale.js');
8
8
  var utils = require('../shared/utils.js');
9
- var BaseLink = require('./BaseLink.js');
10
- var baseRedirect = require('./baseRedirect.js');
9
+ var ServerLink = require('./ServerLink.js');
10
+ var serverRedirect = require('./serverRedirect.js');
11
11
 
12
12
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
13
 
@@ -15,6 +15,7 @@ var React__default = /*#__PURE__*/_interopDefault(React);
15
15
 
16
16
  function createLocalizedPathnamesNavigation(_ref) {
17
17
  let {
18
+ localePrefix,
18
19
  locales,
19
20
  pathnames
20
21
  } = _ref;
@@ -26,7 +27,7 @@ function createLocalizedPathnamesNavigation(_ref) {
26
27
  } = _ref2;
27
28
  const defaultLocale = RequestLocale.getRequestLocale();
28
29
  const finalLocale = locale || defaultLocale;
29
- return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
30
+ return /*#__PURE__*/React__default.default.createElement(ServerLink.default, _rollupPluginBabelHelpers.extends({
30
31
  href: utils.compileLocalizedPathname({
31
32
  locale: finalLocale,
32
33
  // @ts-expect-error -- This is ok
@@ -35,19 +36,23 @@ function createLocalizedPathnamesNavigation(_ref) {
35
36
  params: typeof href === 'object' ? href.params : undefined,
36
37
  pathnames
37
38
  }),
38
- locale: locale
39
+ locale: locale,
40
+ localePrefix: localePrefix
39
41
  }, rest));
40
42
  }
41
43
  function redirect(href) {
42
44
  const locale = RequestLocale.getRequestLocale();
43
- const resolvedHref = getPathname({
45
+ const pathname = getPathname({
44
46
  href,
45
47
  locale
46
48
  });
47
49
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
48
50
  args[_key - 1] = arguments[_key];
49
51
  }
50
- return baseRedirect.default(resolvedHref, ...args);
52
+ return serverRedirect.default({
53
+ localePrefix,
54
+ pathname
55
+ }, ...args);
51
56
  }
52
57
  function getPathname(_ref3) {
53
58
  let {
@@ -2,8 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var BaseLink = require('./BaseLink.js');
6
- var baseRedirect = require('./baseRedirect.js');
5
+ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
+ var React = require('react');
7
+ var ServerLink = require('./ServerLink.js');
8
+ var serverRedirect = require('./serverRedirect.js');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var React__default = /*#__PURE__*/_interopDefault(React);
7
13
 
8
14
  function createSharedPathnamesNavigation(opts) {
9
15
  function notSupported(message) {
@@ -11,9 +17,23 @@ function createSharedPathnamesNavigation(opts) {
11
17
  throw new Error("`".concat(message, "` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."));
12
18
  };
13
19
  }
20
+ function Link(props) {
21
+ return /*#__PURE__*/React__default.default.createElement(ServerLink.default, _rollupPluginBabelHelpers.extends({
22
+ localePrefix: opts.localePrefix
23
+ }, props));
24
+ }
25
+ function redirect(pathname) {
26
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
27
+ args[_key - 1] = arguments[_key];
28
+ }
29
+ return serverRedirect.default({
30
+ ...opts,
31
+ pathname
32
+ }, ...args);
33
+ }
14
34
  return {
15
- Link: BaseLink.default,
16
- redirect: baseRedirect.default,
35
+ Link,
36
+ redirect,
17
37
  usePathname: notSupported('usePathname'),
18
38
  useRouter: notSupported('useRouter')
19
39
  };
@@ -3,14 +3,17 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var RequestLocale = require('../../server/RequestLocale.js');
6
- var redirectWithLocale = require('../../shared/redirectWithLocale.js');
6
+ var baseRedirect = require('../shared/baseRedirect.js');
7
7
 
8
- function baseRedirect(pathname) {
8
+ function serverRedirect(params) {
9
9
  const locale = RequestLocale.getRequestLocale();
10
10
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
11
11
  args[_key - 1] = arguments[_key];
12
12
  }
13
- return redirectWithLocale.default(pathname, locale, ...args);
13
+ return baseRedirect.default({
14
+ ...params,
15
+ locale
16
+ }, ...args);
14
17
  }
15
18
 
16
- exports.default = baseRedirect;
19
+ exports.default = serverRedirect;
@@ -3,22 +3,23 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
6
+ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
7
7
  var NextLink = require('next/link');
8
8
  var navigation = require('next/navigation');
9
9
  var React = require('react');
10
- var useLocale = require('../react-client/useLocale.js');
11
- var utils = require('./utils.js');
10
+ var useLocale = require('../../react-client/useLocale.js');
11
+ var utils = require('../../shared/utils.js');
12
12
 
13
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
15
  var NextLink__default = /*#__PURE__*/_interopDefault(NextLink);
16
16
  var React__default = /*#__PURE__*/_interopDefault(React);
17
17
 
18
- function BaseLinkWithLocale(_ref, ref) {
18
+ function BaseLink(_ref, ref) {
19
19
  let {
20
20
  href,
21
21
  locale,
22
+ localePrefix,
22
23
  prefetch,
23
24
  ...rest
24
25
  } = _ref;
@@ -27,20 +28,22 @@ function BaseLinkWithLocale(_ref, ref) {
27
28
  const pathname = navigation.usePathname();
28
29
  const defaultLocale = useLocale.default();
29
30
  const isChangingLocale = locale !== defaultLocale;
30
- const [localizedHref, setLocalizedHref] = React.useState(() => utils.isLocalHref(href) && locale ?
31
- // Potentially the href shouldn't be prefixed, but to determine this we
31
+ const [localizedHref, setLocalizedHref] = React.useState(() => utils.isLocalHref(href) && (localePrefix !== 'never' || isChangingLocale) ?
32
+ // For the `localePrefix: 'as-needed' strategy, the href shouldn't
33
+ // be prefixed if the locale is the default locale. To determine this, we
32
34
  // need a) the default locale and b) the information if we use prefixed
33
- // routing. During the server side render (both in RSC as well as SSR),
34
- // we don't have this information. Therefore we always prefix the href
35
- // since this will always result in a valid URL, even if it might cause
36
- // a redirect. This is better than pointing to a non-localized href
37
- // during the server render, which would potentially be wrong. The final
38
- // href is determined in the effect below.
35
+ // routing. The default locale can vary by domain, therefore during the
36
+ // RSC as well as the SSR render, we can't determine the default locale
37
+ // statically. Therefore we always prefix the href since this will
38
+ // always result in a valid URL, even if it might cause a redirect. This
39
+ // is better than pointing to a non-localized href during the server
40
+ // render, which would potentially be wrong. The final href is
41
+ // determined in the effect below.
39
42
  utils.prefixHref(href, locale) : href);
40
43
  React.useEffect(() => {
41
- if (!pathname) return;
44
+ if (!pathname || localePrefix === 'never') return;
42
45
  setLocalizedHref(utils.localizeHref(href, locale, defaultLocale, pathname !== null && pathname !== void 0 ? pathname : undefined));
43
- }, [defaultLocale, href, locale, pathname]);
46
+ }, [defaultLocale, href, locale, localePrefix, pathname]);
44
47
  if (isChangingLocale) {
45
48
  if (prefetch && "development" !== 'production') {
46
49
  console.error('The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`');
@@ -53,6 +56,8 @@ function BaseLinkWithLocale(_ref, ref) {
53
56
  prefetch: prefetch
54
57
  }, rest));
55
58
  }
56
- var BaseLinkWithLocale$1 = /*#__PURE__*/React.forwardRef(BaseLinkWithLocale);
59
+ const BaseLinkWithRef = /*#__PURE__*/React.forwardRef(BaseLink);
60
+ BaseLinkWithRef.displayName = 'ClientLink';
61
+ var BaseLink$1 = BaseLinkWithRef;
57
62
 
58
- exports.default = BaseLinkWithLocale$1;
63
+ exports.default = BaseLink$1;
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var navigation = require('next/navigation');
6
+ var utils = require('../../shared/utils.js');
7
+
8
+ function baseRedirect(params) {
9
+ const localizedPathname = params.localePrefix === 'never' ? params.pathname : utils.prefixPathname(params.locale, params.pathname);
10
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
11
+ args[_key - 1] = arguments[_key];
12
+ }
13
+ return navigation.redirect(localizedPathname, ...args);
14
+ }
15
+
16
+ exports.default = baseRedirect;
@@ -15,14 +15,14 @@ function isLocalHref(href) {
15
15
  }
16
16
  }
17
17
  function localizeHref(href, locale) {
18
- let defaultLocale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : locale;
18
+ let curLocale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : locale;
19
19
  let pathname = arguments.length > 3 ? arguments[3] : undefined;
20
20
  if (!isLocalHref(href) || isRelativeHref(href)) {
21
21
  return href;
22
22
  }
23
- const isSwitchingLocale = locale !== defaultLocale;
23
+ const isSwitchingLocale = locale !== curLocale;
24
24
  const isPathnamePrefixed = locale == null || hasPathnamePrefixed(locale, pathname);
25
- const shouldPrefix = isPathnamePrefixed || isSwitchingLocale;
25
+ const shouldPrefix = isSwitchingLocale || isPathnamePrefixed;
26
26
  if (shouldPrefix && locale != null) {
27
27
  return prefixHref(href, locale);
28
28
  }
@@ -31,13 +31,13 @@ function localizeHref(href, locale) {
31
31
  function prefixHref(href, locale) {
32
32
  let prefixedHref;
33
33
  if (typeof href === 'string') {
34
- prefixedHref = localizePathname(locale, href);
34
+ prefixedHref = prefixPathname(locale, href);
35
35
  } else {
36
36
  prefixedHref = {
37
37
  ...href
38
38
  };
39
39
  if (href.pathname) {
40
- prefixedHref.pathname = localizePathname(locale, href.pathname);
40
+ prefixedHref.pathname = prefixPathname(locale, href.pathname);
41
41
  }
42
42
  }
43
43
  return prefixedHref;
@@ -45,7 +45,7 @@ function prefixHref(href, locale) {
45
45
  function unlocalizePathname(pathname, locale) {
46
46
  return pathname.replace(new RegExp("^/".concat(locale)), '') || '/';
47
47
  }
48
- function localizePathname(locale, pathname) {
48
+ function prefixPathname(locale, pathname) {
49
49
  let localizedHref = '/' + locale;
50
50
 
51
51
  // Avoid trailing slashes
@@ -80,8 +80,8 @@ exports.hasPathnamePrefixed = hasPathnamePrefixed;
80
80
  exports.isLocalHref = isLocalHref;
81
81
  exports.isRelativeHref = isRelativeHref;
82
82
  exports.localizeHref = localizeHref;
83
- exports.localizePathname = localizePathname;
84
83
  exports.matchesPathname = matchesPathname;
85
84
  exports.prefixHref = prefixHref;
85
+ exports.prefixPathname = prefixPathname;
86
86
  exports.templateToRegex = templateToRegex;
87
87
  exports.unlocalizePathname = unlocalizePathname;
@@ -1 +1 @@
1
- import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as o,HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as n}from"../shared/utils.js";import t from"./getAlternateLinksHeaderValue.js";import a from"./resolveLocale.js";import{isLocaleSupportedOnDomain as r,getNormalizedPathname as i,getKnownLocaleFromPathname as s,getInternalTemplate as c,formatTemplatePathname as d,getPathWithSearch as f,getBasePath as u,getBestMatchingDomain as m}from"./utils.js";function v(v){const h=function(e){var o,l,n;return{...e,alternateLinks:null===(o=e.alternateLinks)||void 0===o||o,localePrefix:null!==(l=e.localePrefix)&&void 0!==l?l:"always",localeDetection:null===(n=e.localeDetection)||void 0===n||n}}(v);return function(v){var p,x;const{domain:L,locale:P}=a(h,v.headers,v.cookies,v.nextUrl.pathname),g=h.localeDetection&&(null===(p=v.cookies.get(o))||void 0===p?void 0:p.value)!==P,U=L?L.defaultLocale===P:P===h.defaultLocale,k=(null===(x=h.domains)||void 0===x?void 0:x.filter((e=>r(P,e))))||[],w=null!=h.domains&&!L;function j(o){return e.rewrite(new URL(o,v.url),function(){const e=new Headers(v.headers);return e.set(l,P),{request:{headers:e}}}())}function y(o,l){const n=new URL(o,v.url);if(k.length>0&&!l){const e=m(L,P,k);e&&(l=e.domain,e.defaultLocale===P&&"as-needed"===h.localePrefix&&(n.pathname=n.pathname.replace("/".concat(P),"")))}var t;l&&(n.protocol=null!==(t=v.headers.get("x-forwarded-proto"))&&void 0!==t?t:v.nextUrl.protocol,n.port="",n.host=l);return e.redirect(n.toString())}const D=i(v.nextUrl.pathname,h.locales),q=s(v.nextUrl.pathname,h.locales),A=null!=q;let H,R,S=v.nextUrl.pathname;if(h.pathnames){let e;if([e=P,R]=c(h.pathnames,D),R){const o=h.pathnames[R],l="string"==typeof o?o:o[P];if(n(l,D))S=d(D,l,R,q);else{const n=h.defaultLocale===P||(null==L?void 0:L.defaultLocale)===P;H=y(f(d(D,"string"==typeof o?o:o[e],l,q||!n?P:void 0),v.nextUrl.search))}}}if(!H)if("/"===S){const e=f("/".concat(P),v.nextUrl.search);H="never"===h.localePrefix||U&&"as-needed"===h.localePrefix?j(e):y(e)}else{const e=f(S,v.nextUrl.search);if(A){const o=u(e,q);if("never"===h.localePrefix)H=y(o);else if(q===P)if(U&&"as-needed"===h.localePrefix)H=y(o);else if(h.domains){const l=m(L,q,k);H=(null==L?void 0:L.domain)===(null==l?void 0:l.domain)||w?j(e):y(o,null==l?void 0:l.domain)}else H=j(e);else H=y("/".concat(P).concat(o))}else H="never"===h.localePrefix||U&&("as-needed"===h.localePrefix||h.domains)?j("/".concat(P).concat(e)):y("/".concat(P).concat(e))}var z;(g&&H.cookies.set(o,P,{sameSite:"strict",maxAge:31536e3}),"never"!==h.localePrefix&&h.alternateLinks&&h.locales.length>1)&&H.headers.set("Link",t({config:h,localizedPathnames:null!=R?null===(z=h.pathnames)||void 0===z?void 0:z[R]:void 0,request:v,resolvedLocale:P}));return H}}export{v as default};
1
+ import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as o,HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as n}from"../shared/utils.js";import t from"./getAlternateLinksHeaderValue.js";import a from"./resolveLocale.js";import{isLocaleSupportedOnDomain as r,getNormalizedPathname as i,getKnownLocaleFromPathname as s,getInternalTemplate as c,formatTemplatePathname as d,getPathWithSearch as f,getBasePath as u,getBestMatchingDomain as m}from"./utils.js";function v(v){const h=function(e){var o,l,n;return{...e,alternateLinks:null===(o=e.alternateLinks)||void 0===o||o,localePrefix:null!==(l=e.localePrefix)&&void 0!==l?l:"always",localeDetection:null===(n=e.localeDetection)||void 0===n||n}}(v);return function(v){var p,x;const{domain:L,locale:P}=a(h,v.headers,v.cookies,v.nextUrl.pathname),U=h.localeDetection&&(null===(p=v.cookies.get(o))||void 0===p?void 0:p.value)!==P,g=L?L.defaultLocale===P:P===h.defaultLocale,k=(null===(x=h.domains)||void 0===x?void 0:x.filter((e=>r(P,e))))||[],w=null!=h.domains&&!L;function j(o){return e.rewrite(new URL(o,v.url),function(){const e=new Headers(v.headers);return e.set(l,P),{request:{headers:e}}}())}function y(o,l){const n=new URL(o,v.url);if(k.length>0&&!l){const e=m(L,P,k);e&&(l=e.domain,e.defaultLocale===P&&"as-needed"===h.localePrefix&&(n.pathname=n.pathname.replace("/".concat(P),"")))}var t;l&&(n.protocol=null!==(t=v.headers.get("x-forwarded-proto"))&&void 0!==t?t:v.nextUrl.protocol,n.port="",n.host=l);return e.redirect(n.toString())}const D=i(v.nextUrl.pathname,h.locales),q=s(v.nextUrl.pathname,h.locales),A=null!=q;let H,R,S=v.nextUrl.pathname;if(h.pathnames){let e;if([e=P,R]=c(h.pathnames,D),R){const o=h.pathnames[R],l="string"==typeof o?o:o[P];if(n(l,D))S=d(D,l,R,q);else{const n=h.defaultLocale===P||(null==L?void 0:L.defaultLocale)===P;H=y(f(d(D,"string"==typeof o?o:o[e],l,q||!n?P:void 0),v.nextUrl.search))}}}if(!H)if("/"===S){const e=f("/".concat(P),v.nextUrl.search);H="never"===h.localePrefix||g&&"as-needed"===h.localePrefix?j(e):y(e)}else{const e=f(S,v.nextUrl.search);if(A){const o=u(f(D,v.nextUrl.search),q);if("never"===h.localePrefix)H=y(o);else if(q===P)if(g&&"as-needed"===h.localePrefix)H=y(o);else if(h.domains){const l=m(L,q,k);H=(null==L?void 0:L.domain)===(null==l?void 0:l.domain)||w?j(e):y(o,null==l?void 0:l.domain)}else H=j(e);else H=y("/".concat(P).concat(o))}else H="never"===h.localePrefix||g&&("as-needed"===h.localePrefix||h.domains)?j("/".concat(P).concat(e)):y("/".concat(P).concat(e))}var z;(U&&H.cookies.set(o,P,{sameSite:"strict",maxAge:31536e3}),"never"!==h.localePrefix&&h.alternateLinks&&h.locales.length>1)&&H.headers.set("Link",t({config:h,localizedPathnames:null!=R?null===(z=h.pathnames)||void 0===z?void 0:z[R]:void 0,request:v,resolvedLocale:P}));return H}}export{v as default};
@@ -0,0 +1 @@
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import a from"../../react-client/useLocale.js";import l from"../shared/BaseLink.js";function o(t,o){let{locale:n,...s}=t;const i=a(),c=n||i;return r.createElement(l,e({ref:o,hrefLang:c,locale:c},s))}const n=t(o);n.displayName="ClientLink";var s=n;export{s as default};
@@ -0,0 +1 @@
1
+ import e from"../../react-client/useLocale.js";import r from"../shared/baseRedirect.js";function t(t){let a;try{a=e()}catch(e){throw new Error("`redirect()` can only be called during render. To redirect in an event handler or similar, you can use `useRouter()` instead.")}for(var n=arguments.length,o=new Array(n>1?n-1:0),c=1;c<n;c++)o[c-1]=arguments[c];return r({...t,locale:a},...o)}export{t as default};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import o from"../../react-client/useLocale.js";import{getRoute as a,compileLocalizedPathname as n,normalizeNameOrNameWithParams as l}from"../shared/utils.js";import c from"./BaseLink.js";import s from"./baseRedirect.js";import u from"./useBasePathname.js";import i from"./useBaseRouter.js";function f(f){let{locales:m,pathnames:p}=f;function h(){const e=o();if(!m.includes(e))throw new Error('Unknown locale encountered: "'.concat(e,'". Make sure to validate the locale in `app/[locale]/layout.tsx`.'));return e}function d(t,o){let{href:a,locale:l,...s}=t;const u=h(),i=l||u;return r.createElement(c,e({ref:o,href:n({locale:i,pathname:a,params:"object"==typeof a?a.params:void 0,pathnames:p}),locale:l},s))}const v=t(d);function j(e){let{href:r,locale:t}=e;return n({...l(r),locale:t,pathnames:p})}return v.displayName="Link",{Link:v,redirect:function(e){const r=j({href:e,locale:h()});for(var t=arguments.length,o=new Array(t>1?t-1:0),a=1;a<t;a++)o[a-1]=arguments[a];return s(r,...o)},usePathname:function(){const e=u(),r=h();return a({pathname:e,locale:r,pathnames:p})},useRouter:function(){const e=i(),r=h();return{...e,push(t){for(var o,a=arguments.length,n=new Array(a>1?a-1:0),l=1;l<a;l++)n[l-1]=arguments[l];const c=j({href:t,locale:(null===(o=n[0])||void 0===o?void 0:o.locale)||r});return e.push(c,...n)},replace(t){for(var o,a=arguments.length,n=new Array(a>1?a-1:0),l=1;l<a;l++)n[l-1]=arguments[l];const c=j({href:t,locale:(null===(o=n[0])||void 0===o?void 0:o.locale)||r});return e.replace(c,...n)},prefetch(t){for(var o,a=arguments.length,n=new Array(a>1?a-1:0),l=1;l<a;l++)n[l-1]=arguments[l];const c=j({href:t,locale:(null===(o=n[0])||void 0===o?void 0:o.locale)||r});return e.prefetch(c,...n)}}},getPathname:j}}export{f as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import a from"../../react-client/useLocale.js";import{getRoute as o,compileLocalizedPathname as n,normalizeNameOrNameWithParams as l}from"../shared/utils.js";import c from"./ClientLink.js";import s from"./clientRedirect.js";import i from"./useBasePathname.js";import u from"./useBaseRouter.js";function f(f){function m(){const e=a();if(!f.locales.includes(e))throw new Error('Unknown locale encountered: "'.concat(e,'". Make sure to validate the locale in `app/[locale]/layout.tsx`.'));return e}function p(t,a){let{href:o,locale:l,...s}=t;const i=m(),u=l||i;return r.createElement(c,e({ref:a,href:n({locale:u,pathname:o,params:"object"==typeof o?o.params:void 0,pathnames:f.pathnames}),locale:l,localePrefix:f.localePrefix},s))}const h=t(p);function d(e){let{href:r,locale:t}=e;return n({...l(r),locale:t,pathnames:f.pathnames})}return h.displayName="Link",{Link:h,redirect:function(e){const r=d({href:e,locale:m()});for(var t=arguments.length,a=new Array(t>1?t-1:0),o=1;o<t;o++)a[o-1]=arguments[o];return s({...f,pathname:r},...a)},usePathname:function(){const e=i(),r=m();return o({pathname:e,locale:r,pathnames:f.pathnames})},useRouter:function(){const e=u(),r=m();return{...e,push(t){for(var a,o=arguments.length,n=new Array(o>1?o-1:0),l=1;l<o;l++)n[l-1]=arguments[l];const c=d({href:t,locale:(null===(a=n[0])||void 0===a?void 0:a.locale)||r});return e.push(c,...n)},replace(t){for(var a,o=arguments.length,n=new Array(o>1?o-1:0),l=1;l<o;l++)n[l-1]=arguments[l];const c=d({href:t,locale:(null===(a=n[0])||void 0===a?void 0:a.locale)||r});return e.replace(c,...n)},prefetch(t){for(var a,o=arguments.length,n=new Array(o>1?o-1:0),l=1;l<o;l++)n[l-1]=arguments[l];const c=d({href:t,locale:(null===(a=n[0])||void 0===a?void 0:a.locale)||r});return e.prefetch(c,...n)}}},getPathname:d}}export{f as default};
@@ -1 +1 @@
1
- import e from"./BaseLink.js";import r from"./baseRedirect.js";import t from"./useBasePathname.js";import s from"./useBaseRouter.js";function o(o){return{Link:e,redirect:r,usePathname:t,useRouter:s}}export{o as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import n from"./ClientLink.js";import o from"./clientRedirect.js";import a from"./useBasePathname.js";import i from"./useBaseRouter.js";function m(m){function s(t,o){return r.createElement(n,e({ref:o,localePrefix:m.localePrefix},t))}const l=t(s);return l.displayName="Link",{Link:l,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({...m,pathname:e},...t)},usePathname:a,useRouter:i}}export{m as default};
@@ -0,0 +1 @@
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import t from"../shared/BaseLink.js";import a from"../../server/getLocale.js";async function l(l){let{locale:o,...s}=l;return r.createElement(t,e({locale:o||await a()},s))}export{l as default};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import t from"react";import{getRequestLocale as r}from"../../server/RequestLocale.js";import{compileLocalizedPathname as o,normalizeNameOrNameWithParams as n}from"../shared/utils.js";import a from"./BaseLink.js";import s from"./baseRedirect.js";function l(l){let{locales:u,pathnames:c}=l;function m(e){let{href:t,locale:r}=e;return o({...n(t),locale:r,pathnames:c})}function i(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(n){let{href:s,locale:l,...u}=n;const m=r(),i=l||m;return t.createElement(a,e({href:o({locale:i,pathname:s,params:"object"==typeof s?s.params:void 0,pathnames:c}),locale:l},u))},redirect:function(e){const t=m({href:e,locale:r()});for(var o=arguments.length,n=new Array(o>1?o-1:0),a=1;a<o;a++)n[a-1]=arguments[a];return s(t,...n)},getPathname:m,usePathname:i("usePathname"),useRouter:i("useRouter")}}export{l as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import{getRequestLocale as t}from"../../server/RequestLocale.js";import{compileLocalizedPathname as o,normalizeNameOrNameWithParams as n}from"../shared/utils.js";import a from"./ServerLink.js";import l from"./serverRedirect.js";function s(s){let{localePrefix:c,locales:i,pathnames:m}=s;function u(e){let{href:r,locale:t}=e;return o({...n(r),locale:t,pathnames:m})}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(n){let{href:l,locale:s,...i}=n;const u=t(),f=s||u;return r.createElement(a,e({href:o({locale:f,pathname:l,params:"object"==typeof l?l.params:void 0,pathnames:m}),locale:s,localePrefix:c},i))},redirect:function(e){const r=u({href:e,locale:t()});for(var o=arguments.length,n=new Array(o>1?o-1:0),a=1;a<o;a++)n[a-1]=arguments[a];return l({localePrefix:c,pathname:r},...n)},getPathname:u,usePathname:f("usePathname"),useRouter:f("useRouter")}}export{s as default};
@@ -1 +1 @@
1
- import e from"./BaseLink.js";import o from"./baseRedirect.js";function t(t){function n(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:e,redirect:o,usePathname:n("usePathname"),useRouter:n("useRouter")}}export{t as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import t from"./ServerLink.js";import o from"./serverRedirect.js";function n(n){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){return r.createElement(t,e({localePrefix:n.localePrefix},o))},redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),u=1;u<r;u++)t[u-1]=arguments[u];return o({...n,pathname:e},...t)},usePathname:u("usePathname"),useRouter:u("useRouter")}}export{n as default};
@@ -0,0 +1 @@
1
+ import{getRequestLocale as e}from"../../server/RequestLocale.js";import r from"../shared/baseRedirect.js";function o(o){const t=e();for(var a=arguments.length,s=new Array(a>1?a-1:0),n=1;n<a;n++)s[n-1]=arguments[n];return r({...o,locale:t},...s)}export{o as default};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"next/link";import{usePathname as t}from"next/navigation";import o,{forwardRef as l,useState as n,useEffect as i}from"react";import a from"../../react-client/useLocale.js";import{isLocalHref as p,prefixHref as c,localizeHref as s}from"../../shared/utils.js";function f(l,f){let{href:m,locale:u,localePrefix:h,prefetch:d,...v}=l;const x=t(),g=a(),j=u!==g,[k,L]=n((()=>p(m)&&("never"!==h||j)?c(m,u):m));return i((()=>{x&&"never"!==h&&L(s(m,u,g,null!=x?x:void 0))}),[g,m,u,h,x]),j&&(d&&console.error("The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`"),d=!1),o.createElement(r,e({ref:f,href:k,prefetch:d},v))}const m=l(f);m.displayName="ClientLink";var u=m;export{u as default};
@@ -0,0 +1 @@
1
+ import{redirect as e}from"next/navigation";import{prefixPathname as r}from"../../shared/utils.js";function a(a){const t="never"===a.localePrefix?a.pathname:r(a.locale,a.pathname);for(var n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return e(t,...o)}export{a as default};
@@ -1 +1 @@
1
- function t(t){const n="object"==typeof t?t.pathname:t;return null!=n&&!n.startsWith("/")}function n(t){if("object"==typeof t)return null==t.host&&null==t.hostname;return!/^[a-z]+:/i.test(t)}function e(e,c){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c,a=arguments.length>3?arguments[3]:void 0;if(!n(e)||t(e))return e;const l=c!==o;return(null==c||u(c,a)||l)&&null!=c?r(e,c):e}function r(t,n){let e;return"string"==typeof t?e=o(n,t):(e={...t},t.pathname&&(e.pathname=o(n,t.pathname))),e}function c(t,n){return t.replace(new RegExp("^/".concat(n)),"")||"/"}function o(t,n){let e="/"+t;return/^\/(\?.*)?$/.test(n)&&(n=n.slice(1)),e+=n,e}function u(t,n){const e="/".concat(t);return n===e||n.startsWith("".concat(e,"/"))}function a(t,n){return l(t).test(n)}function l(t){const n=t.replace(/\[([^\]]+)\]/g,(t=>t.startsWith("[...")||t.startsWith("[[...")?"(.*)":"([^/]+)")).replaceAll("(.*)]","(.*)");return new RegExp("^".concat(n,"$"))}export{u as hasPathnamePrefixed,n as isLocalHref,t as isRelativeHref,e as localizeHref,o as localizePathname,a as matchesPathname,r as prefixHref,l as templateToRegex,c as unlocalizePathname};
1
+ function t(t){const n="object"==typeof t?t.pathname:t;return null!=n&&!n.startsWith("/")}function n(t){if("object"==typeof t)return null==t.host&&null==t.hostname;return!/^[a-z]+:/i.test(t)}function e(e,c){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c,a=arguments.length>3?arguments[3]:void 0;if(!n(e)||t(e))return e;const l=c!==o,i=null==c||u(c,a);return(l||i)&&null!=c?r(e,c):e}function r(t,n){let e;return"string"==typeof t?e=o(n,t):(e={...t},t.pathname&&(e.pathname=o(n,t.pathname))),e}function c(t,n){return t.replace(new RegExp("^/".concat(n)),"")||"/"}function o(t,n){let e="/"+t;return/^\/(\?.*)?$/.test(n)&&(n=n.slice(1)),e+=n,e}function u(t,n){const e="/".concat(t);return n===e||n.startsWith("".concat(e,"/"))}function a(t,n){return l(t).test(n)}function l(t){const n=t.replace(/\[([^\]]+)\]/g,(t=>t.startsWith("[...")||t.startsWith("[[...")?"(.*)":"([^/]+)")).replaceAll("(.*)]","(.*)");return new RegExp("^".concat(n,"$"))}export{u as hasPathnamePrefixed,n as isLocalHref,t as isRelativeHref,e as localizeHref,a as matchesPathname,r as prefixHref,o as prefixPathname,l as templateToRegex,c as unlocalizePathname};