next-intl 3.21.1 → 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 (129) hide show
  1. package/dist/development/middleware/middleware.js +19 -17
  2. package/dist/development/middleware/resolveLocale.js +20 -34
  3. package/dist/development/middleware/syncCookie.js +8 -7
  4. package/dist/development/navigation/react-client/ClientLink.js +2 -2
  5. package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +6 -1
  6. package/dist/development/navigation/react-client/createNavigation.js +83 -0
  7. package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +6 -1
  8. package/dist/development/navigation/react-client/useBasePathname.js +0 -14
  9. package/dist/development/navigation/react-client/useBaseRouter.js +3 -3
  10. package/dist/development/navigation/react-server/ServerLink.js +4 -2
  11. package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +5 -4
  12. package/dist/development/navigation/react-server/createNavigation.js +30 -0
  13. package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +2 -0
  14. package/dist/development/navigation/react-server/redirects.js +2 -2
  15. package/dist/development/navigation/shared/BaseLink.js +30 -26
  16. package/dist/development/navigation/shared/LegacyBaseLink.js +57 -0
  17. package/dist/development/navigation/shared/createSharedNavigationFns.js +148 -0
  18. package/dist/development/navigation/shared/redirects.js +3 -0
  19. package/dist/development/navigation/shared/syncLocaleCookie.js +26 -5
  20. package/dist/development/navigation/shared/utils.js +40 -1
  21. package/dist/development/navigation.react-client.js +2 -0
  22. package/dist/development/navigation.react-server.js +2 -0
  23. package/dist/development/react-client/index.js +0 -2
  24. package/dist/development/routing/config.js +18 -1
  25. package/dist/development/server/react-server/RequestLocale.js +15 -25
  26. package/dist/development/server/react-server/RequestLocaleCache.js +23 -0
  27. package/dist/development/server/react-server/RequestLocaleLegacy.js +43 -0
  28. package/dist/development/server/react-server/getConfig.js +15 -17
  29. package/dist/development/server/react-server/getRequestConfig.js +1 -1
  30. package/dist/development/server.react-server.js +2 -2
  31. package/dist/development/shared/constants.js +0 -9
  32. package/dist/esm/middleware/middleware.js +1 -1
  33. package/dist/esm/middleware/resolveLocale.js +1 -1
  34. package/dist/esm/middleware/syncCookie.js +1 -1
  35. package/dist/esm/navigation/react-client/ClientLink.js +1 -1
  36. package/dist/esm/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
  37. package/dist/esm/navigation/react-client/createNavigation.js +1 -0
  38. package/dist/esm/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
  39. package/dist/esm/navigation/react-client/useBasePathname.js +0 -1
  40. package/dist/esm/navigation/react-client/useBaseRouter.js +1 -1
  41. package/dist/esm/navigation/react-server/ServerLink.js +1 -1
  42. package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  43. package/dist/esm/navigation/react-server/createNavigation.js +1 -0
  44. package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
  45. package/dist/esm/navigation/react-server/redirects.js +1 -1
  46. package/dist/esm/navigation/shared/BaseLink.js +1 -1
  47. package/dist/esm/navigation/shared/LegacyBaseLink.js +2 -0
  48. package/dist/esm/navigation/shared/createSharedNavigationFns.js +1 -0
  49. package/dist/esm/navigation/shared/syncLocaleCookie.js +1 -1
  50. package/dist/esm/navigation/shared/utils.js +1 -1
  51. package/dist/esm/navigation.react-client.js +1 -1
  52. package/dist/esm/navigation.react-server.js +1 -1
  53. package/dist/esm/routing/config.js +1 -1
  54. package/dist/esm/server/react-server/RequestLocale.js +1 -1
  55. package/dist/esm/server/react-server/RequestLocaleCache.js +1 -0
  56. package/dist/esm/server/react-server/RequestLocaleLegacy.js +1 -0
  57. package/dist/esm/server/react-server/getConfig.js +1 -1
  58. package/dist/esm/server.react-server.js +1 -1
  59. package/dist/esm/shared/constants.js +1 -1
  60. package/dist/production/middleware/middleware.js +1 -1
  61. package/dist/production/middleware/resolveLocale.js +1 -1
  62. package/dist/production/middleware/syncCookie.js +1 -1
  63. package/dist/production/navigation/react-client/ClientLink.js +1 -1
  64. package/dist/production/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
  65. package/dist/production/navigation/react-client/createNavigation.js +1 -0
  66. package/dist/production/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
  67. package/dist/production/navigation/react-client/useBasePathname.js +0 -1
  68. package/dist/production/navigation/react-client/useBaseRouter.js +1 -1
  69. package/dist/production/navigation/react-server/ServerLink.js +1 -1
  70. package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  71. package/dist/production/navigation/react-server/createNavigation.js +1 -0
  72. package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
  73. package/dist/production/navigation/react-server/redirects.js +1 -1
  74. package/dist/production/navigation/shared/BaseLink.js +1 -1
  75. package/dist/production/navigation/shared/LegacyBaseLink.js +2 -0
  76. package/dist/production/navigation/shared/createSharedNavigationFns.js +1 -0
  77. package/dist/production/navigation/shared/syncLocaleCookie.js +1 -1
  78. package/dist/production/navigation/shared/utils.js +1 -1
  79. package/dist/production/navigation.react-client.js +1 -1
  80. package/dist/production/navigation.react-server.js +1 -1
  81. package/dist/production/routing/config.js +1 -1
  82. package/dist/production/server/react-server/RequestLocale.js +1 -1
  83. package/dist/production/server/react-server/RequestLocaleCache.js +1 -0
  84. package/dist/production/server/react-server/RequestLocaleLegacy.js +1 -0
  85. package/dist/production/server/react-server/getConfig.js +1 -1
  86. package/dist/production/server.react-server.js +1 -1
  87. package/dist/production/shared/constants.js +1 -1
  88. package/dist/types/src/middleware/getAlternateLinksHeaderValue.d.ts +3 -3
  89. package/dist/types/src/middleware/middleware.d.ts +11 -3
  90. package/dist/types/src/middleware/resolveLocale.d.ts +2 -3
  91. package/dist/types/src/middleware/syncCookie.d.ts +2 -1
  92. package/dist/types/src/middleware/utils.d.ts +4 -4
  93. package/dist/types/src/navigation/createNavigation.test.d.ts +1 -0
  94. package/dist/types/src/navigation/react-client/ClientLink.d.ts +6 -6
  95. package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.d.ts +17 -5
  96. package/dist/types/src/navigation/react-client/createNavigation.d.ts +467 -0
  97. package/dist/types/src/navigation/react-client/createNavigation.test.d.ts +1 -0
  98. package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +9 -5
  99. package/dist/types/src/navigation/react-client/index.d.ts +1 -0
  100. package/dist/types/src/navigation/react-client/redirects.d.ts +4 -4
  101. package/dist/types/src/navigation/react-client/useBasePathname.d.ts +2 -15
  102. package/dist/types/src/navigation/react-client/useBaseRouter.d.ts +3 -2
  103. package/dist/types/src/navigation/react-server/ServerLink.d.ts +5 -5
  104. package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +14 -5
  105. package/dist/types/src/navigation/react-server/createNavigation.d.ts +385 -0
  106. package/dist/types/src/navigation/react-server/createNavigation.test.d.ts +1 -0
  107. package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +3 -3
  108. package/dist/types/src/navigation/react-server/index.d.ts +1 -0
  109. package/dist/types/src/navigation/react-server/redirects.d.ts +4 -4
  110. package/dist/types/src/navigation/shared/BaseLink.d.ts +13 -6
  111. package/dist/types/src/navigation/shared/LegacyBaseLink.d.ts +12 -0
  112. package/dist/types/src/navigation/shared/createSharedNavigationFns.d.ts +385 -0
  113. package/dist/types/src/navigation/shared/redirects.d.ts +5 -5
  114. package/dist/types/src/navigation/shared/syncLocaleCookie.d.ts +2 -1
  115. package/dist/types/src/navigation/shared/utils.d.ts +10 -3
  116. package/dist/types/src/routing/config.d.ts +46 -11
  117. package/dist/types/src/routing/defineRouting.d.ts +2 -2
  118. package/dist/types/src/routing/types.d.ts +4 -4
  119. package/dist/types/src/server/react-server/RequestLocale.d.ts +1 -2
  120. package/dist/types/src/server/react-server/RequestLocaleCache.d.ts +2 -0
  121. package/dist/types/src/server/react-server/RequestLocaleLegacy.d.ts +1 -0
  122. package/dist/types/src/server/react-server/createRequestConfig.d.ts +2 -3
  123. package/dist/types/src/server/react-server/getRequestConfig.d.ts +32 -6
  124. package/dist/types/src/server/react-server/index.d.ts +1 -1
  125. package/dist/types/src/shared/constants.d.ts +0 -3
  126. package/dist/types/src/shared/types.d.ts +3 -0
  127. package/dist/types/src/shared/utils.d.ts +2 -2
  128. package/package.json +3 -3
  129. package/dist/types/src/middleware/config.d.ts +0 -7
@@ -1,20 +1,46 @@
1
1
  import type { IntlConfig } from 'use-intl/core';
2
- type RequestConfig = Omit<IntlConfig, 'locale'> & {
2
+ export type RequestConfig = Omit<IntlConfig, 'locale'> & {
3
3
  /**
4
- * Instead of reading a `locale` from the argument that's passed to the
4
+ * Instead of reading a `requestLocale` from the argument that's passed to the
5
5
  * function within `getRequestConfig`, you can include a locale as part of the
6
6
  * returned request configuration.
7
7
  *
8
- * This is helpful for apps that only support a single language and for apps
9
- * where the locale should be read from user settings instead of the pathname.
8
+ * This can be helpful for the following use cases:
9
+ * - Apps that only support a single language
10
+ * - Apps where the locale should be read from user settings instead of the pathname
11
+ * - Providing a fallback locale in case the locale was not matched by the middleware
10
12
  **/
11
13
  locale?: IntlConfig['locale'];
12
14
  };
13
15
  export type GetRequestConfigParams = {
16
+ /**
17
+ * Deprecated in favor of `requestLocale` (see https://github.com/amannn/next-intl/pull/1383).
18
+ *
19
+ * The locale that was matched by the `[locale]` path segment. Note however
20
+ * that this can be overridden in async APIs when the `locale` is explicitly
21
+ * passed (e.g. `getTranslations({locale: 'en'})`).
22
+ *
23
+ * @deprecated
24
+ */
14
25
  locale: string;
26
+ /**
27
+ * Typically corresponds to the `[locale]` segment that was matched by the middleware.
28
+ *
29
+ * However, there are three special cases to consider:
30
+ * 1. **Overrides**: When an explicit `locale` is passed to awaitable functions
31
+ * like `getTranslations({locale: 'en'})`, then this value will be used
32
+ * instead of the segment.
33
+ * 2. **`undefined`**: The value can be `undefined` when a page outside of the
34
+ * `[locale]` segment renders (e.g. a language selection page at `app/page.tsx`).
35
+ * 3. **Invalid values**: Since the `[locale]` segment effectively acts like a
36
+ * catch-all for unknown routes (e.g. `/unknown.txt`), invalid values should
37
+ * be replaced with a valid locale.
38
+ *
39
+ * @see https://next-intl-docs.vercel.app/docs/usage/configuration#i18n-request
40
+ */
41
+ requestLocale: Promise<string | undefined>;
15
42
  };
16
43
  /**
17
- * Should be called in `i18n.ts` to create the configuration for the current request.
44
+ * Should be called in `i18n/request.ts` to create the configuration for the current request.
18
45
  */
19
46
  export default function getRequestConfig(createRequestConfig: (params: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>): (params: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>;
20
- export {};
@@ -8,4 +8,4 @@ export { default as getTimeZone } from './getTimeZone';
8
8
  export { default as getTranslations } from './getTranslations';
9
9
  export { default as getMessages } from './getMessages';
10
10
  export { default as getLocale } from './getLocale';
11
- export { setRequestLocale as unstable_setRequestLocale } from './RequestLocale';
11
+ export { setCachedRequestLocale as unstable_setRequestLocale } from './RequestLocaleCache';
@@ -1,6 +1,3 @@
1
- export declare const COOKIE_LOCALE_NAME = "NEXT_LOCALE";
2
- export declare const COOKIE_MAX_AGE = 31536000;
3
- export declare const COOKIE_SAME_SITE = "lax";
4
1
  export declare const COOKIE_BASE_PATH_NAME = "NEXT_INTL_BASE_PATH";
5
2
  export declare const HEADER_LOCALE_NAME = "X-NEXT-INTL-LOCALE";
6
3
  export declare const LOCALE_SEGMENT_NAME = "locale";
@@ -1,2 +1,5 @@
1
1
  export type ParametersExceptFirst<Fn> = Fn extends (arg0: any, ...rest: infer R) => any ? R : never;
2
2
  export type ParametersExceptFirstTwo<Fn> = Fn extends (arg0: any, arg1: any, ...rest: infer R) => any ? R : never;
3
+ export type Prettify<Type> = {
4
+ [Key in keyof Type]: Type[Key];
5
+ } & {};
@@ -1,7 +1,7 @@
1
1
  import { UrlObject } from 'url';
2
2
  import NextLink from 'next/link';
3
3
  import { ComponentProps } from 'react';
4
- import { Locales, LocalePrefixConfigVerbose } from '../routing/types';
4
+ import { Locales, LocalePrefixConfigVerbose, LocalePrefixMode } from '../routing/types';
5
5
  type Href = ComponentProps<typeof NextLink>['href'];
6
6
  export declare function isLocalizableHref(href: Href): boolean;
7
7
  export declare function localizeHref(href: string, locale: string, curLocale: string, curPathname: string, prefix: string): string;
@@ -17,7 +17,7 @@ export declare function matchesPathname(
17
17
  template: string,
18
18
  /** E.g. `/users/23-jane` */
19
19
  pathname: string): boolean;
20
- export declare function getLocalePrefix<AppLocales extends Locales>(locale: AppLocales[number], localePrefix: LocalePrefixConfigVerbose<AppLocales>): string;
20
+ export declare function getLocalePrefix<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode>(locale: AppLocales[number], localePrefix: LocalePrefixConfigVerbose<AppLocales, AppLocalePrefixMode>): string;
21
21
  export declare function templateToRegex(template: string): RegExp;
22
22
  export declare function getSortedPathnames(pathnames: Array<string>): string[];
23
23
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.21.1",
3
+ "version": "3.21.2-canary.0",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -87,11 +87,11 @@
87
87
  "dependencies": {
88
88
  "@formatjs/intl-localematcher": "^0.5.4",
89
89
  "negotiator": "^0.6.3",
90
- "use-intl": "^3.21.1"
90
+ "use-intl": "^3.21.2-canary.0"
91
91
  },
92
92
  "peerDependencies": {
93
93
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
94
94
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
95
95
  },
96
- "gitHead": "cd3d7a2c76a3824b176e00957ff69b2dda2b879b"
96
+ "gitHead": "55bb437395fc4d6d3886fdd7c058b843022630b8"
97
97
  }
@@ -1,7 +0,0 @@
1
- export type MiddlewareOptions = {
2
- /** Sets the `Link` response header to notify search engines about content in other languages (defaults to `true`). See https://developers.google.com/search/docs/specialty/international/localized-versions#http */
3
- alternateLinks?: boolean;
4
- /** By setting this to `false`, the cookie as well as the `accept-language` header will no longer be used for locale detection. */
5
- localeDetection?: boolean;
6
- };
7
- export type ResolvedMiddlewareOptions = Required<MiddlewareOptions>;