@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/types/index.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { NextIntlClientProvider, NextIntlClientProviderProps } from "./client/NextIntlClientProvider.js";
|
|
2
|
-
import { IntlProvider, useExtracted, useFormatter, useMessages, useNow, useTimeZone } from "./client/helpers.js";
|
|
3
|
-
import { useDictionary } from "./useDictionary.js";
|
|
4
|
-
import { useDictionaryDynamic } from "./useDictionaryDynamic.js";
|
|
5
2
|
import { useLocale } from "./client/useLocale.js";
|
|
6
|
-
import { useTranslations } from "./client/
|
|
7
|
-
import { hasLocale } from "./hasLocale.js";
|
|
3
|
+
import { IntlProvider, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useMessages, useNow, useTimeZone, useTranslations } from "./client/index.js";
|
|
8
4
|
import { Routing, defineRouting } from "./routing.js";
|
|
9
|
-
|
|
5
|
+
import { IntlError, IntlErrorCode, createFormatter, createTranslator, hasLocale, initializeConfig } from "@intlayer/use-intl";
|
|
6
|
+
export { IntlError, IntlErrorCode, IntlProvider, NextIntlClientProvider, type NextIntlClientProviderProps, type Routing, createFormatter, createTranslator, defineRouting, hasLocale, initializeConfig, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","names":[],"sources":["../../src/middleware.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","names":[],"sources":["../../src/middleware.ts"],"mappings":";;;;;;;;;;;;;;;;;cAmBa,yBAAyB"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { NextIntlHref } from "./localizeHref.js";
|
|
2
|
-
import * as _$react from "react";
|
|
3
2
|
import { ComponentPropsWithoutRef } from "react";
|
|
4
|
-
import * as _$next_link0 from "next/link";
|
|
5
3
|
import NextLink from "next/link";
|
|
6
|
-
|
|
7
4
|
//#region src/navigation/Link.d.ts
|
|
8
5
|
/**
|
|
9
6
|
* Props for the compat `Link`: identical to `next/link` except `href` accepts a
|
|
@@ -18,12 +15,12 @@ type LinkProps = Omit<ComponentPropsWithoutRef<typeof NextLink>, 'href' | 'local
|
|
|
18
15
|
* `href` with the active locale (or the `locale` prop) before delegating to
|
|
19
16
|
* `next/link`.
|
|
20
17
|
*/
|
|
21
|
-
declare const Link:
|
|
18
|
+
declare const Link: import("react").ForwardRefExoticComponent<Omit<Omit<Omit<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, keyof import("next/link").LinkProps<any>> & import("next/link").LinkProps<any> & {
|
|
22
19
|
children?: React.ReactNode | undefined;
|
|
23
|
-
} &
|
|
20
|
+
} & import("react").RefAttributes<HTMLAnchorElement>, "ref">, "href" | "locale"> & {
|
|
24
21
|
href: NextIntlHref;
|
|
25
22
|
locale?: string;
|
|
26
|
-
} &
|
|
23
|
+
} & import("react").RefAttributes<HTMLAnchorElement>>;
|
|
27
24
|
//#endregion
|
|
28
25
|
export { Link, LinkProps };
|
|
29
26
|
//# sourceMappingURL=Link.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.d.ts","names":[],"sources":["../../../src/navigation/Link.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Link.d.ts","names":[],"sources":["../../../src/navigation/Link.tsx"],"mappings":";;;;;;;;KAWY,YAAY,KACtB,gCAAgC;EAGhC,MAAM;EACN;;;;;;;cAQW,sBAAI,0BAAA,KAAA,KAAA,qBAAA,qBAAA,8CAAA,sCAAA;;;EATT,MAAA;EACG;oBAiBV,cAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNavigation.d.ts","names":[],"sources":["../../../src/navigation/createNavigation.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"createNavigation.d.ts","names":[],"sources":["../../../src/navigation/createNavigation.ts"],"mappings":";;;;;;;;;;;;;;;;cA6Ba,yBAAyB"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { NextIntlHref } from "./localizeHref.js";
|
|
2
|
-
import * as _$next_dist_shared_lib_app_router_context_shared_runtime0 from "next/dist/shared/lib/app-router-context.shared-runtime";
|
|
3
|
-
|
|
4
2
|
//#region src/navigation/hooks.d.ts
|
|
5
3
|
/**
|
|
6
4
|
* Options accepted by the locale-aware router methods: the standard Next.js
|
|
@@ -20,13 +18,13 @@ declare const usePathname: () => string;
|
|
|
20
18
|
* (honouring an optional `locale` option) before navigating.
|
|
21
19
|
*/
|
|
22
20
|
declare const useRouter: () => {
|
|
23
|
-
push: (href: NextIntlHref, options?: NavigateOptions) => void;
|
|
24
|
-
replace: (href: NextIntlHref, options?: NavigateOptions) => void;
|
|
25
|
-
prefetch: (href: NextIntlHref, options?: NavigateOptions) => void;
|
|
26
21
|
back(): void;
|
|
27
22
|
forward(): void;
|
|
28
23
|
refresh(): void;
|
|
29
|
-
experimental_gesturePush?(href: string, options?:
|
|
24
|
+
experimental_gesturePush?(href: string, options?: import("next/dist/shared/lib/app-router-context.shared-runtime").NavigateOptions): void;
|
|
25
|
+
push: (href: NextIntlHref, options?: NavigateOptions) => void;
|
|
26
|
+
replace: (href: NextIntlHref, options?: NavigateOptions) => void;
|
|
27
|
+
prefetch: (href: NextIntlHref, options?: NavigateOptions) => void;
|
|
30
28
|
};
|
|
31
29
|
//#endregion
|
|
32
30
|
export { usePathname, useRouter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","names":[],"sources":["../../../src/navigation/hooks.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","names":[],"sources":["../../../src/navigation/hooks.ts"],"mappings":";;;;;;KAaK;EAAoB;IAAoB;;;;;cAMhC;;;;;;cAeA;;;;;EASI,OAAA,MAAA,cAAY,UAAY;EAKrB,UAAA,MAAA,cAAY,UAAY;EAKvB,WAAA,MAAA,cAAY,UAAY"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localizeHref.d.ts","names":[],"sources":["../../../src/navigation/localizeHref.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"localizeHref.d.ts","names":[],"sources":["../../../src/navigation/localizeHref.ts"],"mappings":";;;;;;KAQY;EAGN;EACA,QAAQ;EACR,SAAS;;;;;;;;;;cAWF,eAAY,MAAU,cAAY"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":";;;;;;;cAiHa,uBAAoB,wBAAsB,aAC3B,eAAkB,QAAQ"}
|
package/dist/types/routing.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.d.ts","names":[],"sources":["../../src/routing.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"routing.d.ts","names":[],"sources":["../../src/routing.ts"],"mappings":";;KAGY;EACV,SAAS;EACT,eAAe;EACf;EACA,YAAY,wBAAwB;;;;;;;;;;;;;;;;;cAkBzB,gBAAgB,SAAS,QAAQ,aAAa"}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { getLocale as getLocale$1 } from "next-intl/server";
|
|
2
|
-
|
|
3
2
|
//#region src/server/getLocale.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Drop-in for next-intl's `getLocale()` server function.
|
|
5
|
+
*
|
|
6
|
+
* Resolution order mirrors next-intl's per-request model:
|
|
7
|
+
*
|
|
8
|
+
* 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`
|
|
9
|
+
* route segment) — the source of truth for URL-driven routing. This is what
|
|
10
|
+
* keeps server-rendered content and the locale switcher in sync with the URL
|
|
11
|
+
* instead of a stale cookie.
|
|
12
|
+
* 2. Otherwise Intlayer's own resolution (cookie / header / Accept-Language),
|
|
13
|
+
* for apps that drive the locale from storage rather than the route.
|
|
6
14
|
*/
|
|
7
15
|
declare const getLocale: typeof getLocale$1;
|
|
8
16
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.d.ts","names":[],"sources":["../../../src/server/getLocale.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getLocale.d.ts","names":[],"sources":["../../../src/server/getLocale.ts"],"mappings":";;;;;;;;;;;;;;cAgBa,kBAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMessages.d.ts","names":[],"sources":["../../../src/server/getMessages.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getMessages.d.ts","names":[],"sources":["../../../src/server/getMessages.ts"],"mappings":";;;;;;;;;;;;;;;;;cAoBa,oBAAoB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getRequestConfig as getRequestConfig$1 } from "next-intl/server";
|
|
2
|
+
//#region src/server/getRequestConfig.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Drop-in for next-intl's `getRequestConfig`.
|
|
5
|
+
*
|
|
6
|
+
* In next-intl this registers the per-request config (locale + messages) read
|
|
7
|
+
* by its own plugin. With intlayer the locale is resolved from routing /
|
|
8
|
+
* storage and messages come from compiled dictionaries, so the returned config
|
|
9
|
+
* is never consumed — this is an identity passthrough kept so existing
|
|
10
|
+
* `i18n/request.ts` files keep resolving and type-checking.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated getRequestConfig has no use case with intlayer. The locale and
|
|
13
|
+
* messages are resolved automatically; the file can be removed.
|
|
14
|
+
*/
|
|
15
|
+
declare const getRequestConfig: typeof getRequestConfig$1;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { getRequestConfig as default, getRequestConfig };
|
|
18
|
+
//# sourceMappingURL=getRequestConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRequestConfig.d.ts","names":[],"sources":["../../../src/server/getRequestConfig.ts"],"mappings":";;;;;;;;;;;;;;cAiBa,yBAAyB"}
|
|
@@ -1,40 +1,15 @@
|
|
|
1
|
-
import { MarkupChunkRenderer, RichChunkRenderer } from "../createTranslator.js";
|
|
2
1
|
import { DictionaryKeys, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
|
-
import {
|
|
4
|
-
import { ValidDotPathsFor } from "@intlayer/core/transpiler";
|
|
5
|
-
|
|
2
|
+
import { LooseTranslateFunction, TranslateFunction, TranslateFunctionForNamespace } from "@intlayer/use-intl";
|
|
6
3
|
//#region src/server/getTranslations.d.ts
|
|
7
4
|
/**
|
|
8
5
|
* Options accepted by the options-object overload of {@link getTranslations}.
|
|
9
6
|
*/
|
|
10
7
|
type GetTranslationsOptions<N extends DictionaryKeys> = {
|
|
11
|
-
/** The dictionary namespace to scope translations to. */
|
|
8
|
+
/** The dictionary namespace to scope translations to. */
|
|
9
|
+
namespace?: N;
|
|
10
|
+
/** Override the locale instead of reading it from the current request. */
|
|
12
11
|
locale?: LocalesValues;
|
|
13
12
|
};
|
|
14
|
-
/**
|
|
15
|
-
* The translation function returned by {@link getTranslations}.
|
|
16
|
-
*
|
|
17
|
-
* Beyond the plain call signature, the function exposes:
|
|
18
|
-
* - `has(key)` — returns `true` when the key exists in the namespace.
|
|
19
|
-
* - `raw(key)` — returns the unprocessed message value.
|
|
20
|
-
* - `rich(key, values)` — resolves `<tag>chunks</tag>` markup to React nodes.
|
|
21
|
-
* - `markup(key, values)` — resolves `<tag>chunks</tag>` markup to a string.
|
|
22
|
-
*/
|
|
23
|
-
type TranslateFunction<N extends DictionaryKeys> = {
|
|
24
|
-
/** Translate a key to a string, with optional ICU interpolation params. */<P extends ValidDotPathsFor<N>>(key: P, params?: Record<string, unknown>): string; /** Returns `true` if the given key exists in the namespace. */
|
|
25
|
-
has<P extends ValidDotPathsFor<N>>(key: P): boolean; /** Returns the raw unprocessed message for the given key. */
|
|
26
|
-
raw<P extends ValidDotPathsFor<N>>(key: P): unknown; /** Resolves rich-text markup, mapping tags through React renderers. */
|
|
27
|
-
rich<P extends ValidDotPathsFor<N>>(key: P, values?: Record<string, RichChunkRenderer | ReactNode>): ReactNode; /** Resolves rich-text markup, mapping tags through string renderers. */
|
|
28
|
-
markup<P extends ValidDotPathsFor<N>>(key: P, values?: Record<string, MarkupChunkRenderer | string | number>): string;
|
|
29
|
-
};
|
|
30
|
-
/** Loosely-typed function returned for nested `'dict.scope'` namespaces. */
|
|
31
|
-
type LooseTranslateFunction = {
|
|
32
|
-
(key: string, params?: Record<string, unknown>): string;
|
|
33
|
-
has(key: string): boolean;
|
|
34
|
-
raw(key: string): unknown;
|
|
35
|
-
rich(key: string, values?: Record<string, RichChunkRenderer | ReactNode>): ReactNode;
|
|
36
|
-
markup(key: string, values?: Record<string, MarkupChunkRenderer | string | number>): string;
|
|
37
|
-
};
|
|
38
13
|
/**
|
|
39
14
|
* Overload set for {@link getTranslations}:
|
|
40
15
|
*
|
|
@@ -42,14 +17,18 @@ type LooseTranslateFunction = {
|
|
|
42
17
|
* 2. An options object `{ namespace?, locale? }` → typed when namespace is
|
|
43
18
|
* a known `DictionaryKeys` value.
|
|
44
19
|
* 3. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative
|
|
45
|
-
*
|
|
20
|
+
* dot-paths under the scope, typed against the dictionary, matching
|
|
21
|
+
* next-intl's scoped-namespace behaviour.
|
|
46
22
|
* 4. No namespace → root scope; the first segment of each key designates
|
|
47
23
|
* the dictionary (`t('about.title')`).
|
|
24
|
+
*
|
|
25
|
+
* The translate function shape (`t`, `t.rich`, `t.markup`, `t.raw`, `t.has`)
|
|
26
|
+
* is shared with `@intlayer/use-intl`.
|
|
48
27
|
*/
|
|
49
28
|
type GetTranslations = {
|
|
50
29
|
<N extends DictionaryKeys>(namespace: N): Promise<TranslateFunction<N>>;
|
|
51
30
|
<N extends DictionaryKeys>(options: GetTranslationsOptions<N>): Promise<TranslateFunction<N>>;
|
|
52
|
-
|
|
31
|
+
<N extends `${string}.${string}`>(namespace: N): Promise<TranslateFunctionForNamespace<N>>;
|
|
53
32
|
(): Promise<LooseTranslateFunction>;
|
|
54
33
|
};
|
|
55
34
|
/**
|
|
@@ -60,8 +39,9 @@ type GetTranslations = {
|
|
|
60
39
|
* arguments (`{value, number}`). Rich text is available through `t.rich()`
|
|
61
40
|
* and `t.markup()`.
|
|
62
41
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
42
|
+
* Resolves the active locale from the current request (or the `locale` option)
|
|
43
|
+
* and delegates to `@intlayer/use-intl`'s `createTranslator`, the same runtime
|
|
44
|
+
* that backs the client `useTranslations`.
|
|
65
45
|
*
|
|
66
46
|
* @example
|
|
67
47
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTranslations.d.ts","names":[],"sources":["../../../src/server/getTranslations.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getTranslations.d.ts","names":[],"sources":["../../../src/server/getTranslations.ts"],"mappings":";;;;;;KAeK,uBAAuB,UAAU;;EAEpC,YAAY;;EAEZ,SAAS;;;;;;;;;;;;;;;;;KAkBN;GACF,UAAU,gBAAgB,WAAW,IAAI,QAAQ,kBAAkB;GACnE,UAAU,gBACT,SAAS,uBAAuB,KAC/B,QAAQ,kBAAkB;GAC5B,iCACC,WAAW,IACV,QAAQ,8BAA8B;MACrC,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+BD,iBAAiB"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getFormatter as getFormatter$1, getNow as getNow$1, getTimeZone as getTimeZone$1 } from "next-intl/server";
|
|
2
|
-
|
|
3
2
|
//#region src/server/helpers.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Drop-in for next-intl's server `getFormatter()`.
|
|
6
|
-
* Returns locale-aware formatters backed by the native `Intl.*` APIs
|
|
5
|
+
* Returns locale-aware formatters backed by the native `Intl.*` APIs,
|
|
6
|
+
* built by `@intlayer/use-intl`'s `createFormatter`.
|
|
7
7
|
*/
|
|
8
8
|
declare const getFormatter: typeof getFormatter$1;
|
|
9
9
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","names":[],"sources":["../../../src/server/helpers.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","names":[],"sources":["../../../src/server/helpers.ts"],"mappings":";;;;;;;cAaa,qBAAqB;;;;;cAWrB,eAAe;;;;;cAOf,oBAAoB"}
|
|
@@ -2,7 +2,9 @@ import { getDictionary } from "../getDictionary.js";
|
|
|
2
2
|
import { getDictionaryDynamic } from "../getDictionaryDynamic.js";
|
|
3
3
|
import { getLocale } from "./getLocale.js";
|
|
4
4
|
import { getMessages } from "./getMessages.js";
|
|
5
|
+
import getRequestConfig from "./getRequestConfig.js";
|
|
5
6
|
import { getTranslations } from "./getTranslations.js";
|
|
6
7
|
import { getFormatter, getNow, getTimeZone } from "./helpers.js";
|
|
7
8
|
import { setLocale } from "./setLocale.js";
|
|
8
|
-
|
|
9
|
+
import { setRequestLocale } from "./setRequestLocale.js";
|
|
10
|
+
export { getDictionary, getDictionaryDynamic, getFormatter, getLocale, getMessages, getNow, getRequestConfig, getTimeZone, getTranslations, setLocale, setRequestLocale };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
|
+
//#region src/server/requestLocaleCache.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Read the locale stored for the current request, or `undefined` when
|
|
5
|
+
* `setRequestLocale` has not been called.
|
|
6
|
+
*/
|
|
7
|
+
declare const getCachedRequestLocale: () => LocalesValues | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Store the locale for the current request. Called by `setRequestLocale`.
|
|
10
|
+
*
|
|
11
|
+
* @param locale - The locale resolved from the `[locale]` route segment.
|
|
12
|
+
*/
|
|
13
|
+
declare const setCachedRequestLocale: (locale: LocalesValues) => void;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getCachedRequestLocale, setCachedRequestLocale };
|
|
16
|
+
//# sourceMappingURL=requestLocaleCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestLocaleCache.d.ts","names":[],"sources":["../../../src/server/requestLocaleCache.ts"],"mappings":";;;;;;cAuBa,8BAA6B;;;;;;cAQ7B,yBAAsB,QAAY"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setLocale.d.ts","names":[],"sources":["../../../src/server/setLocale.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"setLocale.d.ts","names":[],"sources":["../../../src/server/setLocale.ts"],"mappings":";;;;;;;;;;;;;;;;;cAoBa,YAAS,mBAA2B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { setRequestLocale as setRequestLocale$1 } from "next-intl/server";
|
|
2
|
+
//#region src/server/setRequestLocale.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Drop-in for next-intl's `setRequestLocale`.
|
|
5
|
+
*
|
|
6
|
+
* In next-intl this stores the locale (typically the `[locale]` route segment)
|
|
7
|
+
* in a request-scoped cache so the rest of the request can render in that
|
|
8
|
+
* locale and opt into static rendering. The compat keeps the same contract:
|
|
9
|
+
* the locale is stored per-request and read back by `getLocale()` (and, through
|
|
10
|
+
* it, `getTranslations` / `getDictionary` / metadata). This is what makes the
|
|
11
|
+
* per-request locale — and therefore the locale switcher — work without relying
|
|
12
|
+
* on a cookie.
|
|
13
|
+
*
|
|
14
|
+
* @param locale - The locale resolved from the `[locale]` route segment.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* export default async function LocaleLayout({ params }) {
|
|
19
|
+
* const { locale } = await params;
|
|
20
|
+
* setRequestLocale(locale);
|
|
21
|
+
* // …
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare const setRequestLocale: typeof setRequestLocale$1;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { setRequestLocale };
|
|
28
|
+
//# sourceMappingURL=setRequestLocale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setRequestLocale.d.ts","names":[],"sources":["../../../src/server/setRequestLocale.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;cA0Ba,yBAAyB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/next-intl",
|
|
3
|
-
"version": "9.0.0-canary.
|
|
3
|
+
"version": "9.0.0-canary.21",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "next-intl API adapter for intlayer — useTranslations, useLocale, getTranslations, getLocale, NextIntlClientProvider backed by next-intlayer",
|
|
6
6
|
"keywords": [
|
|
@@ -110,25 +110,26 @@
|
|
|
110
110
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
111
111
|
},
|
|
112
112
|
"dependencies": {
|
|
113
|
-
"@intlayer/
|
|
114
|
-
"@intlayer/
|
|
115
|
-
"@intlayer/
|
|
116
|
-
"@intlayer/
|
|
117
|
-
"@intlayer/types": "9.0.0-canary.
|
|
118
|
-
"
|
|
119
|
-
"
|
|
113
|
+
"@intlayer/config": "9.0.0-canary.21",
|
|
114
|
+
"@intlayer/core": "9.0.0-canary.21",
|
|
115
|
+
"@intlayer/dictionaries-entry": "9.0.0-canary.21",
|
|
116
|
+
"@intlayer/engine": "9.0.0-canary.21",
|
|
117
|
+
"@intlayer/types": "9.0.0-canary.21",
|
|
118
|
+
"@intlayer/use-intl": "9.0.0-canary.21",
|
|
119
|
+
"next-intlayer": "9.0.0-canary.21",
|
|
120
|
+
"react-intlayer": "9.0.0-canary.21"
|
|
120
121
|
},
|
|
121
122
|
"devDependencies": {
|
|
122
|
-
"@types/node": "
|
|
123
|
+
"@types/node": "26.1.1",
|
|
123
124
|
"@types/react": "19.2.17",
|
|
124
125
|
"@utils/ts-config": "1.0.4",
|
|
125
126
|
"@utils/ts-config-types": "1.0.4",
|
|
126
127
|
"@utils/tsdown-config": "1.0.4",
|
|
127
|
-
"next-intl": "4.13.
|
|
128
|
+
"next-intl": "4.13.2",
|
|
128
129
|
"rimraf": "6.1.3",
|
|
129
|
-
"tsdown": "0.
|
|
130
|
-
"typescript": "
|
|
131
|
-
"vitest": "4.1.
|
|
130
|
+
"tsdown": "0.22.12",
|
|
131
|
+
"typescript": "7.0.2",
|
|
132
|
+
"vitest": "4.1.10"
|
|
132
133
|
},
|
|
133
134
|
"peerDependencies": {
|
|
134
135
|
"next": ">=14.0.0",
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_createFormatter = require('../createFormatter.cjs');
|
|
6
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
7
|
-
let next_intlayer = require("next-intlayer");
|
|
8
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
-
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
10
|
-
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
11
|
-
|
|
12
|
-
//#region src/client/helpers.tsx
|
|
13
|
-
/**
|
|
14
|
-
* Drop-in for next-intl's `useNow`.
|
|
15
|
-
* Returns the current `Date`. The `updateInterval` option is ignored.
|
|
16
|
-
*/
|
|
17
|
-
const useNow = () => /* @__PURE__ */ new Date();
|
|
18
|
-
/**
|
|
19
|
-
* Drop-in for next-intl's `useTimeZone`.
|
|
20
|
-
* Returns the system time zone resolved from `Intl.DateTimeFormat`.
|
|
21
|
-
*/
|
|
22
|
-
const useTimeZone = () => Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
23
|
-
/**
|
|
24
|
-
* Drop-in for next-intl's `useMessages`.
|
|
25
|
-
*
|
|
26
|
-
* @deprecated useMessages has no use case with intlayer.
|
|
27
|
-
* Messages are loaded automatically under the hood.
|
|
28
|
-
* @returns An empty object.
|
|
29
|
-
*/
|
|
30
|
-
const useMessages = () => {
|
|
31
|
-
if (process.env.NODE_ENV === "development") (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("useMessages", _intlayer_config_colors.CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`);
|
|
32
|
-
return {};
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Drop-in for next-intl's `useFormatter`.
|
|
36
|
-
* Returns locale-aware formatters backed by the native `Intl.*` APIs:
|
|
37
|
-
* `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and
|
|
38
|
-
* `displayName`.
|
|
39
|
-
*/
|
|
40
|
-
const useFormatter = () => {
|
|
41
|
-
const { locale } = (0, next_intlayer.useLocale)();
|
|
42
|
-
return require_createFormatter.createFormatter(locale ?? "en");
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Drop-in for next-intl's `IntlProvider`.
|
|
46
|
-
* Renders children as-is — Intlayer provides its own context via
|
|
47
|
-
* `IntlayerClientProvider`.
|
|
48
|
-
*
|
|
49
|
-
* @deprecated IntlProvider has no use case with intlayer.
|
|
50
|
-
* Use `IntlayerClientProvider` or `NextIntlClientProvider` instead.
|
|
51
|
-
*/
|
|
52
|
-
const IntlProvider = ({ children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children });
|
|
53
|
-
/**
|
|
54
|
-
* @internal Not part of the public next-intl API surface; provided for
|
|
55
|
-
* internal compatibility shims only.
|
|
56
|
-
*/
|
|
57
|
-
const useExtracted = (..._args) => ({});
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
exports.IntlProvider = IntlProvider;
|
|
61
|
-
exports.useExtracted = useExtracted;
|
|
62
|
-
exports.useFormatter = useFormatter;
|
|
63
|
-
exports.useMessages = useMessages;
|
|
64
|
-
exports.useNow = useNow;
|
|
65
|
-
exports.useTimeZone = useTimeZone;
|
|
66
|
-
//# sourceMappingURL=helpers.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs","names":["CYAN","createFormatter"],"sources":["../../../src/client/helpers.tsx"],"sourcesContent":["'use client';\n\nimport { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type {\n IntlProvider as _IntlProvider,\n useFormatter as _useFormatter,\n useMessages as _useMessages,\n useNow as _useNow,\n useTimeZone as _useTimeZone,\n} from 'next-intl';\nimport { useLocale } from 'next-intlayer';\nimport type * as React from 'react';\nimport { createFormatter } from '../createFormatter';\n\n/**\n * Drop-in for next-intl's `useNow`.\n * Returns the current `Date`. The `updateInterval` option is ignored.\n */\nexport const useNow: typeof _useNow = () => new Date();\n\n/**\n * Drop-in for next-intl's `useTimeZone`.\n * Returns the system time zone resolved from `Intl.DateTimeFormat`.\n */\nexport const useTimeZone: typeof _useTimeZone = () =>\n Intl.DateTimeFormat().resolvedOptions().timeZone;\n\n/**\n * Drop-in for next-intl's `useMessages`.\n *\n * @deprecated useMessages has no use case with intlayer.\n * Messages are loaded automatically under the hood.\n * @returns An empty object.\n */\nexport const useMessages: typeof _useMessages = () => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('useMessages', CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return {} as ReturnType<typeof _useMessages>;\n};\n\n/**\n * Drop-in for next-intl's `useFormatter`.\n * Returns locale-aware formatters backed by the native `Intl.*` APIs:\n * `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and\n * `displayName`.\n */\nexport const useFormatter: typeof _useFormatter = () => {\n const { locale } = useLocale();\n return createFormatter((locale as string) ?? 'en');\n};\n\ninterface ProviderProps {\n children?: React.ReactNode;\n [key: string]: unknown;\n}\n\n/**\n * Drop-in for next-intl's `IntlProvider`.\n * Renders children as-is — Intlayer provides its own context via\n * `IntlayerClientProvider`.\n *\n * @deprecated IntlProvider has no use case with intlayer.\n * Use `IntlayerClientProvider` or `NextIntlClientProvider` instead.\n */\nexport const IntlProvider: typeof _IntlProvider = ({\n children,\n}: ProviderProps) => <>{children}</>;\n\n/**\n * @internal Not part of the public next-intl API surface; provided for\n * internal compatibility shims only.\n */\nexport const useExtracted = (..._args: unknown[]) => ({});\n"],"mappings":";;;;;;;;;;;;;;;;AAoBA,MAAa,+BAA+B,IAAI,MAAM;;;;;AAMtD,MAAa,oBACX,KAAK,gBAAgB,CAAC,iBAAiB,CAAC;;;;;;;;AAS1C,MAAa,oBAAyC;AACpD,KAAI,QAAQ,IAAI,aAAa,cAE3B,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,eAAeA,6BAAK,CAAC,iHAClC;AAGH,QAAO,EAAE;;;;;;;;AASX,MAAa,qBAA2C;CACtD,MAAM,EAAE,yCAAsB;AAC9B,QAAOC,wCAAiB,UAAqB,KAAK;;;;;;;;;;AAgBpD,MAAa,gBAAsC,EACjD,eACmB,yEAAG,UAAY;;;;;AAMpC,MAAa,gBAAgB,GAAG,WAAsB,EAAE"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
const require_createTranslator = require('../createTranslator.cjs');
|
|
6
|
-
let next_intlayer = require("next-intlayer");
|
|
7
|
-
let react = require("react");
|
|
8
|
-
|
|
9
|
-
//#region src/client/useTranslations.ts
|
|
10
|
-
/**
|
|
11
|
-
* Drop-in for next-intl's `useTranslations`.
|
|
12
|
-
*
|
|
13
|
-
* Messages support ICU MessageFormat syntax: simple arguments (`{name}`),
|
|
14
|
-
* plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted
|
|
15
|
-
* arguments (`{value, number}`). Rich text is available through `t.rich()`
|
|
16
|
-
* and `t.markup()`.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```tsx
|
|
20
|
-
* const t = useTranslations('about');
|
|
21
|
-
* t('counter.label'); // ✓ typed
|
|
22
|
-
* t('items', { count: 3 }); // ICU plural
|
|
23
|
-
*
|
|
24
|
-
* // Scoped to a nested object (next-intl idiom)
|
|
25
|
-
* const t = useTranslations('about.counter');
|
|
26
|
-
* t('label'); // resolves about → counter.label
|
|
27
|
-
*
|
|
28
|
-
* // Rich text
|
|
29
|
-
* t.rich('terms', { link: (chunks) => <a href="/terms">{chunks}</a> });
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
const useTranslations = ((namespace) => {
|
|
33
|
-
const { locale: currentLocale } = (0, react.useContext)(next_intlayer.IntlayerClientContext) ?? {};
|
|
34
|
-
return (0, react.useMemo)(() => require_createTranslator.createTranslator(currentLocale, namespace), [currentLocale, namespace]);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
exports.useTranslations = useTranslations;
|
|
39
|
-
//# sourceMappingURL=useTranslations.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslations.cjs","names":["IntlayerClientContext","createTranslator"],"sources":["../../../src/client/useTranslations.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerClientContext } from 'next-intlayer';\nimport { type ReactNode, useContext, useMemo } from 'react';\nimport {\n createTranslator,\n type MarkupChunkRenderer,\n type RichChunkRenderer,\n} from '../createTranslator';\n\n/**\n * The translation function returned by {@link useTranslations}.\n *\n * When the namespace is a bare dictionary key, `key` is validated against the\n * dictionary's dot-paths. When the namespace is a nested scope\n * (`'about.counter'`), `key` is a relative `string` path.\n *\n * Beyond the call signature, the function exposes:\n * - `has(key)` — returns `true` when the key exists in the namespace.\n * - `raw(key)` — returns the unprocessed content value.\n * - `rich(key, values)` — resolves `<tag>chunks</tag>` markup to React nodes.\n * - `markup(key, values)` — resolves `<tag>chunks</tag>` markup to a string.\n */\ntype TranslateFunction<N extends DictionaryKeys> = {\n /** Translate a key to a string, with optional ICU interpolation params. */\n <P extends ValidDotPathsFor<N>>(\n key: P,\n params?: Record<string, unknown>\n ): string;\n /** Returns `true` if the given key exists in the namespace. */\n has<P extends ValidDotPathsFor<N>>(key: P): boolean;\n /** Returns the raw unprocessed content for the given key. */\n raw<P extends ValidDotPathsFor<N>>(key: P): unknown;\n /** Resolves rich-text markup, mapping tags through React renderers. */\n rich<P extends ValidDotPathsFor<N>>(\n key: P,\n values?: Record<string, RichChunkRenderer | ReactNode>\n ): ReactNode;\n /** Resolves rich-text markup, mapping tags through string renderers. */\n markup<P extends ValidDotPathsFor<N>>(\n key: P,\n values?: Record<string, MarkupChunkRenderer | string | number>\n ): string;\n};\n\n/** Loosely-typed function returned for nested `'dict.scope'` namespaces. */\ntype LooseTranslateFunction = {\n (key: string, params?: Record<string, unknown>): string;\n has(key: string): boolean;\n raw(key: string): unknown;\n rich(\n key: string,\n values?: Record<string, RichChunkRenderer | ReactNode>\n ): ReactNode;\n markup(\n key: string,\n values?: Record<string, MarkupChunkRenderer | string | number>\n ): string;\n};\n\n/**\n * Overload set for {@link useTranslations}:\n *\n * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).\n * 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative\n * `string` paths, matching next-intl's scoped-namespace behaviour.\n * 3. No namespace → root scope; the first segment of each key designates\n * the dictionary (`t('about.title')`).\n */\ntype UseTranslations = {\n <N extends DictionaryKeys>(namespace: N): TranslateFunction<N>;\n (namespace: `${string}.${string}`): LooseTranslateFunction;\n (): LooseTranslateFunction;\n};\n\n/**\n * Drop-in for next-intl's `useTranslations`.\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 * @example\n * ```tsx\n * const t = useTranslations('about');\n * t('counter.label'); // ✓ typed\n * t('items', { count: 3 }); // ICU plural\n *\n * // Scoped to a nested object (next-intl idiom)\n * const t = useTranslations('about.counter');\n * t('label'); // resolves about → counter.label\n *\n * // Rich text\n * t.rich('terms', { link: (chunks) => <a href=\"/terms\">{chunks}</a> });\n * ```\n */\nexport const useTranslations = ((namespace?: string) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n return useMemo(\n () => createTranslator(currentLocale as LocalesValues, namespace),\n [currentLocale, namespace]\n );\n}) as UseTranslations;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,MAAa,oBAAoB,cAAuB;CACtD,MAAM,EAAE,QAAQ,wCAA6BA,oCAAsB,IAAI,EAAE;AAEzE,iCACQC,0CAAiB,eAAgC,UAAU,EACjE,CAAC,eAAe,UAAU,CAC3B"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
3
|
-
//#region src/createFormatter.ts
|
|
4
|
-
/** Time units orderable by their duration in seconds. */
|
|
5
|
-
const RELATIVE_TIME_UNITS = [
|
|
6
|
-
["year", 31536e3],
|
|
7
|
-
["month", 2628e3],
|
|
8
|
-
["week", 604800],
|
|
9
|
-
["day", 86400],
|
|
10
|
-
["hour", 3600],
|
|
11
|
-
["minute", 60],
|
|
12
|
-
["second", 1]
|
|
13
|
-
];
|
|
14
|
-
const toDate = (value) => value instanceof Date ? value : new Date(value);
|
|
15
|
-
/**
|
|
16
|
-
* Builds a next-intl compatible formatter backed by the native `Intl.*`
|
|
17
|
-
* APIs for the given locale.
|
|
18
|
-
*
|
|
19
|
-
* Shared by `useFormatter` (client) and `getFormatter` (server).
|
|
20
|
-
*/
|
|
21
|
-
const createFormatter = (locale) => ({
|
|
22
|
-
dateTime: (value, options) => new Intl.DateTimeFormat(locale, options).format(value),
|
|
23
|
-
number: (value, options) => new Intl.NumberFormat(locale, options).format(value),
|
|
24
|
-
/** Formats a date range with `Intl.DateTimeFormat#formatRange`. */
|
|
25
|
-
dateTimeRange: (start, end, options) => new Intl.DateTimeFormat(locale, options).formatRange(toDate(start), toDate(end)),
|
|
26
|
-
/**
|
|
27
|
-
* Formats a date relative to now (or a reference date), automatically
|
|
28
|
-
* selecting the largest fitting unit.
|
|
29
|
-
*/
|
|
30
|
-
relativeTime: (date, nowOrOptions) => {
|
|
31
|
-
const options = nowOrOptions instanceof Date || typeof nowOrOptions === "number" ? { now: nowOrOptions } : nowOrOptions ?? {};
|
|
32
|
-
const nowDate = options.now !== void 0 ? toDate(options.now) : /* @__PURE__ */ new Date();
|
|
33
|
-
const diffInSeconds = (toDate(date).getTime() - nowDate.getTime()) / 1e3;
|
|
34
|
-
let unit = options.unit;
|
|
35
|
-
if (!unit) {
|
|
36
|
-
const absoluteDiff = Math.abs(diffInSeconds);
|
|
37
|
-
unit = RELATIVE_TIME_UNITS.find(([, unitSeconds]) => absoluteDiff >= unitSeconds)?.[0] ?? "second";
|
|
38
|
-
}
|
|
39
|
-
const unitSeconds = RELATIVE_TIME_UNITS.find(([unitName]) => unitName === unit)?.[1] ?? 1;
|
|
40
|
-
return new Intl.RelativeTimeFormat(locale, {
|
|
41
|
-
numeric: "auto",
|
|
42
|
-
style: options.style
|
|
43
|
-
}).format(Math.round(diffInSeconds / unitSeconds), unit);
|
|
44
|
-
},
|
|
45
|
-
/** Formats a list with `Intl.ListFormat`. */
|
|
46
|
-
list: (value, options) => new Intl.ListFormat(locale, options).format(value),
|
|
47
|
-
displayName: (value, optionsOrFormat, extraOptions) => {
|
|
48
|
-
const resolvedOptions = typeof optionsOrFormat === "string" ? extraOptions : optionsOrFormat;
|
|
49
|
-
try {
|
|
50
|
-
return new Intl.DisplayNames([locale], resolvedOptions ?? { type: "language" }).of(value) ?? value;
|
|
51
|
-
} catch {
|
|
52
|
-
return value;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
exports.createFormatter = createFormatter;
|
|
59
|
-
//# sourceMappingURL=createFormatter.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createFormatter.cjs","names":[],"sources":["../../src/createFormatter.ts"],"sourcesContent":["import type { useFormatter as _useFormatter } from 'next-intl';\n\n/** The formatter object shape exposed by next-intl. */\nexport type Formatter = ReturnType<typeof _useFormatter>;\n\n/** Time units orderable by their duration in seconds. */\nconst RELATIVE_TIME_UNITS: [Intl.RelativeTimeFormatUnit, number][] = [\n ['year', 31536000],\n ['month', 2628000],\n ['week', 604800],\n ['day', 86400],\n ['hour', 3600],\n ['minute', 60],\n ['second', 1],\n];\n\nconst toDate = (value: Date | number | string): Date =>\n value instanceof Date ? value : new Date(value);\n\n/**\n * Builds a next-intl compatible formatter backed by the native `Intl.*`\n * APIs for the given locale.\n *\n * Shared by `useFormatter` (client) and `getFormatter` (server).\n */\nexport const createFormatter = (locale: string): Formatter =>\n ({\n dateTime: (value: Date | number, options?: Intl.DateTimeFormatOptions) =>\n new Intl.DateTimeFormat(locale, options).format(value),\n\n number: (value: number | bigint, options?: Intl.NumberFormatOptions) =>\n new Intl.NumberFormat(locale, options).format(value),\n\n /** Formats a date range with `Intl.DateTimeFormat#formatRange`. */\n dateTimeRange: (\n start: Date | number,\n end: Date | number,\n options?: Intl.DateTimeFormatOptions\n ) =>\n new Intl.DateTimeFormat(locale, options).formatRange(\n toDate(start),\n toDate(end)\n ),\n\n /**\n * Formats a date relative to now (or a reference date), automatically\n * selecting the largest fitting unit.\n */\n relativeTime: (\n date: Date | number | string,\n nowOrOptions?:\n | Date\n | number\n | {\n now?: Date | number;\n unit?: Intl.RelativeTimeFormatUnit;\n style?: Intl.RelativeTimeFormatStyle;\n numberingSystem?: string;\n }\n ) => {\n const options =\n nowOrOptions instanceof Date || typeof nowOrOptions === 'number'\n ? { now: nowOrOptions }\n : (nowOrOptions ?? {});\n\n const nowDate =\n options.now !== undefined ? toDate(options.now) : new Date();\n const diffInSeconds = (toDate(date).getTime() - nowDate.getTime()) / 1000;\n\n let unit = options.unit;\n if (!unit) {\n const absoluteDiff = Math.abs(diffInSeconds);\n unit =\n RELATIVE_TIME_UNITS.find(\n ([, unitSeconds]) => absoluteDiff >= unitSeconds\n )?.[0] ?? 'second';\n }\n\n const unitSeconds =\n RELATIVE_TIME_UNITS.find(([unitName]) => unitName === unit)?.[1] ?? 1;\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto',\n style: options.style,\n }).format(Math.round(diffInSeconds / unitSeconds), unit);\n },\n\n /** Formats a list with `Intl.ListFormat`. */\n list: (value: Iterable<string>, options?: Intl.ListFormatOptions): string =>\n new Intl.ListFormat(locale, options).format(value),\n\n displayName: (\n value: string,\n optionsOrFormat?: Intl.DisplayNamesOptions | string,\n extraOptions?: Intl.DisplayNamesOptions\n ): string => {\n const resolvedOptions =\n typeof optionsOrFormat === 'string' ? extraOptions : optionsOrFormat;\n try {\n return (\n new Intl.DisplayNames(\n [locale],\n resolvedOptions ?? { type: 'language' }\n ).of(value) ?? value\n );\n } catch {\n return value;\n }\n },\n }) as unknown as Formatter;\n"],"mappings":";;;;AAMA,MAAM,sBAA+D;CACnE,CAAC,QAAQ,QAAS;CAClB,CAAC,SAAS,OAAQ;CAClB,CAAC,QAAQ,OAAO;CAChB,CAAC,OAAO,MAAM;CACd,CAAC,QAAQ,KAAK;CACd,CAAC,UAAU,GAAG;CACd,CAAC,UAAU,EAAE;CACd;AAED,MAAM,UAAU,UACd,iBAAiB,OAAO,QAAQ,IAAI,KAAK,MAAM;;;;;;;AAQjD,MAAa,mBAAmB,YAC7B;CACC,WAAW,OAAsB,YAC/B,IAAI,KAAK,eAAe,QAAQ,QAAQ,CAAC,OAAO,MAAM;CAExD,SAAS,OAAwB,YAC/B,IAAI,KAAK,aAAa,QAAQ,QAAQ,CAAC,OAAO,MAAM;;CAGtD,gBACE,OACA,KACA,YAEA,IAAI,KAAK,eAAe,QAAQ,QAAQ,CAAC,YACvC,OAAO,MAAM,EACb,OAAO,IAAI,CACZ;;;;;CAMH,eACE,MACA,iBASG;EACH,MAAM,UACJ,wBAAwB,QAAQ,OAAO,iBAAiB,WACpD,EAAE,KAAK,cAAc,GACpB,gBAAgB,EAAE;EAEzB,MAAM,UACJ,QAAQ,QAAQ,SAAY,OAAO,QAAQ,IAAI,mBAAG,IAAI,MAAM;EAC9D,MAAM,iBAAiB,OAAO,KAAK,CAAC,SAAS,GAAG,QAAQ,SAAS,IAAI;EAErE,IAAI,OAAO,QAAQ;AACnB,MAAI,CAAC,MAAM;GACT,MAAM,eAAe,KAAK,IAAI,cAAc;AAC5C,UACE,oBAAoB,MACjB,GAAG,iBAAiB,gBAAgB,YACtC,GAAG,MAAM;;EAGd,MAAM,cACJ,oBAAoB,MAAM,CAAC,cAAc,aAAa,KAAK,GAAG,MAAM;AAEtE,SAAO,IAAI,KAAK,mBAAmB,QAAQ;GACzC,SAAS;GACT,OAAO,QAAQ;GAChB,CAAC,CAAC,OAAO,KAAK,MAAM,gBAAgB,YAAY,EAAE,KAAK;;;CAI1D,OAAO,OAAyB,YAC9B,IAAI,KAAK,WAAW,QAAQ,QAAQ,CAAC,OAAO,MAAM;CAEpD,cACE,OACA,iBACA,iBACW;EACX,MAAM,kBACJ,OAAO,oBAAoB,WAAW,eAAe;AACvD,MAAI;AACF,UACE,IAAI,KAAK,aACP,CAAC,OAAO,EACR,mBAAmB,EAAE,MAAM,YAAY,CACxC,CAAC,GAAG,MAAM,IAAI;UAEX;AACN,UAAO;;;CAGZ"}
|