next-intl 2.22.0 → 2.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/config.d.ts +3 -0
- package/dist/config.js +7 -0
- package/dist/development/_virtual/_rollupPluginBabelHelpers.js +20 -0
- package/dist/development/config.js +9 -0
- package/dist/development/index.js +21 -0
- package/dist/development/index.react-server.js +28 -0
- package/dist/development/middleware/getAlternateLinksHeaderValue.js +81 -0
- package/dist/development/middleware/middleware.js +146 -0
- package/dist/development/middleware/resolveLocale.js +110 -0
- package/dist/development/middleware/utils.js +150 -0
- package/dist/development/middleware.js +9 -0
- package/dist/development/navigation/BaseLink.js +52 -0
- package/dist/development/navigation/baseRedirect.js +22 -0
- package/dist/development/navigation/createLocalizedPathnamesNavigation.js +135 -0
- package/dist/development/navigation/createSharedPathnamesNavigation.js +19 -0
- package/dist/development/navigation/react-server/BaseLink.js +25 -0
- package/dist/development/navigation/react-server/baseRedirect.js +16 -0
- package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +77 -0
- package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +22 -0
- package/dist/development/navigation/useBasePathname.js +37 -0
- package/dist/development/navigation/useBaseRouter.js +76 -0
- package/dist/development/navigation/utils.js +108 -0
- package/dist/development/navigation.js +11 -0
- package/dist/development/navigation.react-server.js +11 -0
- package/dist/development/plugin.js +48 -0
- package/dist/development/react-client/index.js +38 -0
- package/dist/development/react-client/useLocale.js +24 -0
- package/dist/development/react-server/NextIntlClientProvider.js +33 -0
- package/dist/development/react-server/getBaseTranslator.js +21 -0
- package/dist/development/react-server/useFormatter.js +19 -0
- package/dist/development/react-server/useHook.js +21 -0
- package/dist/development/react-server/useLocale.js +14 -0
- package/dist/development/react-server/useMessages.js +19 -0
- package/dist/development/react-server/useNow.js +23 -0
- package/dist/development/react-server/useTimeZone.js +19 -0
- package/dist/development/react-server/useTranslations.js +19 -0
- package/dist/development/server/RequestLocale.js +43 -0
- package/dist/development/server/createRequestConfig.js +17 -0
- package/dist/development/server/getConfig.js +43 -0
- package/dist/development/server/getFormatter.js +26 -0
- package/dist/development/server/getLocale.js +11 -0
- package/dist/development/server/getMessages.js +21 -0
- package/dist/development/server/getNow.js +18 -0
- package/dist/development/server/getRequestConfig.js +12 -0
- package/dist/development/server/getTimeZone.js +18 -0
- package/dist/development/server/getTranslations.js +31 -0
- package/dist/development/server/resolveLocaleArg.js +15 -0
- package/dist/development/server.js +23 -0
- package/dist/development/shared/BaseLinkWithLocale.js +58 -0
- package/dist/development/shared/NextIntlClientProvider.js +30 -0
- package/dist/development/shared/constants.js +17 -0
- package/dist/development/shared/redirectWithLocale.js +16 -0
- package/dist/development/shared/utils.js +87 -0
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +1 -0
- package/dist/esm/config.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.react-server.js +1 -0
- package/dist/esm/middleware/getAlternateLinksHeaderValue.js +1 -0
- package/dist/esm/middleware/middleware.js +1 -0
- package/dist/esm/middleware/resolveLocale.js +1 -0
- package/dist/esm/middleware/utils.js +1 -0
- package/dist/esm/middleware.js +1 -0
- package/dist/esm/navigation/BaseLink.js +1 -0
- package/dist/esm/navigation/baseRedirect.js +1 -0
- package/dist/esm/navigation/createLocalizedPathnamesNavigation.js +1 -0
- package/dist/esm/navigation/createSharedPathnamesNavigation.js +1 -0
- package/dist/esm/navigation/react-server/BaseLink.js +1 -0
- package/dist/esm/navigation/react-server/baseRedirect.js +1 -0
- package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -0
- package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +1 -0
- package/dist/esm/navigation/useBasePathname.js +2 -0
- package/dist/esm/navigation/useBaseRouter.js +1 -0
- package/dist/esm/navigation/utils.js +1 -0
- package/dist/esm/navigation.js +1 -0
- package/dist/esm/navigation.react-server.js +1 -0
- package/dist/esm/plugin.js +1 -0
- package/dist/esm/react-client/index.js +1 -0
- package/dist/esm/react-client/useLocale.js +1 -0
- package/dist/esm/react-server/NextIntlClientProvider.js +1 -0
- package/dist/esm/react-server/getBaseTranslator.js +1 -0
- package/dist/esm/react-server/useFormatter.js +1 -0
- package/dist/esm/react-server/useHook.js +1 -0
- package/dist/esm/react-server/useLocale.js +1 -0
- package/dist/esm/react-server/useMessages.js +1 -0
- package/dist/esm/react-server/useNow.js +1 -0
- package/dist/esm/react-server/useTimeZone.js +1 -0
- package/dist/esm/react-server/useTranslations.js +1 -0
- package/dist/esm/server/RequestLocale.js +1 -0
- package/dist/esm/server/createRequestConfig.js +1 -0
- package/dist/esm/server/getConfig.js +1 -0
- package/dist/esm/server/getFormatter.js +1 -0
- package/dist/esm/server/getLocale.js +1 -0
- package/dist/esm/server/getMessages.js +1 -0
- package/dist/esm/server/getNow.js +1 -0
- package/dist/esm/server/getRequestConfig.js +1 -0
- package/dist/esm/server/getTimeZone.js +1 -0
- package/dist/esm/server/getTranslations.js +1 -0
- package/dist/esm/server/resolveLocaleArg.js +1 -0
- package/dist/esm/server.js +1 -0
- package/dist/esm/shared/BaseLinkWithLocale.js +2 -0
- package/dist/esm/shared/NextIntlClientProvider.js +2 -0
- package/dist/esm/shared/constants.js +1 -0
- package/dist/esm/shared/redirectWithLocale.js +1 -0
- package/dist/esm/shared/utils.js +1 -0
- package/dist/index.js +3 -4
- package/dist/index.react-server.js +7 -0
- package/dist/middleware.js +7 -0
- package/dist/navigation.js +7 -0
- package/dist/navigation.react-server.js +7 -0
- package/dist/plugin.js +7 -0
- package/dist/production/_virtual/_rollupPluginBabelHelpers.js +1 -0
- package/dist/production/config.js +1 -0
- package/dist/production/index.js +1 -0
- package/dist/production/index.react-server.js +1 -0
- package/dist/production/middleware/getAlternateLinksHeaderValue.js +1 -0
- package/dist/production/middleware/middleware.js +1 -0
- package/dist/production/middleware/resolveLocale.js +1 -0
- package/dist/production/middleware/utils.js +1 -0
- package/dist/production/middleware.js +1 -0
- package/dist/production/navigation/BaseLink.js +1 -0
- package/dist/production/navigation/baseRedirect.js +1 -0
- package/dist/production/navigation/createLocalizedPathnamesNavigation.js +1 -0
- package/dist/production/navigation/createSharedPathnamesNavigation.js +1 -0
- package/dist/production/navigation/react-server/BaseLink.js +1 -0
- package/dist/production/navigation/react-server/baseRedirect.js +1 -0
- package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -0
- package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +1 -0
- package/dist/production/navigation/useBasePathname.js +2 -0
- package/dist/production/navigation/useBaseRouter.js +1 -0
- package/dist/production/navigation/utils.js +1 -0
- package/dist/production/navigation.js +1 -0
- package/dist/production/navigation.react-server.js +1 -0
- package/dist/production/plugin.js +1 -0
- package/dist/production/react-client/index.js +1 -0
- package/dist/production/react-client/useLocale.js +1 -0
- package/dist/production/react-server/NextIntlClientProvider.js +1 -0
- package/dist/production/react-server/getBaseTranslator.js +1 -0
- package/dist/production/react-server/useFormatter.js +1 -0
- package/dist/production/react-server/useHook.js +1 -0
- package/dist/production/react-server/useLocale.js +1 -0
- package/dist/production/react-server/useMessages.js +1 -0
- package/dist/production/react-server/useNow.js +1 -0
- package/dist/production/react-server/useTimeZone.js +1 -0
- package/dist/production/react-server/useTranslations.js +1 -0
- package/dist/production/server/RequestLocale.js +1 -0
- package/dist/production/server/createRequestConfig.js +1 -0
- package/dist/production/server/getConfig.js +1 -0
- package/dist/production/server/getFormatter.js +1 -0
- package/dist/production/server/getLocale.js +1 -0
- package/dist/production/server/getMessages.js +1 -0
- package/dist/production/server/getNow.js +1 -0
- package/dist/production/server/getRequestConfig.js +1 -0
- package/dist/production/server/getTimeZone.js +1 -0
- package/dist/production/server/getTranslations.js +1 -0
- package/dist/production/server/resolveLocaleArg.js +1 -0
- package/dist/production/server.js +1 -0
- package/dist/production/shared/BaseLinkWithLocale.js +2 -0
- package/dist/production/shared/NextIntlClientProvider.js +2 -0
- package/dist/production/shared/constants.js +1 -0
- package/dist/production/shared/redirectWithLocale.js +1 -0
- package/dist/production/shared/utils.js +1 -0
- package/dist/server.js +7 -0
- package/dist/types/src/config.d.ts +1 -0
- package/dist/types/src/index.react-server.d.ts +1 -0
- package/dist/{src → types/src}/middleware/NextIntlMiddlewareConfig.d.ts +14 -10
- package/dist/types/src/middleware/getAlternateLinksHeaderValue.d.ts +12 -0
- package/dist/types/src/middleware/middleware.d.ts +4 -0
- package/dist/types/src/middleware/resolveLocale.d.ts +7 -0
- package/dist/types/src/middleware/utils.d.ts +17 -0
- package/dist/types/src/middleware.d.ts +1 -0
- package/dist/types/src/navigation/BaseLink.d.ts +63 -0
- package/dist/types/src/navigation/StrictParams.d.ts +8 -0
- package/dist/types/src/navigation/baseRedirect.d.ts +3 -0
- package/dist/types/src/navigation/createLocalizedPathnamesNavigation.d.ts +78 -0
- package/dist/types/src/navigation/createSharedPathnamesNavigation.d.ts +13 -0
- package/dist/types/src/navigation/index.d.ts +3 -0
- package/dist/types/src/navigation/react-server/BaseLink.d.ts +8 -0
- package/dist/types/src/navigation/react-server/baseRedirect.d.ts +3 -0
- package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +60 -0
- package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +44 -0
- package/dist/types/src/navigation/react-server/index.d.ts +3 -0
- package/dist/{src/client/usePathname.d.ts → types/src/navigation/useBasePathname.d.ts} +1 -1
- package/dist/{client/useRouter.d.ts → types/src/navigation/useBaseRouter.d.ts} +32 -31
- package/dist/types/src/navigation/utils.d.ts +51 -0
- package/dist/types/src/navigation.d.ts +1 -0
- package/dist/types/src/navigation.react-server.d.ts +1 -0
- package/dist/types/src/plugin.d.ts +1 -0
- package/dist/{react-client → types/src/react-client}/index.d.ts +15 -12
- package/dist/types/src/react-client/useLocale.d.ts +1 -0
- package/dist/types/src/react-server/NextIntlClientProvider.d.ts +5 -0
- package/dist/types/src/react-server/getBaseTranslator.d.ts +42 -0
- package/dist/types/src/react-server/index.d.ts +15 -0
- package/dist/types/src/react-server/useFormatter.d.ts +2 -0
- package/dist/types/src/react-server/useHook.d.ts +1 -0
- package/dist/types/src/react-server/useLocale.d.ts +2 -0
- package/dist/types/src/react-server/useMessages.d.ts +2 -0
- package/dist/types/src/react-server/useNow.d.ts +2 -0
- package/dist/types/src/react-server/useTimeZone.d.ts +2 -0
- package/dist/types/src/react-server/useTranslations.d.ts +2 -0
- package/dist/types/src/server/RequestLocale.d.ts +2 -0
- package/dist/types/src/server/createRequestConfig.d.ts +4 -0
- package/dist/types/src/server/getConfig.d.ts +23 -0
- package/dist/types/src/server/getFormatter.d.ts +14 -0
- package/dist/types/src/server/getLocale.d.ts +1 -0
- package/dist/types/src/server/getMessages.d.ts +3 -0
- package/dist/types/src/server/getNow.d.ts +3 -0
- package/dist/types/src/server/getRequestConfig.d.ts +10 -0
- package/dist/types/src/server/getTimeZone.d.ts +3 -0
- package/dist/types/src/server/getTranslations.d.ts +83 -0
- package/dist/types/src/server/index.d.ts +11 -0
- package/dist/types/src/server/resolveLocaleArg.d.ts +3 -0
- package/dist/types/src/server.d.ts +1 -0
- package/dist/types/src/shared/NextIntlClientProvider.d.ts +8 -0
- package/dist/{shared → types/src/shared}/constants.d.ts +3 -2
- package/dist/types/src/shared/redirectWithLocale.d.ts +3 -0
- package/dist/types/src/shared/types.d.ts +6 -0
- package/dist/{src → types/src}/shared/utils.d.ts +6 -0
- package/dist/types/test/middleware/getAlternateLinksHeaderValue.test.d.ts +1 -0
- package/dist/types/test/middleware/middleware.test.d.ts +1 -0
- package/dist/types/test/middleware/utils.test.d.ts +1 -0
- package/dist/types/test/navigation/BaseLink.test.d.ts +1 -0
- package/dist/types/test/navigation/createLocalizedPathnamesNavigation.test.d.ts +1 -0
- package/dist/types/test/navigation/createSharedPathnamesNavigation.test.d.ts +1 -0
- package/dist/types/test/navigation/useBasePathname.test.d.ts +1 -0
- package/dist/types/test/navigation/useBaseRouter.test.d.ts +1 -0
- package/dist/types/test/navigation/utils.test.d.ts +1 -0
- package/dist/types/test/react-client/useFormatter.test.d.ts +1 -0
- package/dist/types/test/react-client/useLocale.test.d.ts +1 -0
- package/dist/types/test/react-client/useNow.test.d.ts +1 -0
- package/dist/types/test/react-client/useTimeZone.test.d.ts +1 -0
- package/dist/types/test/react-client/useTranslations.test.d.ts +1 -0
- package/dist/types/test/server/index.test.d.ts +1 -0
- package/dist/types/test/setup.d.ts +1 -0
- package/dist/types/test/shared/NextIntlClientProvider.test.d.ts +1 -0
- package/dist/types/test/shared/utils.test.d.ts +1 -0
- package/middleware.d.ts +1 -1
- package/navigation.d.ts +1 -0
- package/package.json +45 -34
- package/plugin.d.ts +6 -0
- package/server.d.ts +1 -1
- package/client.d.ts +0 -1
- package/dist/_virtual/next-intl.esm.js +0 -29
- package/dist/_virtual/next-intl.esm.js.map +0 -1
- package/dist/client/NextIntlClientProvider.d.ts +0 -4
- package/dist/client/index.d.ts +0 -6
- package/dist/client/useClientLocale.d.ts +0 -1
- package/dist/client/usePathname.d.ts +0 -14
- package/dist/index.d.ts +0 -8
- package/dist/link/Link.d.ts +0 -27
- package/dist/link/index.d.ts +0 -1
- package/dist/link/react-server/Link.d.ts +0 -1
- package/dist/link/react-server/index.d.ts +0 -1
- package/dist/middleware/NextIntlMiddlewareConfig.d.ts +0 -28
- package/dist/middleware/getAlternateLinksHeaderValue.d.ts +0 -6
- package/dist/middleware/index.d.ts +0 -4
- package/dist/middleware/middleware.d.ts +0 -3
- package/dist/middleware/resolveLocale.d.ts +0 -6
- package/dist/middleware/utils.d.ts +0 -5
- package/dist/next-intl.cjs.development.js +0 -82
- package/dist/next-intl.cjs.development.js.map +0 -1
- package/dist/next-intl.cjs.production.min.js +0 -2
- package/dist/next-intl.cjs.production.min.js.map +0 -1
- package/dist/next-intl.esm.js +0 -3
- package/dist/next-intl.esm.js.map +0 -1
- package/dist/react-server/index.d.ts +0 -17
- package/dist/server/index.d.ts +0 -6
- package/dist/shared/BaseLink.d.ts +0 -7
- package/dist/shared/NextIntlClientProvider.d.ts +0 -9
- package/dist/shared/next-intl.esm.js +0 -41
- package/dist/shared/next-intl.esm.js.map +0 -1
- package/dist/shared/utils.d.ts +0 -15
- package/dist/src/client/NextIntlClientProvider.d.ts +0 -4
- package/dist/src/client/NextIntlClientProvider.js +0 -16
- package/dist/src/client/NextIntlClientProvider.js.map +0 -1
- package/dist/src/client/index.d.ts +0 -6
- package/dist/src/client/index.js +0 -8
- package/dist/src/client/index.js.map +0 -1
- package/dist/src/client/useClientLocale.d.ts +0 -1
- package/dist/src/client/useClientLocale.js +0 -18
- package/dist/src/client/useClientLocale.js.map +0 -1
- package/dist/src/client/usePathname.js +0 -34
- package/dist/src/client/usePathname.js.map +0 -1
- package/dist/src/client/useRouter.d.ts +0 -31
- package/dist/src/client/useRouter.js +0 -61
- package/dist/src/client/useRouter.js.map +0 -1
- package/dist/src/index.js +0 -9
- package/dist/src/index.js.map +0 -1
- package/dist/src/link/Link.d.ts +0 -27
- package/dist/src/link/Link.js +0 -29
- package/dist/src/link/Link.js.map +0 -1
- package/dist/src/link/index.d.ts +0 -1
- package/dist/src/link/index.js +0 -2
- package/dist/src/link/index.js.map +0 -1
- package/dist/src/link/react-server/Link.d.ts +0 -1
- package/dist/src/link/react-server/Link.js +0 -6
- package/dist/src/link/react-server/Link.js.map +0 -1
- package/dist/src/link/react-server/index.d.ts +0 -1
- package/dist/src/link/react-server/index.js +0 -2
- package/dist/src/link/react-server/index.js.map +0 -1
- package/dist/src/middleware/NextIntlMiddlewareConfig.js +0 -2
- package/dist/src/middleware/NextIntlMiddlewareConfig.js.map +0 -1
- package/dist/src/middleware/getAlternateLinksHeaderValue.d.ts +0 -6
- package/dist/src/middleware/getAlternateLinksHeaderValue.js +0 -71
- package/dist/src/middleware/getAlternateLinksHeaderValue.js.map +0 -1
- package/dist/src/middleware/index.js +0 -5
- package/dist/src/middleware/index.js.map +0 -1
- package/dist/src/middleware/middleware.d.ts +0 -3
- package/dist/src/middleware/middleware.js +0 -149
- package/dist/src/middleware/middleware.js.map +0 -1
- package/dist/src/middleware/resolveLocale.d.ts +0 -6
- package/dist/src/middleware/resolveLocale.js +0 -88
- package/dist/src/middleware/resolveLocale.js.map +0 -1
- package/dist/src/middleware/utils.d.ts +0 -5
- package/dist/src/middleware/utils.js +0 -37
- package/dist/src/middleware/utils.js.map +0 -1
- package/dist/src/react-client/index.d.ts +0 -12
- package/dist/src/react-client/index.js +0 -14
- package/dist/src/react-client/index.js.map +0 -1
- package/dist/src/react-server/index.d.ts +0 -17
- package/dist/src/react-server/index.js +0 -25
- package/dist/src/react-server/index.js.map +0 -1
- package/dist/src/server/index.d.ts +0 -6
- package/dist/src/server/index.js +0 -30
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/shared/BaseLink.js +0 -38
- package/dist/src/shared/BaseLink.js.map +0 -1
- package/dist/src/shared/NextIntlClientProvider.d.ts +0 -9
- package/dist/src/shared/NextIntlClientProvider.js +0 -33
- package/dist/src/shared/NextIntlClientProvider.js.map +0 -1
- package/dist/src/shared/constants.d.ts +0 -2
- package/dist/src/shared/constants.js +0 -6
- package/dist/src/shared/constants.js.map +0 -1
- package/dist/src/shared/utils.js +0 -53
- package/dist/src/shared/utils.js.map +0 -1
- package/link.d.ts +0 -3
- package/src/client/NextIntlClientProvider.tsx +0 -18
- package/src/client/index.tsx +0 -9
- package/src/client/useClientLocale.tsx +0 -20
- package/src/client/usePathname.tsx +0 -40
- package/src/client/useRouter.tsx +0 -92
- package/src/index.tsx +0 -9
- package/src/link/Link.tsx +0 -34
- package/src/link/index.tsx +0 -1
- package/src/link/react-server/Link.tsx +0 -6
- package/src/link/react-server/index.tsx +0 -1
- package/src/middleware/NextIntlMiddlewareConfig.tsx +0 -42
- package/src/middleware/getAlternateLinksHeaderValue.tsx +0 -97
- package/src/middleware/index.tsx +0 -5
- package/src/middleware/middleware.tsx +0 -206
- package/src/middleware/resolveLocale.tsx +0 -151
- package/src/middleware/utils.tsx +0 -61
- package/src/react-client/index.tsx +0 -15
- package/src/react-server/index.tsx +0 -29
- package/src/server/index.tsx +0 -34
- package/src/shared/BaseLink.tsx +0 -57
- package/src/shared/NextIntlClientProvider.tsx +0 -54
- package/src/shared/constants.tsx +0 -6
- package/src/shared/utils.tsx +0 -91
- /package/dist/{src → types/src}/index.d.ts +0 -0
- /package/dist/{src → types/src}/middleware/index.d.ts +0 -0
- /package/dist/{src/shared/BaseLink.d.ts → types/src/shared/BaseLinkWithLocale.d.ts} +0 -0
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ComponentProps } from 'react';
|
|
2
|
-
import { IntlProvider } from 'use-intl';
|
|
3
|
-
type Props = Omit<ComponentProps<typeof IntlProvider>, 'locale' | 'now'> & {
|
|
4
|
-
locale?: string;
|
|
5
|
-
/** If a string is supplied, make sure this conforms to the ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ */
|
|
6
|
-
now?: Date | string;
|
|
7
|
-
};
|
|
8
|
-
export default function NextIntlClientProvider({ children, locale, now, ...rest }: Props): JSX.Element;
|
|
9
|
-
export {};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useRouter } from 'next/router';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { IntlProvider } from 'use-intl';
|
|
5
|
-
export default function NextIntlClientProvider({ children, locale, now, ...rest }) {
|
|
6
|
-
let router;
|
|
7
|
-
try {
|
|
8
|
-
// Reading from context is practically ok to do conditionally
|
|
9
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
10
|
-
router = useRouter();
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
// Calling `useRouter` is not supported in the app folder
|
|
14
|
-
}
|
|
15
|
-
// The router can be undefined if used in a context outside
|
|
16
|
-
// of Next.js (e.g. unit tests, Storybook, ...)
|
|
17
|
-
if (!locale && router) {
|
|
18
|
-
locale = router.locale;
|
|
19
|
-
}
|
|
20
|
-
// Currently RSC serialize dates to strings, therefore make sure we have
|
|
21
|
-
// a date object. We might be able to remove this once more types have
|
|
22
|
-
// first-class serialization support (https://github.com/facebook/react/issues/25687)
|
|
23
|
-
if (typeof now === 'string') {
|
|
24
|
-
now = new Date(now);
|
|
25
|
-
}
|
|
26
|
-
if (!locale) {
|
|
27
|
-
throw new Error(process.env.NODE_ENV !== 'production'
|
|
28
|
-
? "Couldn't determine locale. Please pass an explicit `locale` prop the provider, or if you're using the `pages` folder, use internationalized routing (https://nextjs.org/docs/advanced-features/i18n-routing)."
|
|
29
|
-
: undefined);
|
|
30
|
-
}
|
|
31
|
-
return (React.createElement(IntlProvider, { locale: locale, now: now, ...rest }, children));
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=NextIntlClientProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NextIntlClientProvider.js","sourceRoot":"","sources":["../../../src/shared/NextIntlClientProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,KAAuB,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAQtC,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,EAC7C,QAAQ,EACR,MAAM,EACN,GAAG,EACH,GAAG,IAAI,EACD;IACN,IAAI,MAAM,CAAC;IACX,IAAI;QACF,6DAA6D;QAC7D,sDAAsD;QACtD,MAAM,GAAG,SAAS,EAAE,CAAC;KACtB;IAAC,OAAO,KAAK,EAAE;QACd,yDAAyD;KAC1D;IAED,2DAA2D;IAC3D,+CAA+C;IAC/C,IAAI,CAAC,MAAM,IAAI,MAAM,EAAE;QACrB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;KACxB;IAED,wEAAwE;IACxE,sEAAsE;IACtE,qFAAqF;IACrF,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;KACrB;IAED,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YACnC,CAAC,CAAC,+MAA+M;YACjN,CAAC,CAAC,SAAS,CACd,CAAC;KACH;IAED,OAAO,CACL,oBAAC,YAAY,IAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,KAAM,IAAI,IAC7C,QAAQ,CACI,CAChB,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// Reuse the legacy cookie name
|
|
2
|
-
// https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie
|
|
3
|
-
export const COOKIE_LOCALE_NAME = 'NEXT_LOCALE';
|
|
4
|
-
// In a URL like "/en-US/about", the locale segment is "en-US"
|
|
5
|
-
export const LOCALE_SEGMENT_NAME = 'locale';
|
|
6
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/shared/constants.tsx"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,2FAA2F;AAC3F,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAEhD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,mBAAmB,GAAG,QAAQ,CAAC"}
|
package/dist/src/shared/utils.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
export function isRelativeHref(href) {
|
|
2
|
-
const pathname = typeof href === 'object' ? href.pathname : href;
|
|
3
|
-
return pathname != null && !pathname.startsWith('/');
|
|
4
|
-
}
|
|
5
|
-
export function isLocalHref(href) {
|
|
6
|
-
if (typeof href === 'object') {
|
|
7
|
-
return href.host == null && href.hostname == null;
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
const hasProtocol = /^[a-z]+:/i.test(href);
|
|
11
|
-
return !hasProtocol;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export function localizeHref(href, locale, defaultLocale = locale, pathname) {
|
|
15
|
-
if (!isLocalHref(href) || isRelativeHref(href)) {
|
|
16
|
-
return href;
|
|
17
|
-
}
|
|
18
|
-
const isSwitchingLocale = locale !== defaultLocale;
|
|
19
|
-
const isPathnamePrefixed = locale == null || hasPathnamePrefixed(locale, pathname);
|
|
20
|
-
const shouldPrefix = isPathnamePrefixed || isSwitchingLocale;
|
|
21
|
-
if (shouldPrefix && locale != null) {
|
|
22
|
-
return prefixHref(href, locale);
|
|
23
|
-
}
|
|
24
|
-
return href;
|
|
25
|
-
}
|
|
26
|
-
export function prefixHref(href, locale) {
|
|
27
|
-
let prefixedHref;
|
|
28
|
-
if (typeof href === 'string') {
|
|
29
|
-
prefixedHref = localizePathname(locale, href);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
prefixedHref = { ...href };
|
|
33
|
-
if (href.pathname) {
|
|
34
|
-
prefixedHref.pathname = localizePathname(locale, href.pathname);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return prefixedHref;
|
|
38
|
-
}
|
|
39
|
-
export function unlocalizePathname(pathname, locale) {
|
|
40
|
-
return pathname.replace(new RegExp(`^/${locale}`), '') || '/';
|
|
41
|
-
}
|
|
42
|
-
export function localizePathname(locale, pathname) {
|
|
43
|
-
let localizedHref = '/' + locale;
|
|
44
|
-
if (pathname !== '/') {
|
|
45
|
-
localizedHref += pathname;
|
|
46
|
-
}
|
|
47
|
-
return localizedHref;
|
|
48
|
-
}
|
|
49
|
-
export function hasPathnamePrefixed(locale, pathname) {
|
|
50
|
-
const prefix = `/${locale}`;
|
|
51
|
-
return pathname === prefix || pathname.startsWith(`${prefix}/`);
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/shared/utils.tsx"],"names":[],"mappings":"AAMA,MAAM,UAAU,cAAc,CAAC,IAAU;IACvC,MAAM,QAAQ,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,OAAO,QAAQ,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAU;IACpC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC;KACnD;SAAM;QACL,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3C,OAAO,CAAC,WAAW,CAAC;KACrB;AACH,CAAC;AAcD,MAAM,UAAU,YAAY,CAC1B,IAAwB,EACxB,MAAc,EACd,gBAAwB,MAAM,EAC9B,QAAgB;IAEhB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE;QAC9C,OAAO,IAAI,CAAC;KACb;IAED,MAAM,iBAAiB,GAAG,MAAM,KAAK,aAAa,CAAC;IACnD,MAAM,kBAAkB,GACtB,MAAM,IAAI,IAAI,IAAI,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC1D,MAAM,YAAY,GAAG,kBAAkB,IAAI,iBAAiB,CAAC;IAE7D,IAAI,YAAY,IAAI,MAAM,IAAI,IAAI,EAAE;QAClC,OAAO,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;KACjC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAOD,MAAM,UAAU,UAAU,CAAC,IAAwB,EAAE,MAAc;IACjE,IAAI,YAAY,CAAC;IACjB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,YAAY,GAAG,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;KAC/C;SAAM;QACL,YAAY,GAAG,EAAC,GAAG,IAAI,EAAC,CAAC;QACzB,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,YAAY,CAAC,QAAQ,GAAG,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;SACjE;KACF;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,QAAgB,EAAE,MAAc;IACjE,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,KAAK,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAc,EAAE,QAAgB;IAC/D,IAAI,aAAa,GAAG,GAAG,GAAG,MAAM,CAAC;IAEjC,IAAI,QAAQ,KAAK,GAAG,EAAE;QACpB,aAAa,IAAI,QAAQ,CAAC;KAC3B;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAc,EAAE,QAAgB;IAClE,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;IAC5B,OAAO,QAAQ,KAAK,MAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;AAClE,CAAC"}
|
package/link.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React, {ComponentProps} from 'react';
|
|
2
|
-
import NextIntlClientProvider_ from '../shared/NextIntlClientProvider';
|
|
3
|
-
|
|
4
|
-
let hasWarned = false;
|
|
5
|
-
/** @deprecated Should be imported from `next-intl`, not `next-intl/client`. */
|
|
6
|
-
export default function NextIntlClientProvider(
|
|
7
|
-
props: ComponentProps<typeof NextIntlClientProvider_>
|
|
8
|
-
) {
|
|
9
|
-
if (!hasWarned) {
|
|
10
|
-
hasWarned = true;
|
|
11
|
-
console.warn(`
|
|
12
|
-
Importing \`NextIntlClientProvider\` from \`next-intl/client\` is deprecated. Please update the import:
|
|
13
|
-
|
|
14
|
-
import {NextIntlClientProvider} from 'next-intl';
|
|
15
|
-
`);
|
|
16
|
-
}
|
|
17
|
-
return <NextIntlClientProvider_ {...props} />;
|
|
18
|
-
}
|
package/src/client/index.tsx
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client-only APIs available via `next-intl/client`.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export {default as useRouter} from './useRouter';
|
|
6
|
-
export {default as usePathname} from './usePathname';
|
|
7
|
-
|
|
8
|
-
// Legacy export (deprecation is handled by component)
|
|
9
|
-
export {default as NextIntlClientProvider} from './NextIntlClientProvider';
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {useParams} from 'next/navigation';
|
|
2
|
-
import {useLocale} from 'use-intl';
|
|
3
|
-
import {LOCALE_SEGMENT_NAME} from '../shared/constants';
|
|
4
|
-
|
|
5
|
-
export default function useClientLocale(): string {
|
|
6
|
-
let locale;
|
|
7
|
-
|
|
8
|
-
// The types aren't entirely correct here. Outside of Next.js
|
|
9
|
-
// `useParams` can be called, but the return type is `null`.
|
|
10
|
-
const params = useParams() as ReturnType<typeof useParams> | null;
|
|
11
|
-
|
|
12
|
-
if (typeof params?.[LOCALE_SEGMENT_NAME] === 'string') {
|
|
13
|
-
locale = params[LOCALE_SEGMENT_NAME];
|
|
14
|
-
} else {
|
|
15
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine
|
|
16
|
-
locale = useLocale();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return locale;
|
|
20
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {usePathname as useNextPathname} from 'next/navigation';
|
|
4
|
-
import {useMemo} from 'react';
|
|
5
|
-
import {hasPathnamePrefixed, unlocalizePathname} from '../shared/utils';
|
|
6
|
-
import useClientLocale from './useClientLocale';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Returns the pathname without a potential locale prefix.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```tsx
|
|
13
|
-
* 'use client';
|
|
14
|
-
*
|
|
15
|
-
* import {usePathname} from 'next-intl/client';
|
|
16
|
-
*
|
|
17
|
-
* // When the user is on `/en`, this will be `/`
|
|
18
|
-
* const pathname = usePathname();
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export default function usePathname(): string {
|
|
22
|
-
// The types aren't entirely correct here. Outside of Next.js
|
|
23
|
-
// `useParams` can be called, but the return type is `null`.
|
|
24
|
-
const pathname = useNextPathname() as ReturnType<
|
|
25
|
-
typeof useNextPathname
|
|
26
|
-
> | null;
|
|
27
|
-
|
|
28
|
-
const locale = useClientLocale();
|
|
29
|
-
|
|
30
|
-
return useMemo(() => {
|
|
31
|
-
if (!pathname) return pathname as ReturnType<typeof useNextPathname>;
|
|
32
|
-
|
|
33
|
-
const isPathnamePrefixed = hasPathnamePrefixed(locale, pathname);
|
|
34
|
-
const unlocalizedPathname = isPathnamePrefixed
|
|
35
|
-
? unlocalizePathname(pathname, locale)
|
|
36
|
-
: pathname;
|
|
37
|
-
|
|
38
|
-
return unlocalizedPathname;
|
|
39
|
-
}, [locale, pathname]);
|
|
40
|
-
}
|
package/src/client/useRouter.tsx
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {useRouter as useNextRouter} from 'next/navigation';
|
|
2
|
-
import {useMemo} from 'react';
|
|
3
|
-
import {localizeHref} from '../shared/utils';
|
|
4
|
-
import useClientLocale from './useClientLocale';
|
|
5
|
-
|
|
6
|
-
type IntlNavigateOptions = {
|
|
7
|
-
locale?: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Returns a wrapped instance of `useRouter` from `next/navigation` that
|
|
12
|
-
* will automatically localize the `href` parameters it receives.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```tsx
|
|
16
|
-
* 'use client';
|
|
17
|
-
*
|
|
18
|
-
* import {useRouter} from 'next-intl/client';
|
|
19
|
-
*
|
|
20
|
-
* const router = useRouter();
|
|
21
|
-
*
|
|
22
|
-
* // When the user is on `/en`, the router will navigate to `/en/about`
|
|
23
|
-
* router.push('/about');
|
|
24
|
-
*
|
|
25
|
-
* // Optionally, you can switch the locale by passing the second argument
|
|
26
|
-
* router.push('/about', {locale: 'de'});
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export default function useRouter() {
|
|
30
|
-
const router = useNextRouter();
|
|
31
|
-
const locale = useClientLocale();
|
|
32
|
-
|
|
33
|
-
return useMemo(() => {
|
|
34
|
-
function localize(href: string, nextLocale?: string) {
|
|
35
|
-
return localizeHref(
|
|
36
|
-
href,
|
|
37
|
-
nextLocale || locale,
|
|
38
|
-
locale,
|
|
39
|
-
window.location.pathname
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
...router,
|
|
45
|
-
push(
|
|
46
|
-
href: string,
|
|
47
|
-
options?: Parameters<typeof router.push>[1] & IntlNavigateOptions
|
|
48
|
-
) {
|
|
49
|
-
const {locale: nextLocale, ...rest} = options || {};
|
|
50
|
-
const args: [
|
|
51
|
-
href: string,
|
|
52
|
-
options?: Parameters<typeof router.push>[1]
|
|
53
|
-
] = [localize(href, nextLocale)];
|
|
54
|
-
if (Object.keys(rest).length > 0) {
|
|
55
|
-
args.push(rest);
|
|
56
|
-
}
|
|
57
|
-
return router.push(...args);
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
replace(
|
|
61
|
-
href: string,
|
|
62
|
-
options?: Parameters<typeof router.replace>[1] & IntlNavigateOptions
|
|
63
|
-
) {
|
|
64
|
-
const {locale: nextLocale, ...rest} = options || {};
|
|
65
|
-
const args: [
|
|
66
|
-
href: string,
|
|
67
|
-
options?: Parameters<typeof router.replace>[1]
|
|
68
|
-
] = [localize(href, nextLocale)];
|
|
69
|
-
if (Object.keys(rest).length > 0) {
|
|
70
|
-
args.push(rest);
|
|
71
|
-
}
|
|
72
|
-
return router.replace(...args);
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
prefetch(
|
|
76
|
-
href: string,
|
|
77
|
-
options?: Parameters<typeof router.prefetch>[1] & IntlNavigateOptions
|
|
78
|
-
) {
|
|
79
|
-
const {locale: nextLocale, ...rest} = options || {};
|
|
80
|
-
const args: [
|
|
81
|
-
href: string,
|
|
82
|
-
options?: Parameters<typeof router.prefetch>[1]
|
|
83
|
-
] = [localize(href, nextLocale)];
|
|
84
|
-
if (Object.keys(rest).length > 0) {
|
|
85
|
-
// @ts-expect-error TypeScript thinks `rest` can be an empty object
|
|
86
|
-
args.push(rest);
|
|
87
|
-
}
|
|
88
|
-
return router.prefetch(...args);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
}, [locale, router]);
|
|
92
|
-
}
|
package/src/index.tsx
DELETED
package/src/link/Link.tsx
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import React, {ComponentProps, forwardRef} from 'react';
|
|
2
|
-
import useClientLocale from '../client/useClientLocale';
|
|
3
|
-
import BaseLink from '../shared/BaseLink';
|
|
4
|
-
|
|
5
|
-
type Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {
|
|
6
|
-
locale?: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
function Link({locale, ...rest}: Props, ref: Props['ref']) {
|
|
10
|
-
const defaultLocale = useClientLocale();
|
|
11
|
-
return <BaseLink ref={ref} locale={locale || defaultLocale} {...rest} />;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Wraps `next/link` and prefixes the `href` with the current locale if
|
|
16
|
-
* necessary.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```tsx
|
|
20
|
-
* import {Link} from 'next-intl';
|
|
21
|
-
*
|
|
22
|
-
* // When the user is on `/en`, the link will point to `/en/about`
|
|
23
|
-
* <Link href="/about">About</Link>
|
|
24
|
-
*
|
|
25
|
-
* // You can override the `locale` to switch to another language
|
|
26
|
-
* <Link href="/" locale="de">Switch to German</Link>
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* Note that when a `locale` prop is passed to switch the locale, the `prefetch`
|
|
30
|
-
* prop is not supported. This is because Next.js would prefetch the page and
|
|
31
|
-
* the `set-cookie` response header would cause the locale cookie on the current
|
|
32
|
-
* page to be overwritten before the user even decides to change the locale.
|
|
33
|
-
*/
|
|
34
|
-
export default forwardRef(Link);
|
package/src/link/index.tsx
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {default} from './Link';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {default} from './Link';
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
type LocalePrefix = 'as-needed' | 'always' | 'never';
|
|
2
|
-
|
|
3
|
-
type RoutingBaseConfig = {
|
|
4
|
-
/** A list of all locales that are supported. */
|
|
5
|
-
locales: Array<string>;
|
|
6
|
-
|
|
7
|
-
/* Used by default if none of the defined locales match. */
|
|
8
|
-
defaultLocale: string;
|
|
9
|
-
|
|
10
|
-
/** The default locale can be used without a prefix (e.g. `/about`). If you prefer to have a prefix for the default locale as well (e.g. `/en/about`), you can switch this option to `always`.
|
|
11
|
-
*/
|
|
12
|
-
localePrefix?: LocalePrefix;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type DomainConfig = Omit<
|
|
16
|
-
RoutingBaseConfig,
|
|
17
|
-
'locales' | 'localePrefix'
|
|
18
|
-
> & {
|
|
19
|
-
/** The domain name (e.g. "example.com", "www.example.com" or "fr.example.com"). Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
|
|
20
|
-
domain: string;
|
|
21
|
-
// Optional here
|
|
22
|
-
locales?: RoutingBaseConfig['locales'];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type MiddlewareConfig = RoutingBaseConfig & {
|
|
26
|
-
/** Can be used to change the locale handling per domain. */
|
|
27
|
-
domains?: Array<DomainConfig>;
|
|
28
|
-
|
|
29
|
-
/** By setting this to `false`, the `accept-language` header will no longer be used for locale detection. */
|
|
30
|
-
localeDetection?: boolean;
|
|
31
|
-
|
|
32
|
-
/** 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 */
|
|
33
|
-
alternateLinks?: boolean;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export type MiddlewareConfigWithDefaults = MiddlewareConfig & {
|
|
37
|
-
alternateLinks: boolean;
|
|
38
|
-
localePrefix: LocalePrefix;
|
|
39
|
-
localeDetection: boolean;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default MiddlewareConfig;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import {NextRequest} from 'next/server';
|
|
2
|
-
import MiddlewareConfig, {
|
|
3
|
-
MiddlewareConfigWithDefaults
|
|
4
|
-
} from './NextIntlMiddlewareConfig';
|
|
5
|
-
import {getHost, isLocaleSupportedOnDomain} from './utils';
|
|
6
|
-
|
|
7
|
-
function getUnprefixedUrl(config: MiddlewareConfig, request: NextRequest) {
|
|
8
|
-
const url = new URL(request.url);
|
|
9
|
-
const host = getHost(request.headers);
|
|
10
|
-
if (host) {
|
|
11
|
-
url.port = '';
|
|
12
|
-
url.host = host;
|
|
13
|
-
}
|
|
14
|
-
url.protocol = request.headers.get('x-forwarded-proto') ?? url.protocol;
|
|
15
|
-
|
|
16
|
-
if (!url.pathname.endsWith('/')) {
|
|
17
|
-
url.pathname += '/';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
url.pathname = url.pathname.replace(
|
|
21
|
-
new RegExp(`^/(${config.locales.join('|')})/`),
|
|
22
|
-
'/'
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
// Remove trailing slash
|
|
26
|
-
if (url.pathname !== '/') {
|
|
27
|
-
url.pathname = url.pathname.slice(0, -1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return url.toString();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function getAlternateEntry(url: string, locale: string) {
|
|
34
|
-
return `<${url}>; rel="alternate"; hreflang="${locale}"`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* See https://developers.google.com/search/docs/specialty/international/localized-versions
|
|
39
|
-
*/
|
|
40
|
-
export default function getAlternateLinksHeaderValue(
|
|
41
|
-
config: MiddlewareConfigWithDefaults,
|
|
42
|
-
request: NextRequest
|
|
43
|
-
) {
|
|
44
|
-
const unprefixedUrl = getUnprefixedUrl(config, request);
|
|
45
|
-
|
|
46
|
-
const links = config.locales.flatMap((locale) => {
|
|
47
|
-
function localizePathname(url: URL) {
|
|
48
|
-
if (url.pathname === '/') {
|
|
49
|
-
url.pathname = `/${locale}`;
|
|
50
|
-
} else {
|
|
51
|
-
url.pathname = `/${locale}${url.pathname}`;
|
|
52
|
-
}
|
|
53
|
-
return url;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let url;
|
|
57
|
-
|
|
58
|
-
if (config.domains) {
|
|
59
|
-
const domainConfigs =
|
|
60
|
-
config.domains.filter((cur) =>
|
|
61
|
-
isLocaleSupportedOnDomain(locale, cur)
|
|
62
|
-
) || [];
|
|
63
|
-
|
|
64
|
-
return domainConfigs.map((domainConfig) => {
|
|
65
|
-
url = new URL(unprefixedUrl);
|
|
66
|
-
url.port = '';
|
|
67
|
-
url.host = domainConfig.domain;
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
locale !== domainConfig.defaultLocale ||
|
|
71
|
-
config.localePrefix === 'always'
|
|
72
|
-
) {
|
|
73
|
-
localizePathname(url);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return getAlternateEntry(url.toString(), locale);
|
|
77
|
-
});
|
|
78
|
-
} else {
|
|
79
|
-
url = new URL(unprefixedUrl);
|
|
80
|
-
if (locale !== config.defaultLocale || config.localePrefix === 'always') {
|
|
81
|
-
localizePathname(url);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return getAlternateEntry(url.toString(), locale);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// Add x-default entry
|
|
89
|
-
if (!config.domains) {
|
|
90
|
-
const url = new URL(unprefixedUrl);
|
|
91
|
-
links.push(getAlternateEntry(url.toString(), 'x-default'));
|
|
92
|
-
} else {
|
|
93
|
-
// For `type: domain` there is no reasonable x-default
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return links.join(', ');
|
|
97
|
-
}
|