next-intl 3.21.0-canary.0 → 3.21.1

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 (106) hide show
  1. package/dist/development/middleware/middleware.js +6 -6
  2. package/dist/development/middleware/resolveLocale.js +7 -2
  3. package/dist/development/navigation/react-client/ClientLink.js +2 -2
  4. package/dist/development/navigation/react-client/useBasePathname.js +14 -0
  5. package/dist/development/navigation/react-server/ServerLink.js +2 -4
  6. package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +4 -4
  7. package/dist/development/navigation/react-server/redirects.js +2 -2
  8. package/dist/development/navigation/shared/BaseLink.js +25 -28
  9. package/dist/development/navigation/shared/redirects.js +0 -3
  10. package/dist/development/navigation/shared/utils.js +1 -40
  11. package/dist/development/navigation.react-client.js +0 -2
  12. package/dist/development/navigation.react-server.js +0 -2
  13. package/dist/development/react-client/index.js +2 -0
  14. package/dist/development/routing/config.js +1 -1
  15. package/dist/development/server/react-server/RequestLocale.js +25 -15
  16. package/dist/development/server/react-server/getConfig.js +17 -15
  17. package/dist/development/server/react-server/getRequestConfig.js +1 -1
  18. package/dist/development/server.react-server.js +2 -2
  19. package/dist/esm/middleware/middleware.js +1 -1
  20. package/dist/esm/middleware/resolveLocale.js +1 -1
  21. package/dist/esm/navigation/react-client/ClientLink.js +1 -1
  22. package/dist/esm/navigation/react-client/useBasePathname.js +1 -0
  23. package/dist/esm/navigation/react-server/ServerLink.js +1 -1
  24. package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  25. package/dist/esm/navigation/react-server/redirects.js +1 -1
  26. package/dist/esm/navigation/shared/BaseLink.js +1 -1
  27. package/dist/esm/navigation/shared/utils.js +1 -1
  28. package/dist/esm/navigation.react-client.js +1 -1
  29. package/dist/esm/navigation.react-server.js +1 -1
  30. package/dist/esm/routing/config.js +1 -1
  31. package/dist/esm/server/react-server/RequestLocale.js +1 -1
  32. package/dist/esm/server/react-server/getConfig.js +1 -1
  33. package/dist/esm/server.react-server.js +1 -1
  34. package/dist/production/middleware/middleware.js +1 -1
  35. package/dist/production/middleware/resolveLocale.js +1 -1
  36. package/dist/production/navigation/react-client/ClientLink.js +1 -1
  37. package/dist/production/navigation/react-client/useBasePathname.js +1 -0
  38. package/dist/production/navigation/react-server/ServerLink.js +1 -1
  39. package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  40. package/dist/production/navigation/react-server/redirects.js +1 -1
  41. package/dist/production/navigation/shared/BaseLink.js +1 -1
  42. package/dist/production/navigation/shared/utils.js +1 -1
  43. package/dist/production/navigation.react-client.js +1 -1
  44. package/dist/production/navigation.react-server.js +1 -1
  45. package/dist/production/routing/config.js +1 -1
  46. package/dist/production/server/react-server/RequestLocale.js +1 -1
  47. package/dist/production/server/react-server/getConfig.js +1 -1
  48. package/dist/production/server.react-server.js +1 -1
  49. package/dist/types/src/middleware/getAlternateLinksHeaderValue.d.ts +3 -3
  50. package/dist/types/src/middleware/middleware.d.ts +2 -2
  51. package/dist/types/src/middleware/resolveLocale.d.ts +2 -2
  52. package/dist/types/src/middleware/utils.d.ts +4 -4
  53. package/dist/types/src/navigation/react-client/ClientLink.d.ts +6 -6
  54. package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.d.ts +4 -12
  55. package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +4 -4
  56. package/dist/types/src/navigation/react-client/index.d.ts +0 -1
  57. package/dist/types/src/navigation/react-client/redirects.d.ts +4 -4
  58. package/dist/types/src/navigation/react-client/useBasePathname.d.ts +15 -2
  59. package/dist/types/src/navigation/react-client/useBaseRouter.d.ts +2 -2
  60. package/dist/types/src/navigation/react-server/ServerLink.d.ts +5 -5
  61. package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +4 -12
  62. package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +3 -3
  63. package/dist/types/src/navigation/react-server/index.d.ts +0 -1
  64. package/dist/types/src/navigation/react-server/redirects.d.ts +4 -4
  65. package/dist/types/src/navigation/shared/BaseLink.d.ts +6 -11
  66. package/dist/types/src/navigation/shared/redirects.d.ts +5 -5
  67. package/dist/types/src/navigation/shared/utils.d.ts +3 -10
  68. package/dist/types/src/react-server/getTranslator.d.ts +9 -0
  69. package/dist/types/src/routing/config.d.ts +11 -19
  70. package/dist/types/src/routing/defineRouting.d.ts +2 -2
  71. package/dist/types/src/routing/types.d.ts +4 -4
  72. package/dist/types/src/server/react-server/RequestLocale.d.ts +2 -1
  73. package/dist/types/src/server/react-server/createRequestConfig.d.ts +3 -2
  74. package/dist/types/src/server/react-server/getRequestConfig.d.ts +6 -32
  75. package/dist/types/src/server/react-server/getTranslations.d.ts +9 -0
  76. package/dist/types/src/server/react-server/index.d.ts +1 -1
  77. package/dist/types/src/shared/types.d.ts +0 -3
  78. package/dist/types/src/shared/utils.d.ts +2 -2
  79. package/package.json +3 -3
  80. package/dist/development/navigation/react-client/createNavigation.js +0 -83
  81. package/dist/development/navigation/react-server/createNavigation.js +0 -30
  82. package/dist/development/navigation/shared/LegacyBaseLink.js +0 -55
  83. package/dist/development/navigation/shared/createSharedNavigationFns.js +0 -147
  84. package/dist/development/server/react-server/RequestLocaleCache.js +0 -23
  85. package/dist/development/server/react-server/RequestLocaleLegacy.js +0 -43
  86. package/dist/esm/navigation/react-client/createNavigation.js +0 -1
  87. package/dist/esm/navigation/react-server/createNavigation.js +0 -1
  88. package/dist/esm/navigation/shared/LegacyBaseLink.js +0 -2
  89. package/dist/esm/navigation/shared/createSharedNavigationFns.js +0 -1
  90. package/dist/esm/server/react-server/RequestLocaleCache.js +0 -1
  91. package/dist/esm/server/react-server/RequestLocaleLegacy.js +0 -1
  92. package/dist/production/navigation/react-client/createNavigation.js +0 -1
  93. package/dist/production/navigation/react-server/createNavigation.js +0 -1
  94. package/dist/production/navigation/shared/LegacyBaseLink.js +0 -2
  95. package/dist/production/navigation/shared/createSharedNavigationFns.js +0 -1
  96. package/dist/production/server/react-server/RequestLocaleCache.js +0 -1
  97. package/dist/production/server/react-server/RequestLocaleLegacy.js +0 -1
  98. package/dist/types/src/navigation/createNavigation.test.d.ts +0 -1
  99. package/dist/types/src/navigation/react-client/createNavigation.d.ts +0 -467
  100. package/dist/types/src/navigation/react-client/createNavigation.test.d.ts +0 -1
  101. package/dist/types/src/navigation/react-server/createNavigation.d.ts +0 -385
  102. package/dist/types/src/navigation/react-server/createNavigation.test.d.ts +0 -1
  103. package/dist/types/src/navigation/shared/LegacyBaseLink.d.ts +0 -10
  104. package/dist/types/src/navigation/shared/createSharedNavigationFns.d.ts +0 -382
  105. package/dist/types/src/server/react-server/RequestLocaleCache.d.ts +0 -2
  106. package/dist/types/src/server/react-server/RequestLocaleLegacy.d.ts +0 -1
@@ -1,7 +1,6 @@
1
1
  import type { ParsedUrlQueryInput } from 'node:querystring';
2
2
  import type { UrlObject } from 'url';
3
- import { ResolvedRoutingConfig } from '../../routing/config';
4
- import { DomainsConfig, LocalePrefixMode, Locales, Pathnames } from '../../routing/types';
3
+ import { Locales, Pathnames } from '../../routing/types';
5
4
  import StrictParams from './StrictParams';
6
5
  type SearchParamValue = ParsedUrlQueryInput[keyof ParsedUrlQueryInput];
7
6
  type HrefOrHrefWithParamsImpl<Pathname, Other> = Pathname extends `${string}[[...${string}` ? // Optional catch-all
@@ -17,14 +16,10 @@ Pathname | ({
17
16
  pathname: Pathname;
18
17
  } & Other);
19
18
  export type HrefOrUrlObjectWithParams<Pathname> = HrefOrHrefWithParamsImpl<Pathname, Omit<UrlObject, 'pathname'>>;
20
- export type QueryParams = Record<string, SearchParamValue>;
21
19
  export type HrefOrHrefWithParams<Pathname> = HrefOrHrefWithParamsImpl<Pathname, {
22
- query?: QueryParams;
20
+ query?: Record<string, SearchParamValue>;
23
21
  }>;
24
- export declare function normalizeNameOrNameWithParams<Pathname>(href: HrefOrHrefWithParams<Pathname> | {
25
- locale: string;
26
- href: HrefOrHrefWithParams<Pathname>;
27
- }): {
22
+ export declare function normalizeNameOrNameWithParams<Pathname>(href: HrefOrHrefWithParams<Pathname>): {
28
23
  pathname: Pathname;
29
24
  params?: StrictParams<Pathname>;
30
25
  };
@@ -48,6 +43,4 @@ export declare function compileLocalizedPathname<AppLocales extends Locales, Pat
48
43
  }): UrlObject;
49
44
  export declare function getRoute<AppLocales extends Locales>(locale: AppLocales[number], pathname: string, pathnames: Pathnames<AppLocales>): keyof Pathnames<AppLocales>;
50
45
  export declare function getBasePath(pathname: string, windowPathname?: string): string;
51
- export declare function applyPathnamePrefix<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode, AppPathnames extends Pathnames<AppLocales> | undefined, AppDomains extends DomainsConfig<AppLocales> | undefined>(pathname: string, locale: Locales[number], routing: Pick<ResolvedRoutingConfig<AppLocales, AppLocalePrefixMode, AppPathnames, AppDomains>, 'localePrefix' | 'domains'> & Partial<Pick<ResolvedRoutingConfig<AppLocales, AppLocalePrefixMode, AppPathnames, AppDomains>, 'defaultLocale'>>, domain?: string, force?: boolean): string;
52
- export declare function validateReceivedConfig<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode, AppPathnames extends Pathnames<AppLocales> | undefined, AppDomains extends DomainsConfig<AppLocales> | undefined>(config: Partial<Pick<ResolvedRoutingConfig<AppLocales, AppLocalePrefixMode, AppPathnames, AppDomains>, 'defaultLocale' | 'localePrefix'>>): void;
53
46
  export {};
@@ -37,6 +37,15 @@ declare function getTranslatorImpl<NestedKey extends NamespaceKeys<IntlMessages,
37
37
  }, [
38
38
  NestedKey
39
39
  ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
40
+ has<TargetKey extends MessageKeys<NestedValueOf<{
41
+ '!': IntlMessages;
42
+ }, [
43
+ NestedKey
44
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
45
+ '!': IntlMessages;
46
+ }, [
47
+ NestedKey
48
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): boolean;
40
49
  };
41
50
  declare const _default: typeof getTranslatorImpl;
42
51
  export default _default;
@@ -1,5 +1,5 @@
1
- import { Locales, LocalePrefix, LocalePrefixConfigVerbose, DomainsConfig, Pathnames, LocalePrefixMode } from './types';
2
- export type RoutingConfig<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode, AppPathnames extends Pathnames<AppLocales> | undefined, AppDomains extends DomainsConfig<AppLocales> | undefined> = {
1
+ import { Locales, LocalePrefix, LocalePrefixConfigVerbose, DomainsConfig, Pathnames } from './types';
2
+ export type RoutingConfig<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>> = {
3
3
  /**
4
4
  * All available locales.
5
5
  * @see https://next-intl-docs.vercel.app/docs/routing
@@ -14,12 +14,12 @@ export type RoutingConfig<AppLocales extends Locales, AppLocalePrefixMode extend
14
14
  * Configures whether and which prefix is shown for a given locale.
15
15
  * @see https://next-intl-docs.vercel.app/docs/routing#locale-prefix
16
16
  **/
17
- localePrefix?: LocalePrefix<AppLocales, AppLocalePrefixMode>;
17
+ localePrefix?: LocalePrefix<AppLocales>;
18
18
  /**
19
19
  * Can be used to change the locale handling per domain.
20
20
  * @see https://next-intl-docs.vercel.app/docs/routing#domains
21
21
  **/
22
- domains?: AppDomains;
22
+ domains?: DomainsConfig<AppLocales>;
23
23
  } & ([AppPathnames] extends [never] ? {} : {
24
24
  /**
25
25
  * A map of localized pathnames per locale.
@@ -27,22 +27,14 @@ export type RoutingConfig<AppLocales extends Locales, AppLocalePrefixMode extend
27
27
  **/
28
28
  pathnames: AppPathnames;
29
29
  });
30
- export type RoutingConfigSharedNavigation<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode, AppDomains extends DomainsConfig<AppLocales> = never> = Omit<RoutingConfig<AppLocales, AppLocalePrefixMode, never, AppDomains>, 'defaultLocale' | 'locales' | 'pathnames'> & Partial<Pick<RoutingConfig<AppLocales, never, never, AppDomains>, 'defaultLocale' | 'locales'>>;
31
- export type RoutingConfigLocalizedNavigation<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode, AppPathnames extends Pathnames<AppLocales>, AppDomains extends DomainsConfig<AppLocales> = never> = Omit<RoutingConfig<AppLocales, AppLocalePrefixMode, AppPathnames, AppDomains>, 'defaultLocale' | 'pathnames'> & Partial<Pick<RoutingConfig<AppLocales, AppLocalePrefixMode, AppPathnames, AppDomains>, 'defaultLocale'>> & {
30
+ export type RoutingConfigSharedNavigation<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>> = Omit<RoutingConfig<AppLocales, AppPathnames>, 'defaultLocale' | 'locales' | 'pathnames'> & Partial<Pick<RoutingConfig<AppLocales, AppPathnames>, 'defaultLocale' | 'locales'>>;
31
+ export type RoutingConfigLocalizedNavigation<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>> = Omit<RoutingConfig<AppLocales, AppPathnames>, 'defaultLocale' | 'pathnames'> & Partial<Pick<RoutingConfig<AppLocales, AppPathnames>, 'defaultLocale'>> & {
32
32
  pathnames: AppPathnames;
33
33
  };
34
- export type ResolvedRoutingConfig<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode, AppPathnames extends Pathnames<AppLocales> | undefined, AppDomains extends DomainsConfig<AppLocales> | undefined> = Omit<RoutingConfig<AppLocales, AppLocalePrefixMode, AppPathnames, AppDomains>, 'localePrefix'> & {
35
- localePrefix: LocalePrefixConfigVerbose<AppLocales, AppLocalePrefixMode>;
34
+ export type ResolvedRoutingConfig<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales> = never> = Omit<RoutingConfig<AppLocales, AppPathnames>, 'localePrefix'> & {
35
+ localePrefix: LocalePrefixConfigVerbose<AppLocales>;
36
36
  };
37
- export declare function receiveRoutingConfig<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode, AppPathnames extends Pathnames<AppLocales> | undefined, AppDomains extends DomainsConfig<AppLocales> | undefined, Config extends Partial<RoutingConfig<AppLocales, AppLocalePrefixMode, AppPathnames, AppDomains>>>(input: Config): Omit<Config, "localePrefix"> & {
38
- localePrefix: {
39
- mode: "never";
40
- } | {
41
- mode: "always";
42
- prefixes?: Partial<Record<AppLocales[number], string>> | undefined;
43
- } | {
44
- mode: "as-needed";
45
- prefixes?: Partial<Record<AppLocales[number], string>> | undefined;
46
- };
37
+ export declare function receiveRoutingConfig<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>, Config extends Partial<RoutingConfig<AppLocales, AppPathnames>>>(input: Config): Config & {
38
+ localePrefix: LocalePrefixConfigVerbose<AppLocales>;
47
39
  };
48
- export declare function receiveLocalePrefixConfig<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode>(localePrefix?: LocalePrefix<AppLocales, AppLocalePrefixMode>): LocalePrefixConfigVerbose<AppLocales, AppLocalePrefixMode>;
40
+ export declare function receiveLocalePrefixConfig<AppLocales extends Locales>(localePrefix?: LocalePrefix<AppLocales>): LocalePrefixConfigVerbose<AppLocales>;
@@ -1,3 +1,3 @@
1
1
  import { RoutingConfig } from './config';
2
- import { DomainsConfig, LocalePrefixMode, Locales, Pathnames } from './types';
3
- export default function defineRouting<const AppLocales extends Locales, const AppLocalePrefixMode extends LocalePrefixMode = 'always', const AppPathnames extends Pathnames<AppLocales> = never, const AppDomains extends DomainsConfig<AppLocales> = never>(config: RoutingConfig<AppLocales, AppLocalePrefixMode, AppPathnames, AppDomains>): RoutingConfig<AppLocales, AppLocalePrefixMode, AppPathnames, AppDomains>;
2
+ import { Locales, Pathnames } from './types';
3
+ export default function defineRouting<const AppLocales extends Locales, const AppPathnames extends Pathnames<AppLocales> = never>(config: RoutingConfig<AppLocales, AppPathnames>): RoutingConfig<AppLocales, AppPathnames>;
@@ -2,16 +2,16 @@ export type Locales = ReadonlyArray<string>;
2
2
  export type LocalePrefixMode = 'always' | 'as-needed' | 'never';
3
3
  type Pathname = string;
4
4
  export type LocalePrefixes<AppLocales extends Locales> = Partial<Record<AppLocales[number], Pathname>>;
5
- export type LocalePrefixConfigVerbose<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode> = AppLocalePrefixMode extends 'always' ? {
5
+ export type LocalePrefixConfigVerbose<AppLocales extends Locales> = {
6
6
  mode: 'always';
7
7
  prefixes?: LocalePrefixes<AppLocales>;
8
- } : AppLocalePrefixMode extends 'as-needed' ? {
8
+ } | {
9
9
  mode: 'as-needed';
10
10
  prefixes?: LocalePrefixes<AppLocales>;
11
- } : {
11
+ } | {
12
12
  mode: 'never';
13
13
  };
14
- export type LocalePrefix<AppLocales extends Locales = [], AppLocalePrefixMode extends LocalePrefixMode = 'always'> = AppLocalePrefixMode | LocalePrefixConfigVerbose<AppLocales, AppLocalePrefixMode>;
14
+ export type LocalePrefix<AppLocales extends Locales = never> = LocalePrefixMode | LocalePrefixConfigVerbose<AppLocales>;
15
15
  export type Pathnames<AppLocales extends Locales> = Record<Pathname, Record<AppLocales[number], Pathname> | Pathname>;
16
16
  export type DomainConfig<AppLocales extends Locales> = {
17
17
  defaultLocale: AppLocales[number];
@@ -1 +1,2 @@
1
- export declare function getRequestLocale(): Promise<string | undefined>;
1
+ export declare function setRequestLocale(locale: string): void;
2
+ export declare function getRequestLocale(): string;
@@ -1,3 +1,4 @@
1
- import type { GetRequestConfigParams, RequestConfig } from './getRequestConfig';
2
- declare const _default: (params: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>;
1
+ import type { IntlConfig } from 'use-intl/core';
2
+ import type { GetRequestConfigParams } from './getRequestConfig';
3
+ declare const _default: (params: GetRequestConfigParams) => IntlConfig | Promise<IntlConfig>;
3
4
  export default _default;
@@ -1,46 +1,20 @@
1
1
  import type { IntlConfig } from 'use-intl/core';
2
- export type RequestConfig = Omit<IntlConfig, 'locale'> & {
2
+ type RequestConfig = Omit<IntlConfig, 'locale'> & {
3
3
  /**
4
- * Instead of reading a `requestLocale` from the argument that's passed to the
4
+ * Instead of reading a `locale` 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 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
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.
12
10
  **/
13
11
  locale?: IntlConfig['locale'];
14
12
  };
15
13
  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
- */
25
14
  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>;
42
15
  };
43
16
  /**
44
- * Should be called in `i18n/request.ts` to create the configuration for the current request.
17
+ * Should be called in `i18n.ts` to create the configuration for the current request.
45
18
  */
46
19
  export default function getRequestConfig(createRequestConfig: (params: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>): (params: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>;
20
+ export {};
@@ -37,6 +37,15 @@ declare function getTranslations<NestedKey extends NamespaceKeys<IntlMessages, N
37
37
  }, [
38
38
  NestedKey
39
39
  ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: [TargetKey] extends [never] ? string : TargetKey): any;
40
+ has<TargetKey extends MessageKeys<NestedValueOf<{
41
+ '!': IntlMessages;
42
+ }, [
43
+ NestedKey
44
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
45
+ '!': IntlMessages;
46
+ }, [
47
+ NestedKey
48
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: [TargetKey] extends [never] ? string : TargetKey): boolean;
40
49
  }>;
41
50
  declare function getTranslations<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>(opts?: {
42
51
  locale: string;
@@ -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 { setCachedRequestLocale as unstable_setRequestLocale } from './RequestLocaleCache';
11
+ export { setRequestLocale as unstable_setRequestLocale } from './RequestLocale';
@@ -1,5 +1,2 @@
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, LocalePrefixMode } from '../routing/types';
4
+ import { Locales, LocalePrefixConfigVerbose } 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, AppLocalePrefixMode extends LocalePrefixMode>(locale: AppLocales[number], localePrefix: LocalePrefixConfigVerbose<AppLocales, AppLocalePrefixMode>): string;
20
+ export declare function getLocalePrefix<AppLocales extends Locales>(locale: AppLocales[number], localePrefix: LocalePrefixConfigVerbose<AppLocales>): 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.0-canary.0",
3
+ "version": "3.21.1",
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.0-canary.0"
90
+ "use-intl": "^3.21.1"
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": "3105da4fefa30e07be10849ca72e515034e5fe9b"
96
+ "gitHead": "cd3d7a2c76a3824b176e00957ff69b2dda2b879b"
97
97
  }
@@ -1,83 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var navigation = require('next/navigation');
6
- var React = require('react');
7
- var useLocale = require('../../react-client/useLocale.js');
8
- var createSharedNavigationFns = require('../shared/createSharedNavigationFns.js');
9
- var syncLocaleCookie = require('../shared/syncLocaleCookie.js');
10
- var utils = require('../shared/utils.js');
11
- var useBasePathname = require('./useBasePathname.js');
12
-
13
- function createNavigation(routing) {
14
- function useTypedLocale() {
15
- return useLocale.default();
16
- }
17
- const {
18
- Link,
19
- config,
20
- getPathname,
21
- ...redirects
22
- } = createSharedNavigationFns.default(useTypedLocale, routing);
23
-
24
- /** @see https://next-intl-docs.vercel.app/docs/routing/navigation#usepathname */
25
- function usePathname() {
26
- const pathname = useBasePathname.default(config.localePrefix);
27
- const locale = useTypedLocale();
28
-
29
- // @ts-expect-error -- Mirror the behavior from Next.js, where `null` is returned when `usePathname` is used outside of Next, but the types indicate that a string is always returned.
30
- return React.useMemo(() => pathname &&
31
- // @ts-expect-error -- This is fine
32
- config.pathnames ? utils.getRoute(locale, pathname,
33
- // @ts-expect-error -- This is fine
34
- config.pathnames) : pathname, [locale, pathname]);
35
- }
36
- function useRouter() {
37
- const router = navigation.useRouter();
38
- const curLocale = useTypedLocale();
39
- const nextPathname = navigation.usePathname();
40
- return React.useMemo(() => {
41
- function createHandler(fn) {
42
- return function handler(href, options) {
43
- const {
44
- locale: nextLocale,
45
- ...rest
46
- } = options || {};
47
-
48
- // @ts-expect-error -- We're passing a domain here just in case
49
- const pathname = getPathname({
50
- href,
51
- locale: nextLocale || curLocale,
52
- domain: window.location.host
53
- });
54
- const args = [pathname];
55
- if (Object.keys(rest).length > 0) {
56
- // @ts-expect-error -- This is fine
57
- args.push(rest);
58
- }
59
- fn(...args);
60
- syncLocaleCookie.default(nextPathname, curLocale, nextLocale);
61
- };
62
- }
63
- return {
64
- ...router,
65
- /** @see https://next-intl-docs.vercel.app/docs/routing/navigation#userouter */
66
- push: createHandler(router.push),
67
- /** @see https://next-intl-docs.vercel.app/docs/routing/navigation#userouter */
68
- replace: createHandler(router.replace),
69
- /** @see https://next-intl-docs.vercel.app/docs/routing/navigation#userouter */
70
- prefetch: createHandler(router.prefetch)
71
- };
72
- }, [curLocale, nextPathname, router]);
73
- }
74
- return {
75
- ...redirects,
76
- Link,
77
- usePathname,
78
- useRouter,
79
- getPathname
80
- };
81
- }
82
-
83
- exports.default = createNavigation;
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var RequestLocale = require('../../server/react-server/RequestLocale.js');
6
- var createSharedNavigationFns = require('../shared/createSharedNavigationFns.js');
7
-
8
- function createNavigation(routing) {
9
- function getLocale() {
10
- return RequestLocale.getRequestLocale();
11
- }
12
-
13
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
- const {
15
- config,
16
- ...fns
17
- } = createSharedNavigationFns.default(getLocale, routing);
18
- function notSupported(hookName) {
19
- return () => {
20
- throw new Error("`".concat(hookName, "` is not supported in Server Components. You can use this hook if you convert the calling component to a Client Component."));
21
- };
22
- }
23
- return {
24
- ...fns,
25
- usePathname: notSupported('usePathname'),
26
- useRouter: notSupported('useRouter')
27
- };
28
- }
29
-
30
- exports.default = createNavigation;
@@ -1,55 +0,0 @@
1
- "use client";
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
7
- var navigation = require('next/navigation');
8
- var React = require('react');
9
- var useLocale = require('../../react-client/useLocale.js');
10
- var utils = require('../../shared/utils.js');
11
- var BaseLink = require('./BaseLink.js');
12
-
13
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
-
15
- var React__default = /*#__PURE__*/_interopDefault(React);
16
-
17
- function LegacyBaseLink(_ref, ref) {
18
- let {
19
- href,
20
- locale,
21
- localePrefixMode,
22
- prefix,
23
- ...rest
24
- } = _ref;
25
- // The types aren't entirely correct here. Outside of Next.js
26
- // `useParams` can be called, but the return type is `null`.
27
- const pathname = navigation.usePathname();
28
- const curLocale = useLocale.default();
29
- const isChangingLocale = locale !== curLocale;
30
- const [localizedHref, setLocalizedHref] = React.useState(() => utils.isLocalizableHref(href) && (localePrefixMode !== 'never' || isChangingLocale) ?
31
- // For the `localePrefix: 'as-needed' strategy, the href shouldn't
32
- // be prefixed if the locale is the default locale. To determine this, we
33
- // need a) the default locale and b) the information if we use prefixed
34
- // routing. The default locale can vary by domain, therefore during the
35
- // RSC as well as the SSR render, we can't determine the default locale
36
- // statically. Therefore we always prefix the href since this will
37
- // always result in a valid URL, even if it might cause a redirect. This
38
- // is better than pointing to a non-localized href during the server
39
- // render, which would potentially be wrong. The final href is
40
- // determined in the effect below.
41
- utils.prefixHref(href, prefix) : href);
42
- React.useEffect(() => {
43
- if (!pathname) return;
44
- setLocalizedHref(utils.localizeHref(href, locale, curLocale, pathname, prefix));
45
- }, [curLocale, href, locale, pathname, prefix]);
46
- return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
47
- ref: ref,
48
- href: localizedHref,
49
- locale: locale
50
- }, rest));
51
- }
52
- const LegacyBaseLinkWithRef = /*#__PURE__*/React.forwardRef(LegacyBaseLink);
53
- LegacyBaseLinkWithRef.displayName = 'ClientLink';
54
-
55
- exports.default = LegacyBaseLinkWithRef;
@@ -1,147 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
- var navigation = require('next/navigation');
7
- var React = require('react');
8
- var config = require('../../routing/config.js');
9
- var utils$1 = require('../../shared/utils.js');
10
- var BaseLink = require('./BaseLink.js');
11
- var utils = require('./utils.js');
12
-
13
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
-
15
- var React__default = /*#__PURE__*/_interopDefault(React);
16
-
17
- /**
18
- * Shared implementations for `react-server` and `react-client`
19
- */
20
- function createSharedNavigationFns(getLocale, routing) {
21
- const config$1 = config.receiveRoutingConfig(routing || {});
22
- {
23
- utils.validateReceivedConfig(config$1);
24
- }
25
- const pathnames = config$1.pathnames;
26
-
27
- // This combination requires that the current host is known in order to
28
- // compute a correct pathname. Since that can only be achieved by reading from
29
- // headers, this would break static rendering. Therefore, as a workaround we
30
- // always add a prefix in this case to be on the safe side. The downside is
31
- // that the user might get redirected again if the middleware detects that the
32
- // prefix is not needed.
33
- const forcePrefixSsr = config$1.localePrefix.mode === 'as-needed' && config$1.domains || undefined;
34
- function Link(_ref, ref) {
35
- let {
36
- href,
37
- locale,
38
- ...rest
39
- } = _ref;
40
- let pathname, params;
41
- if (typeof href === 'object') {
42
- pathname = href.pathname;
43
- // @ts-expect-error -- This is ok
44
- params = href.params;
45
- } else {
46
- pathname = href;
47
- }
48
-
49
- // @ts-expect-error -- This is ok
50
- const isLocalizable = utils$1.isLocalizableHref(href);
51
- const localePromiseOrValue = getLocale();
52
- const curLocale = localePromiseOrValue instanceof Promise ? React.use(localePromiseOrValue) : localePromiseOrValue;
53
- const finalPathname = isLocalizable ? getPathname(
54
- // @ts-expect-error -- This is ok
55
- {
56
- locale: locale || curLocale,
57
- href: pathnames == null ? pathname : {
58
- pathname,
59
- params
60
- }
61
- }, locale != null || forcePrefixSsr || undefined) : pathname;
62
- return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
63
- ref: ref
64
- // @ts-expect-error -- Available after the validation
65
- ,
66
- defaultLocale: config$1.defaultLocale,
67
- href: {
68
- ...(typeof href === 'object' && href),
69
- // @ts-expect-error -- This is ok
70
- pathname: finalPathname
71
- },
72
- locale: locale
73
- // Provide the minimal relevant information to the client side in order
74
- // to potentially remove the prefix in case of the `forcePrefixSsr` case
75
- ,
76
- unprefixed: forcePrefixSsr && isLocalizable ? {
77
- domains: config$1.domains.reduce((acc, domain) => {
78
- // @ts-expect-error -- This is ok
79
- acc[domain.domain] = domain.defaultLocale;
80
- return acc;
81
- }, {}),
82
- pathname: getPathname(
83
- // @ts-expect-error -- This is ok
84
- {
85
- locale: curLocale,
86
- href: pathnames == null ? pathname : {
87
- pathname,
88
- params
89
- }
90
- }, false)
91
- } : undefined
92
- }, rest));
93
- }
94
- const LinkWithRef = /*#__PURE__*/React.forwardRef(Link);
95
- function getPathname(args, /** @private Removed in types returned below */
96
- _forcePrefix) {
97
- const {
98
- href,
99
- locale
100
- } = args;
101
- let pathname;
102
- if (pathnames == null) {
103
- if (typeof href === 'object') {
104
- pathname = href.pathname;
105
- if (href.query) {
106
- pathname += utils.serializeSearchParams(href.query);
107
- }
108
- } else {
109
- pathname = href;
110
- }
111
- } else {
112
- pathname = utils.compileLocalizedPathname({
113
- locale,
114
- // @ts-expect-error -- This is ok
115
- ...utils.normalizeNameOrNameWithParams(href),
116
- // @ts-expect-error -- This is ok
117
- pathnames: config$1.pathnames
118
- });
119
- }
120
- return utils.applyPathnamePrefix(pathname, locale, config$1,
121
- // @ts-expect-error -- This is ok
122
- args.domain, _forcePrefix);
123
- }
124
- function getRedirectFn(fn) {
125
- /** @see https://next-intl-docs.vercel.app/docs/routing/navigation#redirect */
126
- return function redirectFn(args) {
127
- for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
128
- rest[_key - 1] = arguments[_key];
129
- }
130
- return fn(
131
- // @ts-expect-error -- We're forcing the prefix when no domain is provided
132
- getPathname(args, args.domain ? undefined : forcePrefixSsr), ...rest);
133
- };
134
- }
135
- const redirect = getRedirectFn(navigation.redirect);
136
- const permanentRedirect = getRedirectFn(navigation.permanentRedirect);
137
- return {
138
- config: config$1,
139
- Link: LinkWithRef,
140
- redirect,
141
- permanentRedirect,
142
- // Remove `_forcePrefix` from public API
143
- getPathname: getPathname
144
- };
145
- }
146
-
147
- exports.default = createSharedNavigationFns;
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var React = require('react');
6
-
7
- // See https://github.com/vercel/next.js/discussions/58862
8
- function getCacheImpl() {
9
- const value = {
10
- locale: undefined
11
- };
12
- return value;
13
- }
14
- const getCache = React.cache(getCacheImpl);
15
- function getCachedRequestLocale() {
16
- return getCache().locale;
17
- }
18
- function setCachedRequestLocale(locale) {
19
- getCache().locale = locale;
20
- }
21
-
22
- exports.getCachedRequestLocale = getCachedRequestLocale;
23
- exports.setCachedRequestLocale = setCachedRequestLocale;