@intlayer/next-intl 9.0.0-canary.2 → 9.0.0-canary.21
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/dist/cjs/client/NextIntlClientProvider.cjs +8 -4
- package/dist/cjs/client/NextIntlClientProvider.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +55 -13
- package/dist/cjs/client/useLocale.cjs +0 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +19 -30
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getDictionaryDynamic.cjs +8 -24
- package/dist/cjs/getDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/index.cjs +91 -15
- package/dist/cjs/middleware.cjs +0 -1
- package/dist/cjs/middleware.cjs.map +1 -1
- package/dist/cjs/navigation/Link.cjs.map +1 -1
- package/dist/cjs/navigation/createNavigation.cjs +0 -1
- package/dist/cjs/navigation/createNavigation.cjs.map +1 -1
- package/dist/cjs/navigation/hooks.cjs +0 -1
- package/dist/cjs/navigation/hooks.cjs.map +1 -1
- package/dist/cjs/navigation/localizeHref.cjs +0 -1
- package/dist/cjs/navigation/localizeHref.cjs.map +1 -1
- package/dist/cjs/plugin/index.cjs +9 -15
- package/dist/cjs/plugin/index.cjs.map +1 -1
- package/dist/cjs/routing.cjs +0 -1
- package/dist/cjs/routing.cjs.map +1 -1
- package/dist/cjs/server/getLocale.cjs +15 -2
- package/dist/cjs/server/getLocale.cjs.map +1 -1
- package/dist/cjs/server/getMessages.cjs +0 -1
- package/dist/cjs/server/getMessages.cjs.map +1 -1
- package/dist/cjs/server/getRequestConfig.cjs +27 -0
- package/dist/cjs/server/getRequestConfig.cjs.map +1 -0
- package/dist/cjs/server/getTranslations.cjs +8 -4
- package/dist/cjs/server/getTranslations.cjs.map +1 -1
- package/dist/cjs/server/helpers.cjs +4 -3
- package/dist/cjs/server/helpers.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +5 -1
- package/dist/cjs/server/requestLocaleCache.cjs +35 -0
- package/dist/cjs/server/requestLocaleCache.cjs.map +1 -0
- package/dist/cjs/server/setLocale.cjs +0 -1
- package/dist/cjs/server/setLocale.cjs.map +1 -1
- package/dist/cjs/server/setRequestLocale.cjs +33 -0
- package/dist/cjs/server/setRequestLocale.cjs.map +1 -0
- package/dist/esm/client/NextIntlClientProvider.mjs +9 -4
- package/dist/esm/client/NextIntlClientProvider.mjs.map +1 -1
- package/dist/esm/client/index.mjs +1 -4
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +19 -29
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getDictionaryDynamic.mjs +8 -23
- package/dist/esm/getDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/index.mjs +3 -6
- package/dist/esm/middleware.mjs.map +1 -1
- package/dist/esm/navigation/Link.mjs.map +1 -1
- package/dist/esm/navigation/createNavigation.mjs.map +1 -1
- package/dist/esm/navigation/hooks.mjs.map +1 -1
- package/dist/esm/navigation/localizeHref.mjs.map +1 -1
- package/dist/esm/plugin/index.mjs +8 -14
- package/dist/esm/plugin/index.mjs.map +1 -1
- package/dist/esm/routing.mjs.map +1 -1
- package/dist/esm/server/getLocale.mjs +15 -1
- package/dist/esm/server/getLocale.mjs.map +1 -1
- package/dist/esm/server/getMessages.mjs.map +1 -1
- package/dist/esm/server/getRequestConfig.mjs +25 -0
- package/dist/esm/server/getRequestConfig.mjs.map +1 -0
- package/dist/esm/server/getTranslations.mjs +8 -4
- package/dist/esm/server/getTranslations.mjs.map +1 -1
- package/dist/esm/server/helpers.mjs +4 -3
- package/dist/esm/server/helpers.mjs.map +1 -1
- package/dist/esm/server/index.mjs +3 -1
- package/dist/esm/server/requestLocaleCache.mjs +33 -0
- package/dist/esm/server/requestLocaleCache.mjs.map +1 -0
- package/dist/esm/server/setLocale.mjs.map +1 -1
- package/dist/esm/server/setRequestLocale.mjs +32 -0
- package/dist/esm/server/setRequestLocale.mjs.map +1 -0
- package/dist/types/client/NextIntlClientProvider.d.ts +0 -1
- package/dist/types/client/NextIntlClientProvider.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -4
- package/dist/types/client/useLocale.d.ts +0 -1
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +25 -13
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getDictionaryDynamic.d.ts +15 -7
- package/dist/types/getDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -6
- package/dist/types/middleware.d.ts +0 -1
- package/dist/types/middleware.d.ts.map +1 -1
- package/dist/types/navigation/Link.d.ts +3 -6
- package/dist/types/navigation/Link.d.ts.map +1 -1
- package/dist/types/navigation/createNavigation.d.ts +0 -1
- package/dist/types/navigation/createNavigation.d.ts.map +1 -1
- package/dist/types/navigation/hooks.d.ts +4 -6
- package/dist/types/navigation/hooks.d.ts.map +1 -1
- package/dist/types/navigation/localizeHref.d.ts.map +1 -1
- package/dist/types/plugin/index.d.ts +0 -1
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/routing.d.ts +0 -1
- package/dist/types/routing.d.ts.map +1 -1
- package/dist/types/server/getLocale.d.ts +9 -1
- package/dist/types/server/getLocale.d.ts.map +1 -1
- package/dist/types/server/getMessages.d.ts +0 -1
- package/dist/types/server/getMessages.d.ts.map +1 -1
- package/dist/types/server/getRequestConfig.d.ts +18 -0
- package/dist/types/server/getRequestConfig.d.ts.map +1 -0
- package/dist/types/server/getTranslations.d.ts +13 -33
- package/dist/types/server/getTranslations.d.ts.map +1 -1
- package/dist/types/server/helpers.d.ts +2 -2
- package/dist/types/server/helpers.d.ts.map +1 -1
- package/dist/types/server/index.d.ts +3 -1
- package/dist/types/server/requestLocaleCache.d.ts +16 -0
- package/dist/types/server/requestLocaleCache.d.ts.map +1 -0
- package/dist/types/server/setLocale.d.ts.map +1 -1
- package/dist/types/server/setRequestLocale.d.ts +28 -0
- package/dist/types/server/setRequestLocale.d.ts.map +1 -0
- package/package.json +14 -13
- package/dist/cjs/client/helpers.cjs +0 -66
- package/dist/cjs/client/helpers.cjs.map +0 -1
- package/dist/cjs/client/useTranslations.cjs +0 -39
- package/dist/cjs/client/useTranslations.cjs.map +0 -1
- package/dist/cjs/createFormatter.cjs +0 -59
- package/dist/cjs/createFormatter.cjs.map +0 -1
- package/dist/cjs/createTranslator.cjs +0 -111
- package/dist/cjs/createTranslator.cjs.map +0 -1
- package/dist/cjs/getTranslationsDictionary.cjs +0 -31
- package/dist/cjs/getTranslationsDictionary.cjs.map +0 -1
- package/dist/cjs/getTranslationsDictionaryDynamic.cjs +0 -27
- package/dist/cjs/getTranslationsDictionaryDynamic.cjs.map +0 -1
- package/dist/cjs/hasLocale.cjs +0 -25
- package/dist/cjs/hasLocale.cjs.map +0 -1
- package/dist/cjs/package.cjs +0 -122
- package/dist/cjs/package.cjs.map +0 -1
- package/dist/cjs/useDictionary.cjs +0 -45
- package/dist/cjs/useDictionary.cjs.map +0 -1
- package/dist/cjs/useDictionaryDynamic.cjs +0 -37
- package/dist/cjs/useDictionaryDynamic.cjs.map +0 -1
- package/dist/cjs/useTranslationsDictionary.cjs +0 -37
- package/dist/cjs/useTranslationsDictionary.cjs.map +0 -1
- package/dist/cjs/useTranslationsDictionaryDynamic.cjs +0 -29
- package/dist/cjs/useTranslationsDictionaryDynamic.cjs.map +0 -1
- package/dist/esm/_virtual/_rolldown/runtime.mjs +0 -8
- package/dist/esm/client/helpers.mjs +0 -59
- package/dist/esm/client/helpers.mjs.map +0 -1
- package/dist/esm/client/useTranslations.mjs +0 -37
- package/dist/esm/client/useTranslations.mjs.map +0 -1
- package/dist/esm/createFormatter.mjs +0 -57
- package/dist/esm/createFormatter.mjs.map +0 -1
- package/dist/esm/createTranslator.mjs +0 -108
- package/dist/esm/createTranslator.mjs.map +0 -1
- package/dist/esm/getTranslationsDictionary.mjs +0 -29
- package/dist/esm/getTranslationsDictionary.mjs.map +0 -1
- package/dist/esm/getTranslationsDictionaryDynamic.mjs +0 -25
- package/dist/esm/getTranslationsDictionaryDynamic.mjs.map +0 -1
- package/dist/esm/hasLocale.mjs +0 -23
- package/dist/esm/hasLocale.mjs.map +0 -1
- package/dist/esm/package.mjs +0 -119
- package/dist/esm/package.mjs.map +0 -1
- package/dist/esm/useDictionary.mjs +0 -43
- package/dist/esm/useDictionary.mjs.map +0 -1
- package/dist/esm/useDictionaryDynamic.mjs +0 -35
- package/dist/esm/useDictionaryDynamic.mjs.map +0 -1
- package/dist/esm/useTranslationsDictionary.mjs +0 -35
- package/dist/esm/useTranslationsDictionary.mjs.map +0 -1
- package/dist/esm/useTranslationsDictionaryDynamic.mjs +0 -27
- package/dist/esm/useTranslationsDictionaryDynamic.mjs.map +0 -1
- package/dist/types/client/helpers.d.ts +0 -45
- package/dist/types/client/helpers.d.ts.map +0 -1
- package/dist/types/client/useTranslations.d.ts +0 -74
- package/dist/types/client/useTranslations.d.ts.map +0 -1
- package/dist/types/createFormatter.d.ts +0 -15
- package/dist/types/createFormatter.d.ts.map +0 -1
- package/dist/types/createTranslator.d.ts +0 -40
- package/dist/types/createTranslator.d.ts.map +0 -1
- package/dist/types/getTranslationsDictionary.d.ts +0 -15
- package/dist/types/getTranslationsDictionary.d.ts.map +0 -1
- package/dist/types/getTranslationsDictionaryDynamic.d.ts +0 -12
- package/dist/types/getTranslationsDictionaryDynamic.d.ts.map +0 -1
- package/dist/types/hasLocale.d.ts +0 -20
- package/dist/types/hasLocale.d.ts.map +0 -1
- package/dist/types/useDictionary.d.ts +0 -22
- package/dist/types/useDictionary.d.ts.map +0 -1
- package/dist/types/useDictionaryDynamic.d.ts +0 -15
- package/dist/types/useDictionaryDynamic.d.ts.map +0 -1
- package/dist/types/useTranslationsDictionary.d.ts +0 -19
- package/dist/types/useTranslationsDictionary.d.ts.map +0 -1
- package/dist/types/useTranslationsDictionaryDynamic.d.ts +0 -12
- package/dist/types/useTranslationsDictionaryDynamic.d.ts.map +0 -1
package/dist/esm/index.mjs
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { defineRouting } from "./routing.mjs";
|
|
2
|
-
import { hasLocale } from "./hasLocale.mjs";
|
|
3
|
-
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
4
|
-
import { useDictionary } from "./useDictionary.mjs";
|
|
5
|
-
import { IntlProvider, useExtracted, useFormatter, useMessages, useNow, useTimeZone } from "./client/helpers.mjs";
|
|
6
2
|
import { NextIntlClientProvider } from "./client/NextIntlClientProvider.mjs";
|
|
7
3
|
import { useLocale } from "./client/useLocale.mjs";
|
|
8
|
-
import { useTranslations } from "./client/
|
|
4
|
+
import { IntlProvider, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useMessages, useNow, useTimeZone, useTranslations } from "./client/index.mjs";
|
|
5
|
+
import { IntlError, IntlErrorCode, createFormatter, createTranslator, hasLocale, initializeConfig } from "@intlayer/use-intl";
|
|
9
6
|
|
|
10
|
-
export { IntlProvider, NextIntlClientProvider, defineRouting, hasLocale, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
7
|
+
export { IntlError, IntlErrorCode, IntlProvider, NextIntlClientProvider, createFormatter, createTranslator, defineRouting, hasLocale, initializeConfig, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.mjs","names":[],"sources":["../../src/middleware.ts"],"sourcesContent":["import type { NextFetchEvent, NextRequest } from 'next/server';\nimport type _createMiddleware from 'next-intl/middleware';\nimport { intlayerMiddleware } from 'next-intlayer/middleware';\n\n/**\n * Drop-in replacement for next-intl's `createMiddleware`.\n *\n * Returns Intlayer's proxy/middleware, which handles locale detection and\n * routing from the Intlayer configuration. The `routing` argument is accepted\n * for API compatibility but ignored — locales come from `intlayer.config`.\n *\n * @example\n * ```ts\n * // proxy.ts (or middleware.ts on Next <= 15)\n * import createMiddleware from 'next-intl/middleware';\n * export default createMiddleware(routing);\n * export const config = { matcher: ['/((?!api|_next|.*\\\\..*).*)'] };\n * ```\n */\nexport const createMiddleware: typeof _createMiddleware =\n (_routing?: unknown) => (request: NextRequest, event?: NextFetchEvent) => {\n const response = intlayerMiddleware(request, event);\n\n if (response) {\n // Intlayer middleware writes the resolved locale to the x-intlayer-locale header\n // We read it and explicitly set the NEXT_LOCALE cookie to maintain compatibility with next-intl\n const resolvedLocale = response.headers.get('x-intlayer-locale');\n if (resolvedLocale) {\n response.cookies.set('NEXT_LOCALE', resolvedLocale, {\n path: '/',\n sameSite: 'lax',\n maxAge: 60 * 60 * 24 * 365,\n });\n }\n }\n\n return response;\n };\n\nexport default createMiddleware;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAa,oBACV,cAAwB,SAAsB,UAA2B;CACxE,MAAM,WAAW,mBAAmB,SAAS,
|
|
1
|
+
{"version":3,"file":"middleware.mjs","names":[],"sources":["../../src/middleware.ts"],"sourcesContent":["import type { NextFetchEvent, NextRequest } from 'next/server';\nimport type _createMiddleware from 'next-intl/middleware';\nimport { intlayerMiddleware } from 'next-intlayer/middleware';\n\n/**\n * Drop-in replacement for next-intl's `createMiddleware`.\n *\n * Returns Intlayer's proxy/middleware, which handles locale detection and\n * routing from the Intlayer configuration. The `routing` argument is accepted\n * for API compatibility but ignored — locales come from `intlayer.config`.\n *\n * @example\n * ```ts\n * // proxy.ts (or middleware.ts on Next <= 15)\n * import createMiddleware from 'next-intl/middleware';\n * export default createMiddleware(routing);\n * export const config = { matcher: ['/((?!api|_next|.*\\\\..*).*)'] };\n * ```\n */\nexport const createMiddleware: typeof _createMiddleware =\n (_routing?: unknown) => (request: NextRequest, event?: NextFetchEvent) => {\n const response = intlayerMiddleware(request, event);\n\n if (response) {\n // Intlayer middleware writes the resolved locale to the x-intlayer-locale header\n // We read it and explicitly set the NEXT_LOCALE cookie to maintain compatibility with next-intl\n const resolvedLocale = response.headers.get('x-intlayer-locale');\n if (resolvedLocale) {\n response.cookies.set('NEXT_LOCALE', resolvedLocale, {\n path: '/',\n sameSite: 'lax',\n maxAge: 60 * 60 * 24 * 365,\n });\n }\n }\n\n return response;\n };\n\nexport default createMiddleware;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAa,oBACV,cAAwB,SAAsB,UAA2B;CACxE,MAAM,WAAW,mBAAmB,SAAS,KAAK;CAElD,IAAI,UAAU;EAGZ,MAAM,iBAAiB,SAAS,QAAQ,IAAI,mBAAmB;EAC/D,IAAI,gBACF,SAAS,QAAQ,IAAI,eAAe,gBAAgB;GAClD,MAAM;GACN,UAAU;GACV,QAAQ,OAAU,KAAK;EACzB,CAAC;CAEL;CAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.mjs","names":[],"sources":["../../../src/navigation/Link.tsx"],"sourcesContent":["'use client';\n\nimport NextLink from 'next/link';\nimport { useLocale } from 'next-intlayer';\nimport { type ComponentPropsWithoutRef, forwardRef, type Ref } from 'react';\nimport { localizeHref, type NextIntlHref } from './localizeHref';\n\n/**\n * Props for the compat `Link`: identical to `next/link` except `href` accepts a\n * `next-intl` href and an optional `locale` overrides the current one.\n */\nexport type LinkProps = Omit<\n ComponentPropsWithoutRef<typeof NextLink>,\n 'href' | 'locale'\n> & {\n href: NextIntlHref;\n locale?: string;\n};\n\n/**\n * Drop-in for the `Link` returned by next-intl's `createNavigation`. Prefixes\n * `href` with the active locale (or the `locale` prop) before delegating to\n * `next/link`.\n */\nexport const Link = forwardRef(\n ({ href, locale, ...rest }: LinkProps, ref: Ref<HTMLAnchorElement>) => {\n const { locale: currentLocale } = useLocale();\n const targetLocale = locale ?? (currentLocale as string);\n\n return (\n <NextLink ref={ref} href={localizeHref(href, targetLocale)} {...rest} />\n );\n }\n);\n\nLink.displayName = 'Link';\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAa,OAAO,YACjB,EAAE,MAAM,QAAQ,GAAG,QAAmB,QAAgC;CACrE,MAAM,EAAE,QAAQ,kBAAkB,
|
|
1
|
+
{"version":3,"file":"Link.mjs","names":[],"sources":["../../../src/navigation/Link.tsx"],"sourcesContent":["'use client';\n\nimport NextLink from 'next/link';\nimport { useLocale } from 'next-intlayer';\nimport { type ComponentPropsWithoutRef, forwardRef, type Ref } from 'react';\nimport { localizeHref, type NextIntlHref } from './localizeHref';\n\n/**\n * Props for the compat `Link`: identical to `next/link` except `href` accepts a\n * `next-intl` href and an optional `locale` overrides the current one.\n */\nexport type LinkProps = Omit<\n ComponentPropsWithoutRef<typeof NextLink>,\n 'href' | 'locale'\n> & {\n href: NextIntlHref;\n locale?: string;\n};\n\n/**\n * Drop-in for the `Link` returned by next-intl's `createNavigation`. Prefixes\n * `href` with the active locale (or the `locale` prop) before delegating to\n * `next/link`.\n */\nexport const Link = forwardRef(\n ({ href, locale, ...rest }: LinkProps, ref: Ref<HTMLAnchorElement>) => {\n const { locale: currentLocale } = useLocale();\n const targetLocale = locale ?? (currentLocale as string);\n\n return (\n <NextLink ref={ref} href={localizeHref(href, targetLocale)} {...rest} />\n );\n }\n);\n\nLink.displayName = 'Link';\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAa,OAAO,YACjB,EAAE,MAAM,QAAQ,GAAG,QAAmB,QAAgC;CACrE,MAAM,EAAE,QAAQ,kBAAkB,UAAU;CAG5C,OACE,oBAAC,UAAD;EAAe;EAAK,MAAM,aAAa,MAHpB,UAAW,aAG2B;EAAG,GAAI;CAAO;AAE3E,CACF;AAEA,KAAK,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNavigation.mjs","names":["redirect","nextRedirect","permanentRedirect","nextPermanentRedirect"],"sources":["../../../src/navigation/createNavigation.ts"],"sourcesContent":["import {\n permanentRedirect as nextPermanentRedirect,\n redirect as nextRedirect,\n} from 'next/navigation';\nimport type { createNavigation as _createNavigation } from 'next-intl/navigation';\nimport { usePathname, useRouter } from './hooks';\nimport { Link } from './Link';\nimport { localizeHref, type NextIntlHref } from './localizeHref';\n\n/** Arguments shared by `getPathname`, `redirect` and `permanentRedirect`. */\ntype LocalizedHrefArgs = { href: NextIntlHref; locale: string };\n\n/** The optional `RedirectType` accepted by `next/navigation`'s redirect APIs. */\ntype RedirectTypeArg = Parameters<typeof nextRedirect>[1];\n\n/**\n * Drop-in replacement for next-intl's `createNavigation`.\n *\n * Returns locale-aware navigation APIs (`Link`, `usePathname`, `useRouter`,\n * `getPathname`, `redirect`, `permanentRedirect`) backed by Intlayer's routing\n * configuration. The `routing` argument is accepted for API compatibility;\n * locales come from the Intlayer configuration.\n *\n * @example\n * ```ts\n * export const { Link, redirect, usePathname, useRouter, getPathname } =\n * createNavigation();\n * ```\n */\nexport const createNavigation: typeof _createNavigation = (\n _routing?: unknown\n) => {\n const getPathname = ({ href, locale }: LocalizedHrefArgs): string =>\n localizeHref(href, locale);\n\n const redirect = (\n { href, locale }: LocalizedHrefArgs,\n type?: RedirectTypeArg\n ) => nextRedirect(localizeHref(href, locale), type);\n\n const permanentRedirect = (\n { href, locale }: LocalizedHrefArgs,\n type?: RedirectTypeArg\n ) => nextPermanentRedirect(localizeHref(href, locale), type);\n\n return {\n Link: Link as ReturnType<typeof _createNavigation>['Link'],\n usePathname,\n useRouter,\n getPathname,\n redirect,\n permanentRedirect,\n } as ReturnType<typeof _createNavigation>;\n};\n\nexport default createNavigation;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,oBACX,aACG;CACH,MAAM,eAAe,EAAE,MAAM,aAC3B,aAAa,MAAM,
|
|
1
|
+
{"version":3,"file":"createNavigation.mjs","names":["redirect","nextRedirect","permanentRedirect","nextPermanentRedirect"],"sources":["../../../src/navigation/createNavigation.ts"],"sourcesContent":["import {\n permanentRedirect as nextPermanentRedirect,\n redirect as nextRedirect,\n} from 'next/navigation';\nimport type { createNavigation as _createNavigation } from 'next-intl/navigation';\nimport { usePathname, useRouter } from './hooks';\nimport { Link } from './Link';\nimport { localizeHref, type NextIntlHref } from './localizeHref';\n\n/** Arguments shared by `getPathname`, `redirect` and `permanentRedirect`. */\ntype LocalizedHrefArgs = { href: NextIntlHref; locale: string };\n\n/** The optional `RedirectType` accepted by `next/navigation`'s redirect APIs. */\ntype RedirectTypeArg = Parameters<typeof nextRedirect>[1];\n\n/**\n * Drop-in replacement for next-intl's `createNavigation`.\n *\n * Returns locale-aware navigation APIs (`Link`, `usePathname`, `useRouter`,\n * `getPathname`, `redirect`, `permanentRedirect`) backed by Intlayer's routing\n * configuration. The `routing` argument is accepted for API compatibility;\n * locales come from the Intlayer configuration.\n *\n * @example\n * ```ts\n * export const { Link, redirect, usePathname, useRouter, getPathname } =\n * createNavigation();\n * ```\n */\nexport const createNavigation: typeof _createNavigation = (\n _routing?: unknown\n) => {\n const getPathname = ({ href, locale }: LocalizedHrefArgs): string =>\n localizeHref(href, locale);\n\n const redirect = (\n { href, locale }: LocalizedHrefArgs,\n type?: RedirectTypeArg\n ) => nextRedirect(localizeHref(href, locale), type);\n\n const permanentRedirect = (\n { href, locale }: LocalizedHrefArgs,\n type?: RedirectTypeArg\n ) => nextPermanentRedirect(localizeHref(href, locale), type);\n\n return {\n Link: Link as ReturnType<typeof _createNavigation>['Link'],\n usePathname,\n useRouter,\n getPathname,\n redirect,\n permanentRedirect,\n } as ReturnType<typeof _createNavigation>;\n};\n\nexport default createNavigation;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,oBACX,aACG;CACH,MAAM,eAAe,EAAE,MAAM,aAC3B,aAAa,MAAM,MAAM;CAE3B,MAAMA,cACJ,EAAE,MAAM,UACR,SACGC,SAAa,aAAa,MAAM,MAAM,GAAG,IAAI;CAElD,MAAMC,uBACJ,EAAE,MAAM,UACR,SACGC,kBAAsB,aAAa,MAAM,MAAM,GAAG,IAAI;CAE3D,OAAO;EACC;EACN;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.mjs","names":["useNextPathname","useNextRouter"],"sources":["../../../src/navigation/hooks.ts"],"sourcesContent":["'use client';\n\nimport {\n usePathname as useNextPathname,\n useRouter as useNextRouter,\n} from 'next/navigation';\nimport { useLocale } from 'next-intlayer';\nimport { localizeHref, type NextIntlHref } from './localizeHref';\n\n/**\n * Options accepted by the locale-aware router methods: the standard Next.js\n * navigate options plus an optional target `locale`.\n */\ntype NavigateOptions = { locale?: string } & Record<string, unknown>;\n\n/**\n * Drop-in for the `usePathname` returned by next-intl's `createNavigation`.\n * Returns the current pathname with the locale prefix stripped.\n */\nexport const usePathname = (): string => {\n const pathname = useNextPathname();\n const { locale } = useLocale();\n const prefix = `/${locale}`;\n\n if (pathname === prefix) return '/';\n if (pathname.startsWith(`${prefix}/`)) return pathname.slice(prefix.length);\n return pathname;\n};\n\n/**\n * Drop-in for the `useRouter` returned by next-intl's `createNavigation`.\n * Wraps the Next.js router so `push`/`replace`/`prefetch` localize their href\n * (honouring an optional `locale` option) before navigating.\n */\nexport const useRouter = () => {\n const router = useNextRouter();\n const { locale: currentLocale } = useLocale();\n\n const localize = (href: NextIntlHref, locale?: string): string =>\n localizeHref(href, locale ?? (currentLocale as string));\n\n return {\n ...router,\n push: (href: NextIntlHref, options?: NavigateOptions) =>\n router.push(\n localize(href, options?.locale),\n options as Parameters<typeof router.push>[1]\n ),\n replace: (href: NextIntlHref, options?: NavigateOptions) =>\n router.replace(\n localize(href, options?.locale),\n options as Parameters<typeof router.replace>[1]\n ),\n prefetch: (href: NextIntlHref, options?: NavigateOptions) =>\n router.prefetch(localize(href, options?.locale)),\n };\n};\n"],"mappings":";;;;;;;;;;;AAmBA,MAAa,oBAA4B;CACvC,MAAM,WAAWA,
|
|
1
|
+
{"version":3,"file":"hooks.mjs","names":["useNextPathname","useNextRouter"],"sources":["../../../src/navigation/hooks.ts"],"sourcesContent":["'use client';\n\nimport {\n usePathname as useNextPathname,\n useRouter as useNextRouter,\n} from 'next/navigation';\nimport { useLocale } from 'next-intlayer';\nimport { localizeHref, type NextIntlHref } from './localizeHref';\n\n/**\n * Options accepted by the locale-aware router methods: the standard Next.js\n * navigate options plus an optional target `locale`.\n */\ntype NavigateOptions = { locale?: string } & Record<string, unknown>;\n\n/**\n * Drop-in for the `usePathname` returned by next-intl's `createNavigation`.\n * Returns the current pathname with the locale prefix stripped.\n */\nexport const usePathname = (): string => {\n const pathname = useNextPathname();\n const { locale } = useLocale();\n const prefix = `/${locale}`;\n\n if (pathname === prefix) return '/';\n if (pathname.startsWith(`${prefix}/`)) return pathname.slice(prefix.length);\n return pathname;\n};\n\n/**\n * Drop-in for the `useRouter` returned by next-intl's `createNavigation`.\n * Wraps the Next.js router so `push`/`replace`/`prefetch` localize their href\n * (honouring an optional `locale` option) before navigating.\n */\nexport const useRouter = () => {\n const router = useNextRouter();\n const { locale: currentLocale } = useLocale();\n\n const localize = (href: NextIntlHref, locale?: string): string =>\n localizeHref(href, locale ?? (currentLocale as string));\n\n return {\n ...router,\n push: (href: NextIntlHref, options?: NavigateOptions) =>\n router.push(\n localize(href, options?.locale),\n options as Parameters<typeof router.push>[1]\n ),\n replace: (href: NextIntlHref, options?: NavigateOptions) =>\n router.replace(\n localize(href, options?.locale),\n options as Parameters<typeof router.replace>[1]\n ),\n prefetch: (href: NextIntlHref, options?: NavigateOptions) =>\n router.prefetch(localize(href, options?.locale)),\n };\n};\n"],"mappings":";;;;;;;;;;;AAmBA,MAAa,oBAA4B;CACvC,MAAM,WAAWA,cAAgB;CACjC,MAAM,EAAE,WAAW,UAAU;CAC7B,MAAM,SAAS,IAAI;CAEnB,IAAI,aAAa,QAAQ,OAAO;CAChC,IAAI,SAAS,WAAW,GAAG,OAAO,EAAE,GAAG,OAAO,SAAS,MAAM,OAAO,MAAM;CAC1E,OAAO;AACT;;;;;;AAOA,MAAa,kBAAkB;CAC7B,MAAM,SAASC,YAAc;CAC7B,MAAM,EAAE,QAAQ,kBAAkB,UAAU;CAE5C,MAAM,YAAY,MAAoB,WACpC,aAAa,MAAM,UAAW,aAAwB;CAExD,OAAO;EACL,GAAG;EACH,OAAO,MAAoB,YACzB,OAAO,KACL,SAAS,MAAM,SAAS,MAAM,GAC9B,OACF;EACF,UAAU,MAAoB,YAC5B,OAAO,QACL,SAAS,MAAM,SAAS,MAAM,GAC9B,OACF;EACF,WAAW,MAAoB,YAC7B,OAAO,SAAS,SAAS,MAAM,SAAS,MAAM,CAAC;CACnD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localizeHref.mjs","names":[],"sources":["../../../src/navigation/localizeHref.ts"],"sourcesContent":["import { getLocalizedUrl } from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * A `next-intl` navigation href: either a pathname string or an object with a\n * `pathname` and optional `query`. The `pathnames` (typed routes) feature is\n * accepted for API compatibility but not interpolated.\n */\nexport type NextIntlHref =\n | string\n | {\n pathname: string;\n query?: Record<string, string | number | (string | number)[]>;\n params?: Record<string, string | number | (string | number)[]>;\n };\n\n/**\n * Prefix a `next-intl` href with the given locale using Intlayer's\n * `getLocalizedUrl`, preserving any query parameters.\n *\n * @param href - The target href (string or `{ pathname, query }`).\n * @param locale - The locale to localize the href for.\n * @returns The localized URL string.\n */\nexport const localizeHref = (href: NextIntlHref, locale: string): string => {\n const pathname = typeof href === 'string' ? href : href.pathname;\n const localizedPathname = getLocalizedUrl(pathname, locale as LocalesValues);\n\n if (typeof href === 'string' || !href.query) {\n return localizedPathname;\n }\n\n const searchParams = new URLSearchParams();\n for (const [key, value] of Object.entries(href.query)) {\n if (Array.isArray(value)) {\n for (const entry of value) {\n searchParams.append(key, String(entry));\n }\n } else {\n searchParams.append(key, String(value));\n }\n }\n\n const queryString = searchParams.toString();\n return queryString\n ? `${localizedPathname}?${queryString}`\n : localizedPathname;\n};\n"],"mappings":";;;;;;;;;;;AAwBA,MAAa,gBAAgB,MAAoB,WAA2B;CAE1E,MAAM,oBAAoB,gBADT,OAAO,SAAS,WAAW,OAAO,KAAK,UACJ,
|
|
1
|
+
{"version":3,"file":"localizeHref.mjs","names":[],"sources":["../../../src/navigation/localizeHref.ts"],"sourcesContent":["import { getLocalizedUrl } from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * A `next-intl` navigation href: either a pathname string or an object with a\n * `pathname` and optional `query`. The `pathnames` (typed routes) feature is\n * accepted for API compatibility but not interpolated.\n */\nexport type NextIntlHref =\n | string\n | {\n pathname: string;\n query?: Record<string, string | number | (string | number)[]>;\n params?: Record<string, string | number | (string | number)[]>;\n };\n\n/**\n * Prefix a `next-intl` href with the given locale using Intlayer's\n * `getLocalizedUrl`, preserving any query parameters.\n *\n * @param href - The target href (string or `{ pathname, query }`).\n * @param locale - The locale to localize the href for.\n * @returns The localized URL string.\n */\nexport const localizeHref = (href: NextIntlHref, locale: string): string => {\n const pathname = typeof href === 'string' ? href : href.pathname;\n const localizedPathname = getLocalizedUrl(pathname, locale as LocalesValues);\n\n if (typeof href === 'string' || !href.query) {\n return localizedPathname;\n }\n\n const searchParams = new URLSearchParams();\n for (const [key, value] of Object.entries(href.query)) {\n if (Array.isArray(value)) {\n for (const entry of value) {\n searchParams.append(key, String(entry));\n }\n } else {\n searchParams.append(key, String(value));\n }\n }\n\n const queryString = searchParams.toString();\n return queryString\n ? `${localizedPathname}?${queryString}`\n : localizedPathname;\n};\n"],"mappings":";;;;;;;;;;;AAwBA,MAAa,gBAAgB,MAAoB,WAA2B;CAE1E,MAAM,oBAAoB,gBADT,OAAO,SAAS,WAAW,OAAO,KAAK,UACJ,MAAuB;CAE3E,IAAI,OAAO,SAAS,YAAY,CAAC,KAAK,OACpC,OAAO;CAGT,MAAM,eAAe,IAAI,gBAAgB;CACzC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,KAAK,GAClD,IAAI,MAAM,QAAQ,KAAK,GACrB,KAAK,MAAM,SAAS,OAClB,aAAa,OAAO,KAAK,OAAO,KAAK,CAAC;MAGxC,aAAa,OAAO,KAAK,OAAO,KAAK,CAAC;CAI1C,MAAM,cAAc,aAAa,SAAS;CAC1C,OAAO,cACH,GAAG,kBAAkB,GAAG,gBACxB;AACN"}
|
|
@@ -3,8 +3,9 @@ import * as ANSIColors from "@intlayer/config/colors";
|
|
|
3
3
|
import { colorize, getAppLogger } from "@intlayer/config/logger";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
6
|
-
import {
|
|
6
|
+
import { NEXT_INTL_CALLERS, toSwcExtraCallers } from "@intlayer/config/callers";
|
|
7
7
|
import { getConfiguration } from "@intlayer/config/node";
|
|
8
|
+
import { runOnce } from "@intlayer/engine/utils";
|
|
8
9
|
|
|
9
10
|
//#region src/plugin/index.ts
|
|
10
11
|
/**
|
|
@@ -86,19 +87,12 @@ const resolveEsmPath = (specifier) => {
|
|
|
86
87
|
* @returns Relative specifier such as `./node_modules/@intlayer/next-intl/...`.
|
|
87
88
|
*/
|
|
88
89
|
const toTurbopackAlias = (absolutePath) => `./${relative(process.cwd(), absolutePath).split(sep).join("/")}`;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}, {
|
|
96
|
-
callerName: "getTranslations",
|
|
97
|
-
importSources: ["next-intl/server", "@intlayer/next-intl/server"],
|
|
98
|
-
namespaceArgIndex: 0,
|
|
99
|
-
staticReplacement: "getDictionary",
|
|
100
|
-
dynamicReplacement: "getDictionaryDynamic"
|
|
101
|
-
}];
|
|
90
|
+
/**
|
|
91
|
+
* SWC extra-caller configs derived from the shared caller registry
|
|
92
|
+
* (`@intlayer/config/callers`) — the single source of truth also consumed by
|
|
93
|
+
* the babel analyzer/optimizer and the LSP.
|
|
94
|
+
*/
|
|
95
|
+
const NEXT_INTL_SWC_CALLERS = toSwcExtraCallers(NEXT_INTL_CALLERS);
|
|
102
96
|
/**
|
|
103
97
|
* A Next.js plugin for next-intl compat that wraps next-intlayer's plugin
|
|
104
98
|
* and configures resolve aliases so `next-intl` imports are served by
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original `next-intl` import specifier to the `@intlayer/next-intl`\n * specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-intl/server', replacement: '@intlayer/next-intl/server' },\n { request: 'next-intl/routing', replacement: '@intlayer/next-intl/routing' },\n {\n request: 'next-intl/navigation',\n replacement: '@intlayer/next-intl/navigation',\n },\n {\n request: 'next-intl/middleware',\n replacement: '@intlayer/next-intl/middleware',\n },\n { request: 'next-intl', replacement: '@intlayer/next-intl' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/next-intl/server` or `next-intl`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName?.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/next-intl/server`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n string | { import?: string; require?: string; default?: string }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/next-intl/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\nconst NEXT_INTL_SWC_CALLERS = [\n {\n callerName: 'useTranslations',\n importSources: ['next-intl', '@intlayer/next-intl'],\n namespaceArgIndex: 0,\n staticReplacement: 'useDictionary',\n dynamicReplacement: 'useDictionaryDynamic',\n },\n {\n callerName: 'getTranslations',\n importSources: ['next-intl/server', '@intlayer/next-intl/server'],\n namespaceArgIndex: 0,\n staticReplacement: 'getDictionary',\n dynamicReplacement: 'getDictionaryDynamic',\n },\n];\n\n/**\n * A Next.js plugin for next-intl compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-intl` imports are served by\n * `@intlayer/next-intl`.\n */\nexport const createNextIntlPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig?.system?.baseDir ?? process.cwd(),\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n absolutePath: resolveEsmPath(replacement),\n }));\n\n // Webpack resolves aliases from absolute paths.\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n absolutePath,\n ])\n );\n\n // Turbopack only honours project-root-relative `./` paths.\n const turboAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n toTurbopackAlias(absolutePath),\n ])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n // Only inject the NEXT_LOCALE cookie default when the user has not\n // configured their own routing.storage in intlayer.config.ts.\n // This lets users override via intlayer.config.ts while keeping\n // next-intl compatibility (NEXT_LOCALE) as the default.\n let hasUserDefinedStorage = false;\n try {\n hasUserDefinedStorage = !!(\n intlayerConfig?.routing &&\n 'storage' in intlayerConfig.routing &&\n intlayerConfig.routing.storage !== undefined\n );\n } catch {\n // If the config file cannot be read, fall back to the NEXT_LOCALE default.\n }\n\n const configOptions = hasUserDefinedStorage\n ? { swcExtraCallers: NEXT_INTL_SWC_CALLERS }\n : {\n override: {\n routing: {\n storage: [\n { type: 'cookie' as const, name: 'NEXT_LOCALE' },\n { type: 'header' as const, name: 'x-intlayer-locale' },\n ],\n },\n },\n swcExtraCallers: NEXT_INTL_SWC_CALLERS,\n };\n\n return withIntlayer(mergedConfig, configOptions);\n };\n};\n\nexport default createNextIntlPlugin;\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport { NEXT_INTL_CALLERS, toSwcExtraCallers } from '@intlayer/config/callers';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { runOnce } from '@intlayer/engine/utils';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original `next-intl` import specifier to the `@intlayer/next-intl`\n * specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-intl/server', replacement: '@intlayer/next-intl/server' },\n { request: 'next-intl/routing', replacement: '@intlayer/next-intl/routing' },\n {\n request: 'next-intl/navigation',\n replacement: '@intlayer/next-intl/navigation',\n },\n {\n request: 'next-intl/middleware',\n replacement: '@intlayer/next-intl/middleware',\n },\n { request: 'next-intl', replacement: '@intlayer/next-intl' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/next-intl/server` or `next-intl`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName?.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/next-intl/server`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n string | { import?: string; require?: string; default?: string }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/next-intl/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\n/**\n * SWC extra-caller configs derived from the shared caller registry\n * (`@intlayer/config/callers`) — the single source of truth also consumed by\n * the babel analyzer/optimizer and the LSP.\n */\nconst NEXT_INTL_SWC_CALLERS = toSwcExtraCallers(NEXT_INTL_CALLERS);\n\n/**\n * A Next.js plugin for next-intl compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-intl` imports are served by\n * `@intlayer/next-intl`.\n */\nexport const createNextIntlPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig?.system?.baseDir ?? process.cwd(),\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n absolutePath: resolveEsmPath(replacement),\n }));\n\n // Webpack resolves aliases from absolute paths.\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n absolutePath,\n ])\n );\n\n // Turbopack only honours project-root-relative `./` paths.\n const turboAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n toTurbopackAlias(absolutePath),\n ])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n // Only inject the NEXT_LOCALE cookie default when the user has not\n // configured their own routing.storage in intlayer.config.ts.\n // This lets users override via intlayer.config.ts while keeping\n // next-intl compatibility (NEXT_LOCALE) as the default.\n let hasUserDefinedStorage = false;\n try {\n hasUserDefinedStorage = !!(\n intlayerConfig?.routing &&\n 'storage' in intlayerConfig.routing &&\n intlayerConfig.routing.storage !== undefined\n );\n } catch {\n // If the config file cannot be read, fall back to the NEXT_LOCALE default.\n }\n\n const configOptions = hasUserDefinedStorage\n ? { swcExtraCallers: NEXT_INTL_SWC_CALLERS }\n : {\n override: {\n routing: {\n storage: [\n { type: 'cookie' as const, name: 'NEXT_LOCALE' },\n { type: 'header' as const, name: 'x-intlayer-locale' },\n ],\n },\n },\n swcExtraCallers: NEXT_INTL_SWC_CALLERS,\n };\n\n return withIntlayer(mergedConfig, configOptions);\n };\n};\n\nexport default createNextIntlPlugin;\n"],"mappings":"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"}
|
package/dist/esm/routing.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.mjs","names":[],"sources":["../../src/routing.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport type Routing = {\n locales: LocalesValues[];\n defaultLocale: LocalesValues;\n localePrefix?: 'always' | 'as-needed' | 'never';\n pathnames?: Record<string, string | Record<string, string>>;\n};\n\n/**\n * Drop-in replacement for next-intl's `defineRouting()`.\n *\n * Merges the provided config with Intlayer's own routing / internationalization\n * configuration so you don't have to repeat locale lists. All fields are\n * optional — omitted values are read from the Intlayer config at runtime.\n *\n * @example\n * ```ts\n * export default defineRouting({\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * });\n * ```\n */\nexport const defineRouting: (config?: Partial<Routing>) => Routing = (\n config?: Partial<Routing>\n): Routing => ({\n locales:\n config?.locales ??\n ((internationalization?.locales ?? []) as LocalesValues[]),\n defaultLocale:\n config?.defaultLocale ??\n (internationalization?.defaultLocale as LocalesValues),\n localePrefix:\n config?.localePrefix ?? (routing?.prefixDefault ? 'always' : 'as-needed'),\n ...config,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,MAAa,iBACX,YACa;CACb,SACE,QAAQ,WACN,sBAAsB,WAAW,
|
|
1
|
+
{"version":3,"file":"routing.mjs","names":[],"sources":["../../src/routing.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport type Routing = {\n locales: LocalesValues[];\n defaultLocale: LocalesValues;\n localePrefix?: 'always' | 'as-needed' | 'never';\n pathnames?: Record<string, string | Record<string, string>>;\n};\n\n/**\n * Drop-in replacement for next-intl's `defineRouting()`.\n *\n * Merges the provided config with Intlayer's own routing / internationalization\n * configuration so you don't have to repeat locale lists. All fields are\n * optional — omitted values are read from the Intlayer config at runtime.\n *\n * @example\n * ```ts\n * export default defineRouting({\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * });\n * ```\n */\nexport const defineRouting: (config?: Partial<Routing>) => Routing = (\n config?: Partial<Routing>\n): Routing => ({\n locales:\n config?.locales ??\n ((internationalization?.locales ?? []) as LocalesValues[]),\n defaultLocale:\n config?.defaultLocale ??\n (internationalization?.defaultLocale as LocalesValues),\n localePrefix:\n config?.localePrefix ?? (routing?.prefixDefault ? 'always' : 'as-needed'),\n ...config,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,MAAa,iBACX,YACa;CACb,SACE,QAAQ,WACN,sBAAsB,WAAW,CAAC;CACtC,eACE,QAAQ,iBACP,sBAAsB;CACzB,cACE,QAAQ,iBAAiB,SAAS,gBAAgB,WAAW;CAC/D,GAAG;AACL"}
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
import { getCachedRequestLocale } from "./requestLocaleCache.mjs";
|
|
1
2
|
import { getLocale as getLocale$1 } from "next-intlayer/server";
|
|
2
3
|
|
|
3
4
|
//#region src/server/getLocale.ts
|
|
4
5
|
/**
|
|
5
6
|
* Drop-in for next-intl's `getLocale()` server function.
|
|
7
|
+
*
|
|
8
|
+
* Resolution order mirrors next-intl's per-request model:
|
|
9
|
+
*
|
|
10
|
+
* 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`
|
|
11
|
+
* route segment) — the source of truth for URL-driven routing. This is what
|
|
12
|
+
* keeps server-rendered content and the locale switcher in sync with the URL
|
|
13
|
+
* instead of a stale cookie.
|
|
14
|
+
* 2. Otherwise Intlayer's own resolution (cookie / header / Accept-Language),
|
|
15
|
+
* for apps that drive the locale from storage rather than the route.
|
|
6
16
|
*/
|
|
7
|
-
const getLocale = async () =>
|
|
17
|
+
const getLocale = async () => {
|
|
18
|
+
const requestLocale = getCachedRequestLocale();
|
|
19
|
+
if (requestLocale) return requestLocale;
|
|
20
|
+
return await getLocale$1();
|
|
21
|
+
};
|
|
8
22
|
|
|
9
23
|
//#endregion
|
|
10
24
|
export { getLocale };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.mjs","names":["getLocaleIntlayer"],"sources":["../../../src/server/getLocale.ts"],"sourcesContent":["import type { getLocale as _getLocale } from 'next-intl/server';\nimport { getLocale as getLocaleIntlayer } from 'next-intlayer/server';\n\n/**\n * Drop-in for next-intl's `getLocale()` server function.\n */\nexport const getLocale: typeof _getLocale = async (): Promise<string>
|
|
1
|
+
{"version":3,"file":"getLocale.mjs","names":["getLocaleIntlayer"],"sources":["../../../src/server/getLocale.ts"],"sourcesContent":["import type { getLocale as _getLocale } from 'next-intl/server';\nimport { getLocale as getLocaleIntlayer } from 'next-intlayer/server';\nimport { getCachedRequestLocale } from './requestLocaleCache';\n\n/**\n * Drop-in for next-intl's `getLocale()` server function.\n *\n * Resolution order mirrors next-intl's per-request model:\n *\n * 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`\n * route segment) — the source of truth for URL-driven routing. This is what\n * keeps server-rendered content and the locale switcher in sync with the URL\n * instead of a stale cookie.\n * 2. Otherwise Intlayer's own resolution (cookie / header / Accept-Language),\n * for apps that drive the locale from storage rather than the route.\n */\nexport const getLocale: typeof _getLocale = async (): Promise<string> => {\n const requestLocale = getCachedRequestLocale();\n if (requestLocale) return requestLocale as string;\n\n return (await getLocaleIntlayer()) as string;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAa,YAA+B,YAA6B;CACvE,MAAM,gBAAgB,uBAAuB;CAC7C,IAAI,eAAe,OAAO;CAE1B,OAAQ,MAAMA,YAAkB;AAClC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMessages.mjs","names":[],"sources":["../../../src/server/getMessages.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { getMessages as _getMessages } from 'next-intl/server';\n\n/**\n * Drop-in replacement for next-intl's `getMessages()` server function.\n *\n * Returns all compiled dictionary content for the current locale as a flat\n * record keyed by dictionary name. Useful when you need to pass messages\n * to a `NextIntlClientProvider`.\n *\n * @example\n * ```ts\n * const messages = await getMessages();\n * ```\n *\n * @deprecated getMessages has no use case with intlayer.\n * Messages are loaded automatically under the hood\n */\nexport const getMessages: typeof _getMessages = async () => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('getMessages', CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return {};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,cAAmC,YAAY;
|
|
1
|
+
{"version":3,"file":"getMessages.mjs","names":[],"sources":["../../../src/server/getMessages.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { getMessages as _getMessages } from 'next-intl/server';\n\n/**\n * Drop-in replacement for next-intl's `getMessages()` server function.\n *\n * Returns all compiled dictionary content for the current locale as a flat\n * record keyed by dictionary name. Useful when you need to pass messages\n * to a `NextIntlClientProvider`.\n *\n * @example\n * ```ts\n * const messages = await getMessages();\n * ```\n *\n * @deprecated getMessages has no use case with intlayer.\n * Messages are loaded automatically under the hood\n */\nexport const getMessages: typeof _getMessages = async () => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('getMessages', CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return {};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,cAAmC,YAAY;CAGxD,AADkB,aAAa,EAAE,IAAI,CAC7B,CAAC,CACP,GAAG,SAAS,eAAe,IAAI,EAAE,gHACnC;CAGF,OAAO,CAAC;AACV"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { log } from "@intlayer/config/built";
|
|
2
|
+
import { CYAN } from "@intlayer/config/colors";
|
|
3
|
+
import { colorize, getAppLogger } from "@intlayer/config/logger";
|
|
4
|
+
|
|
5
|
+
//#region src/server/getRequestConfig.ts
|
|
6
|
+
/**
|
|
7
|
+
* Drop-in for next-intl's `getRequestConfig`.
|
|
8
|
+
*
|
|
9
|
+
* In next-intl this registers the per-request config (locale + messages) read
|
|
10
|
+
* by its own plugin. With intlayer the locale is resolved from routing /
|
|
11
|
+
* storage and messages come from compiled dictionaries, so the returned config
|
|
12
|
+
* is never consumed — this is an identity passthrough kept so existing
|
|
13
|
+
* `i18n/request.ts` files keep resolving and type-checking.
|
|
14
|
+
*
|
|
15
|
+
* @deprecated getRequestConfig has no use case with intlayer. The locale and
|
|
16
|
+
* messages are resolved automatically; the file can be removed.
|
|
17
|
+
*/
|
|
18
|
+
const getRequestConfig = (createRequestConfig) => {
|
|
19
|
+
getAppLogger({ log })(`${colorize("getRequestConfig", CYAN)} has no use case with intlayer. The locale and messages are resolved automatically; the i18n/request.ts file can be removed`);
|
|
20
|
+
return createRequestConfig;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { getRequestConfig as default, getRequestConfig };
|
|
25
|
+
//# sourceMappingURL=getRequestConfig.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRequestConfig.mjs","names":[],"sources":["../../../src/server/getRequestConfig.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { getRequestConfig as _getRequestConfig } from 'next-intl/server';\n\n/**\n * Drop-in for next-intl's `getRequestConfig`.\n *\n * In next-intl this registers the per-request config (locale + messages) read\n * by its own plugin. With intlayer the locale is resolved from routing /\n * storage and messages come from compiled dictionaries, so the returned config\n * is never consumed — this is an identity passthrough kept so existing\n * `i18n/request.ts` files keep resolving and type-checking.\n *\n * @deprecated getRequestConfig has no use case with intlayer. The locale and\n * messages are resolved automatically; the file can be removed.\n */\nexport const getRequestConfig: typeof _getRequestConfig = (\n createRequestConfig\n) => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('getRequestConfig', CYAN)} has no use case with intlayer. The locale and messages are resolved automatically; the i18n/request.ts file can be removed`\n );\n }\n\n return createRequestConfig;\n};\n\nexport default getRequestConfig;\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAa,oBACX,wBACG;CAGD,AADkB,aAAa,EAAE,IAAI,CAC7B,CAAC,CACP,GAAG,SAAS,oBAAoB,IAAI,EAAE,4HACxC;CAGF,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getLocale } from "./getLocale.mjs";
|
|
2
|
-
import { createTranslator } from "
|
|
2
|
+
import { createTranslator } from "@intlayer/use-intl";
|
|
3
3
|
|
|
4
4
|
//#region src/server/getTranslations.ts
|
|
5
5
|
/**
|
|
@@ -10,8 +10,9 @@ import { createTranslator } from "../createTranslator.mjs";
|
|
|
10
10
|
* arguments (`{value, number}`). Rich text is available through `t.rich()`
|
|
11
11
|
* and `t.markup()`.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Resolves the active locale from the current request (or the `locale` option)
|
|
14
|
+
* and delegates to `@intlayer/use-intl`'s `createTranslator`, the same runtime
|
|
15
|
+
* that backs the client `useTranslations`.
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* ```ts
|
|
@@ -36,7 +37,10 @@ const getTranslations = (async (namespaceOrOptions) => {
|
|
|
36
37
|
namespace = namespaceOrOptions.namespace;
|
|
37
38
|
localeOverride = namespaceOrOptions.locale;
|
|
38
39
|
} else namespace = namespaceOrOptions;
|
|
39
|
-
return createTranslator(
|
|
40
|
+
return createTranslator({
|
|
41
|
+
locale: localeOverride ?? await getLocale(),
|
|
42
|
+
namespace
|
|
43
|
+
});
|
|
40
44
|
});
|
|
41
45
|
|
|
42
46
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTranslations.mjs","names":[],"sources":["../../../src/server/getTranslations.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"getTranslations.mjs","names":[],"sources":["../../../src/server/getTranslations.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n createTranslator,\n type LooseTranslateFunction,\n type TranslateFunction,\n type TranslateFunctionForNamespace,\n} from '@intlayer/use-intl';\nimport { getLocale } from './getLocale';\n\n/**\n * Options accepted by the options-object overload of {@link getTranslations}.\n */\ntype GetTranslationsOptions<N extends DictionaryKeys> = {\n /** The dictionary namespace to scope translations to. */\n namespace?: N;\n /** Override the locale instead of reading it from the current request. */\n locale?: LocalesValues;\n};\n\n/**\n * Overload set for {@link getTranslations}:\n *\n * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).\n * 2. An options object `{ namespace?, locale? }` → typed when namespace is\n * a known `DictionaryKeys` value.\n * 3. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative\n * dot-paths under the scope, typed against the dictionary, matching\n * next-intl's scoped-namespace behaviour.\n * 4. No namespace → root scope; the first segment of each key designates\n * the dictionary (`t('about.title')`).\n *\n * The translate function shape (`t`, `t.rich`, `t.markup`, `t.raw`, `t.has`)\n * is shared with `@intlayer/use-intl`.\n */\ntype GetTranslations = {\n <N extends DictionaryKeys>(namespace: N): Promise<TranslateFunction<N>>;\n <N extends DictionaryKeys>(\n options: GetTranslationsOptions<N>\n ): Promise<TranslateFunction<N>>;\n <N extends `${string}.${string}`>(\n namespace: N\n ): Promise<TranslateFunctionForNamespace<N>>;\n (): Promise<LooseTranslateFunction>;\n};\n\n/**\n * Drop-in for next-intl's server `getTranslations()`.\n *\n * Messages support ICU MessageFormat syntax: simple arguments (`{name}`),\n * plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted\n * arguments (`{value, number}`). Rich text is available through `t.rich()`\n * and `t.markup()`.\n *\n * Resolves the active locale from the current request (or the `locale` option)\n * and delegates to `@intlayer/use-intl`'s `createTranslator`, the same runtime\n * that backs the client `useTranslations`.\n *\n * @example\n * ```ts\n * // Bare namespace — fully typed dot-paths\n * const t = await getTranslations('about');\n * return <h1>{t('counter.label')}</h1>;\n *\n * // ICU plural\n * t('items', { count: 3 });\n *\n * // Options object with locale override\n * const t = await getTranslations({ namespace: 'about', locale: 'fr' });\n *\n * // Rich text\n * t.rich('terms', { link: (chunks) => <a href=\"/terms\">{chunks}</a> });\n * ```\n */\nexport const getTranslations: GetTranslations = (async (\n namespaceOrOptions?: string | GetTranslationsOptions<DictionaryKeys>\n) => {\n let namespace: string | undefined;\n let localeOverride: LocalesValues | undefined;\n\n if (typeof namespaceOrOptions === 'object' && namespaceOrOptions !== null) {\n namespace = namespaceOrOptions.namespace;\n localeOverride = namespaceOrOptions.locale;\n } else {\n namespace = namespaceOrOptions as string | undefined;\n }\n\n const locale = localeOverride ?? (await getLocale());\n\n return createTranslator({ locale: locale as LocalesValues, namespace });\n}) as GetTranslations;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,MAAa,mBAAoC,OAC/C,uBACG;CACH,IAAI;CACJ,IAAI;CAEJ,IAAI,OAAO,uBAAuB,YAAY,uBAAuB,MAAM;EACzE,YAAY,mBAAmB;EAC/B,iBAAiB,mBAAmB;CACtC,OACE,YAAY;CAKd,OAAO,iBAAiB;EAAE,QAFX,kBAAmB,MAAM,UAAU;EAES;CAAU,CAAC;AACxE"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { createFormatter } from "../createFormatter.mjs";
|
|
2
1
|
import { getLocale } from "./getLocale.mjs";
|
|
2
|
+
import { createFormatter } from "@intlayer/use-intl";
|
|
3
3
|
|
|
4
4
|
//#region src/server/helpers.ts
|
|
5
5
|
/**
|
|
6
6
|
* Drop-in for next-intl's server `getFormatter()`.
|
|
7
|
-
* Returns locale-aware formatters backed by the native `Intl.*` APIs
|
|
7
|
+
* Returns locale-aware formatters backed by the native `Intl.*` APIs,
|
|
8
|
+
* built by `@intlayer/use-intl`'s `createFormatter`.
|
|
8
9
|
*/
|
|
9
10
|
const getFormatter = (async (options) => {
|
|
10
|
-
return createFormatter(options?.locale ?? await getLocale());
|
|
11
|
+
return createFormatter({ locale: options?.locale ?? await getLocale() });
|
|
11
12
|
});
|
|
12
13
|
/**
|
|
13
14
|
* Drop-in for next-intl's server `getNow()`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../src/server/helpers.ts"],"sourcesContent":["import type {\n getFormatter as _getFormatter,\n getNow as _getNow,\n getTimeZone as _getTimeZone,\n} from 'next-intl/server';\nimport {
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../src/server/helpers.ts"],"sourcesContent":["import { createFormatter } from '@intlayer/use-intl';\nimport type {\n getFormatter as _getFormatter,\n getNow as _getNow,\n getTimeZone as _getTimeZone,\n} from 'next-intl/server';\nimport { getLocale } from './getLocale';\n\n/**\n * Drop-in for next-intl's server `getFormatter()`.\n * Returns locale-aware formatters backed by the native `Intl.*` APIs,\n * built by `@intlayer/use-intl`'s `createFormatter`.\n */\nexport const getFormatter: typeof _getFormatter = (async (options?: {\n locale?: string;\n}) => {\n const locale = options?.locale ?? (await getLocale());\n return createFormatter({ locale: locale as string });\n}) as typeof _getFormatter;\n\n/**\n * Drop-in for next-intl's server `getNow()`.\n * Returns the current `Date`.\n */\nexport const getNow: typeof _getNow = (async () =>\n new Date()) as typeof _getNow;\n\n/**\n * Drop-in for next-intl's server `getTimeZone()`.\n * Returns the system time zone resolved from `Intl.DateTimeFormat`.\n */\nexport const getTimeZone: typeof _getTimeZone = (async () =>\n Intl.DateTimeFormat().resolvedOptions().timeZone) as typeof _getTimeZone;\n"],"mappings":";;;;;;;;;AAaA,MAAa,gBAAsC,OAAO,YAEpD;CAEJ,OAAO,gBAAgB,EAAE,QADV,SAAS,UAAW,MAAM,UAAU,EACD,CAAC;AACrD;;;;;AAMA,MAAa,UAA0B,4BACrC,IAAI,KAAK;;;;;AAMX,MAAa,eAAoC,YAC/C,KAAK,eAAe,CAAC,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -2,8 +2,10 @@ import { getLocale } from "./getLocale.mjs";
|
|
|
2
2
|
import { getDictionary } from "../getDictionary.mjs";
|
|
3
3
|
import { getDictionaryDynamic } from "../getDictionaryDynamic.mjs";
|
|
4
4
|
import { getFormatter, getNow, getTimeZone } from "./helpers.mjs";
|
|
5
|
+
import getRequestConfig from "./getRequestConfig.mjs";
|
|
6
|
+
import { setRequestLocale } from "./setRequestLocale.mjs";
|
|
5
7
|
import { setLocale } from "./setLocale.mjs";
|
|
6
8
|
import { getTranslations } from "./getTranslations.mjs";
|
|
7
9
|
import { getMessages } from "./getMessages.mjs";
|
|
8
10
|
|
|
9
|
-
export { getDictionary, getDictionaryDynamic, getFormatter, getLocale, getMessages, getNow, getTimeZone, getTranslations, setLocale };
|
|
11
|
+
export { getDictionary, getDictionaryDynamic, getFormatter, getLocale, getMessages, getNow, getRequestConfig, getTimeZone, getTranslations, setLocale, setRequestLocale };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { cache } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/server/requestLocaleCache.ts
|
|
4
|
+
/**
|
|
5
|
+
* Request-scoped holder for the locale provided through {@link setRequestLocale}.
|
|
6
|
+
*
|
|
7
|
+
* next-intl resolves the active locale per request from the `[locale]` route
|
|
8
|
+
* segment, which the app forwards via `setRequestLocale(locale)`. React's
|
|
9
|
+
* `cache()` gives a per-request singleton (the same trick next-intl uses in its
|
|
10
|
+
* own `RequestLocaleCache`), so the value set in the layout/page is readable by
|
|
11
|
+
* the other server APIs (`getLocale`, `getTranslations`, …) during the same
|
|
12
|
+
* render.
|
|
13
|
+
*
|
|
14
|
+
* @see https://github.com/vercel/next.js/discussions/58862
|
|
15
|
+
*/
|
|
16
|
+
const getRequestLocaleHolder = cache(() => ({ locale: void 0 }));
|
|
17
|
+
/**
|
|
18
|
+
* Read the locale stored for the current request, or `undefined` when
|
|
19
|
+
* `setRequestLocale` has not been called.
|
|
20
|
+
*/
|
|
21
|
+
const getCachedRequestLocale = () => getRequestLocaleHolder().locale;
|
|
22
|
+
/**
|
|
23
|
+
* Store the locale for the current request. Called by `setRequestLocale`.
|
|
24
|
+
*
|
|
25
|
+
* @param locale - The locale resolved from the `[locale]` route segment.
|
|
26
|
+
*/
|
|
27
|
+
const setCachedRequestLocale = (locale) => {
|
|
28
|
+
getRequestLocaleHolder().locale = locale;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { getCachedRequestLocale, setCachedRequestLocale };
|
|
33
|
+
//# sourceMappingURL=requestLocaleCache.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestLocaleCache.mjs","names":[],"sources":["../../../src/server/requestLocaleCache.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { cache } from 'react';\n\n/**\n * Request-scoped holder for the locale provided through {@link setRequestLocale}.\n *\n * next-intl resolves the active locale per request from the `[locale]` route\n * segment, which the app forwards via `setRequestLocale(locale)`. React's\n * `cache()` gives a per-request singleton (the same trick next-intl uses in its\n * own `RequestLocaleCache`), so the value set in the layout/page is readable by\n * the other server APIs (`getLocale`, `getTranslations`, …) during the same\n * render.\n *\n * @see https://github.com/vercel/next.js/discussions/58862\n */\nconst getRequestLocaleHolder = cache((): { locale?: LocalesValues } => ({\n locale: undefined,\n}));\n\n/**\n * Read the locale stored for the current request, or `undefined` when\n * `setRequestLocale` has not been called.\n */\nexport const getCachedRequestLocale = (): LocalesValues | undefined =>\n getRequestLocaleHolder().locale;\n\n/**\n * Store the locale for the current request. Called by `setRequestLocale`.\n *\n * @param locale - The locale resolved from the `[locale]` route segment.\n */\nexport const setCachedRequestLocale = (locale: LocalesValues): void => {\n getRequestLocaleHolder().locale = locale;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAM,yBAAyB,aAAyC,EACtE,QAAQ,OACV,EAAE;;;;;AAMF,MAAa,+BACX,uBAAuB,CAAC,CAAC;;;;;;AAO3B,MAAa,0BAA0B,WAAgC;CACrE,uBAAuB,CAAC,CAAC,SAAS;AACpC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setLocale.mjs","names":[],"sources":["../../../src/server/setLocale.ts"],"sourcesContent":["import { setLocaleInStorageServer } from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { cookies } from 'next/headers.js';\n\n/**\n * Drop-in replacement for next-intl's `setLocale()` server action.\n *\n * Writes the locale to whichever cookie(s) the active `routing.storage`\n * configuration specifies. When `createNextIntlPlugin` is used (the default),\n * this is `NEXT_LOCALE`; when the user has configured a custom storage in\n * `intlayer.config.ts`, that name is used instead.\n *\n * Must be called inside a Server Action.\n *\n * @example\n * ```ts\n * 'use server';\n * await setLocale('fr');\n * ```\n */\nexport const setLocale = async (locale: string): Promise<void> => {\n const cookieStore = await cookies();\n\n setLocaleInStorageServer(locale as LocalesValues, {\n setCookieStore: (name, value, attributes) => {\n cookieStore.set(name, value, {\n ...(attributes ?? {}),\n path: attributes?.path ?? '/',\n sameSite: (attributes?.sameSite as 'lax') ?? 'lax',\n httpOnly: attributes?.httpOnly ?? false,\n secure: attributes?.secure ?? process.env.NODE_ENV === 'production',\n });\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,YAAY,OAAO,WAAkC;CAChE,MAAM,cAAc,MAAM,
|
|
1
|
+
{"version":3,"file":"setLocale.mjs","names":[],"sources":["../../../src/server/setLocale.ts"],"sourcesContent":["import { setLocaleInStorageServer } from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { cookies } from 'next/headers.js';\n\n/**\n * Drop-in replacement for next-intl's `setLocale()` server action.\n *\n * Writes the locale to whichever cookie(s) the active `routing.storage`\n * configuration specifies. When `createNextIntlPlugin` is used (the default),\n * this is `NEXT_LOCALE`; when the user has configured a custom storage in\n * `intlayer.config.ts`, that name is used instead.\n *\n * Must be called inside a Server Action.\n *\n * @example\n * ```ts\n * 'use server';\n * await setLocale('fr');\n * ```\n */\nexport const setLocale = async (locale: string): Promise<void> => {\n const cookieStore = await cookies();\n\n setLocaleInStorageServer(locale as LocalesValues, {\n setCookieStore: (name, value, attributes) => {\n cookieStore.set(name, value, {\n ...(attributes ?? {}),\n path: attributes?.path ?? '/',\n sameSite: (attributes?.sameSite as 'lax') ?? 'lax',\n httpOnly: attributes?.httpOnly ?? false,\n secure: attributes?.secure ?? process.env.NODE_ENV === 'production',\n });\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,YAAY,OAAO,WAAkC;CAChE,MAAM,cAAc,MAAM,QAAQ;CAElC,yBAAyB,QAAyB,EAChD,iBAAiB,MAAM,OAAO,eAAe;EAC3C,YAAY,IAAI,MAAM,OAAO;GAC3B,GAAI,cAAc,CAAC;GACnB,MAAM,YAAY,QAAQ;GAC1B,UAAW,YAAY,YAAsB;GAC7C,UAAU,YAAY,YAAY;GAClC,QAAQ,YAAY,UAAU;EAChC,CAAC;CACH,EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { setCachedRequestLocale } from "./requestLocaleCache.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/server/setRequestLocale.ts
|
|
4
|
+
/**
|
|
5
|
+
* Drop-in for next-intl's `setRequestLocale`.
|
|
6
|
+
*
|
|
7
|
+
* In next-intl this stores the locale (typically the `[locale]` route segment)
|
|
8
|
+
* in a request-scoped cache so the rest of the request can render in that
|
|
9
|
+
* locale and opt into static rendering. The compat keeps the same contract:
|
|
10
|
+
* the locale is stored per-request and read back by `getLocale()` (and, through
|
|
11
|
+
* it, `getTranslations` / `getDictionary` / metadata). This is what makes the
|
|
12
|
+
* per-request locale — and therefore the locale switcher — work without relying
|
|
13
|
+
* on a cookie.
|
|
14
|
+
*
|
|
15
|
+
* @param locale - The locale resolved from the `[locale]` route segment.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* export default async function LocaleLayout({ params }) {
|
|
20
|
+
* const { locale } = await params;
|
|
21
|
+
* setRequestLocale(locale);
|
|
22
|
+
* // …
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
const setRequestLocale = (locale) => {
|
|
27
|
+
setCachedRequestLocale(locale);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { setRequestLocale };
|
|
32
|
+
//# sourceMappingURL=setRequestLocale.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setRequestLocale.mjs","names":[],"sources":["../../../src/server/setRequestLocale.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { setRequestLocale as _setRequestLocale } from 'next-intl/server';\nimport { setCachedRequestLocale } from './requestLocaleCache';\n\n/**\n * Drop-in for next-intl's `setRequestLocale`.\n *\n * In next-intl this stores the locale (typically the `[locale]` route segment)\n * in a request-scoped cache so the rest of the request can render in that\n * locale and opt into static rendering. The compat keeps the same contract:\n * the locale is stored per-request and read back by `getLocale()` (and, through\n * it, `getTranslations` / `getDictionary` / metadata). This is what makes the\n * per-request locale — and therefore the locale switcher — work without relying\n * on a cookie.\n *\n * @param locale - The locale resolved from the `[locale]` route segment.\n *\n * @example\n * ```ts\n * export default async function LocaleLayout({ params }) {\n * const { locale } = await params;\n * setRequestLocale(locale);\n * // …\n * }\n * ```\n */\nexport const setRequestLocale: typeof _setRequestLocale = (locale): void => {\n setCachedRequestLocale(locale as LocalesValues);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,oBAA8C,WAAiB;CAC1E,uBAAuB,MAAuB;AAChD"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
2
|
import { NextIntlClientProvider as NextIntlClientProvider$1 } from "next-intl";
|
|
3
3
|
import { ComponentProps } from "react";
|
|
4
|
-
|
|
5
4
|
//#region src/client/NextIntlClientProvider.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Drop-in for next-intl's `NextIntlClientProvider`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NextIntlClientProvider.d.ts","names":[],"sources":["../../../src/client/NextIntlClientProvider.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"NextIntlClientProvider.d.ts","names":[],"sources":["../../../src/client/NextIntlClientProvider.tsx"],"mappings":";;;;;;;;;cAiBa,+BAA+B;;;;KAsDhC,8BAA8B,KACxC,sBAAsB;;;;;EAOtB;;;;EAIA,QAAQ"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { NextIntlClientProvider, NextIntlClientProviderProps } from "./NextIntlClientProvider.js";
|
|
2
|
-
import { IntlProvider, useExtracted, useFormatter, useMessages, useNow, useTimeZone } from "./helpers.js";
|
|
3
|
-
import { useDictionary } from "../useDictionary.js";
|
|
4
|
-
import { useDictionaryDynamic } from "../useDictionaryDynamic.js";
|
|
5
2
|
import { useLocale } from "./useLocale.js";
|
|
6
|
-
import { useTranslations } from "
|
|
3
|
+
import { IntlProvider, _useExtracted as useExtracted, useDictionary, useDictionaryDynamic, useFormatter, useMessages, useNow, useTimeZone, useTranslations } from "@intlayer/use-intl";
|
|
7
4
|
export { IntlProvider, NextIntlClientProvider, type NextIntlClientProviderProps, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;;;;cAQa,kBAAkB"}
|
|
@@ -1,23 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DictionaryKeys, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
|
+
import { ScopedTranslateFunction, TranslateFunction } from "@intlayer/use-intl";
|
|
2
3
|
import { Dictionary } from "@intlayer/types/dictionary";
|
|
3
|
-
|
|
4
4
|
//#region src/getDictionary.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Overload set for {@link getDictionary}: a string rest argument is the
|
|
7
|
+
* key-prefix remainder of a nested namespace (relative dot-paths under the
|
|
8
|
+
* scope); otherwise the translator is typed against the dictionary's
|
|
9
|
+
* dot-paths.
|
|
10
|
+
*/
|
|
11
|
+
type GetDictionary = {
|
|
12
|
+
<T extends Dictionary, Prefix extends string>(dictionary: T, namespacePrefix: Prefix): Promise<ScopedTranslateFunction<T['key'] & DictionaryKeys, Prefix>>;
|
|
13
|
+
<T extends Dictionary>(dictionary: T, options?: {
|
|
14
|
+
locale?: LocalesValues;
|
|
15
|
+
}): Promise<TranslateFunction<T['key'] & DictionaryKeys>>;
|
|
16
|
+
};
|
|
5
17
|
/**
|
|
6
18
|
* Dictionary-accepting variant of `getTranslations`.
|
|
7
19
|
*
|
|
8
|
-
* Used internally by the
|
|
9
|
-
* at runtime by key, the
|
|
10
|
-
* and passes it directly here. This enables tree-shaking of
|
|
20
|
+
* Used internally by the build-time optimization: instead of looking up the
|
|
21
|
+
* dictionary at runtime by key, the babel/swc plugin pre-imports the dictionary
|
|
22
|
+
* JSON at build time and passes it directly here. This enables tree-shaking of
|
|
23
|
+
* unused locale content.
|
|
11
24
|
*
|
|
12
|
-
* Runs on the server, where next-intl apps do not mount an
|
|
13
|
-
* The request locale therefore cannot be read from a
|
|
14
|
-
* asynchronously from the cookie/header via
|
|
15
|
-
*
|
|
25
|
+
* Runs on the server, where next-intl apps do not mount an
|
|
26
|
+
* `IntlayerServerProvider`. The request locale therefore cannot be read from a
|
|
27
|
+
* server context and is resolved asynchronously from the cookie/header via
|
|
28
|
+
* `getLocale()` (or the explicit `{ locale }` of the object overload).
|
|
29
|
+
* `getTranslations` is always awaited, so an async resolver is a drop-in
|
|
30
|
+
* replacement.
|
|
16
31
|
*/
|
|
17
|
-
declare const getDictionary:
|
|
18
|
-
has: <P extends ValidDotPathsFor<any>>(lookup: P) => boolean;
|
|
19
|
-
raw: <P extends ValidDotPathsFor<any>>(lookup: P) => unknown;
|
|
20
|
-
}>;
|
|
32
|
+
declare const getDictionary: GetDictionary;
|
|
21
33
|
//#endregion
|
|
22
34
|
export { getDictionary };
|
|
23
35
|
//# sourceMappingURL=getDictionary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.d.ts","names":[],"sources":["../../src/getDictionary.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDictionary.d.ts","names":[],"sources":["../../src/getDictionary.ts"],"mappings":";;;;;;;;;;KAkCK;GACF,UAAU,YAAY,uBACrB,YAAY,GACZ,iBAAiB,SAChB,QAAQ,wBAAwB,WAAW,gBAAgB;GAC7D,UAAU,YACT,YAAY,GACZ;IAAY,SAAS;MACpB,QAAQ,kBAAkB,WAAW;;;;;;;;;;;;;;;;;cAkB7B,eASP"}
|
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import { StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
2
|
-
import {
|
|
1
|
+
import { DictionaryKeys, StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
2
|
+
import { ScopedTranslateFunction, TranslateFunction } from "@intlayer/use-intl";
|
|
3
3
|
import { Dictionary } from "@intlayer/types/dictionary";
|
|
4
|
-
|
|
5
4
|
//#region src/getDictionaryDynamic.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Overload set for {@link getDictionaryDynamic}: without a prefix the
|
|
7
|
+
* translator is typed against the dictionary's dot-paths; with a prefix the
|
|
8
|
+
* keys are relative dot-paths under that scope.
|
|
9
|
+
*/
|
|
10
|
+
type GetDictionaryDynamic = {
|
|
11
|
+
<T extends Dictionary, K extends DictionaryKeys>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>, key: K): Promise<TranslateFunction<K>>;
|
|
12
|
+
<T extends Dictionary, K extends DictionaryKeys, Prefix extends string>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>, key: K, namespacePrefix: Prefix): Promise<ScopedTranslateFunction<K, Prefix>>;
|
|
13
|
+
};
|
|
6
14
|
/**
|
|
7
15
|
* Dynamic dictionary-accepting variant of `getTranslations`.
|
|
16
|
+
*
|
|
17
|
+
* Counterpart to {@link getDictionary} for dictionaries imported lazily per
|
|
18
|
+
* locale. Used internally by the build-time optimization.
|
|
8
19
|
*/
|
|
9
|
-
declare const getDictionaryDynamic:
|
|
10
|
-
has: <P extends ValidDotPathsFor<any>>(lookup: P) => boolean;
|
|
11
|
-
raw: <P extends ValidDotPathsFor<any>>(lookup: P) => unknown;
|
|
12
|
-
}>;
|
|
20
|
+
declare const getDictionaryDynamic: GetDictionaryDynamic;
|
|
13
21
|
//#endregion
|
|
14
22
|
export { getDictionaryDynamic };
|
|
15
23
|
//# sourceMappingURL=getDictionaryDynamic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionaryDynamic.d.ts","names":[],"sources":["../../src/getDictionaryDynamic.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDictionaryDynamic.d.ts","names":[],"sources":["../../src/getDictionaryDynamic.ts"],"mappings":";;;;;;;;;KAmBK;GACF,UAAU,YAAY,UAAU,gBAC/B,mBAAmB,0BAA0B,QAAQ,KACrD,KAAK,IACJ,QAAQ,kBAAkB;GAC5B,UAAU,YAAY,UAAU,gBAAgB,uBAC/C,mBAAmB,0BAA0B,QAAQ,KACrD,KAAK,GACL,iBAAiB,SAChB,QAAQ,wBAAwB,GAAG;;;;;;;;cAS3B,sBAYP"}
|