remix-intlayer 9.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +331 -0
- package/dist/cjs/IntlayerProvider.cjs +36 -0
- package/dist/cjs/IntlayerProvider.cjs.map +1 -0
- package/dist/cjs/context.cjs +23 -0
- package/dist/cjs/context.cjs.map +1 -0
- package/dist/cjs/format/index.cjs +20 -0
- package/dist/cjs/format/useCompact.cjs +18 -0
- package/dist/cjs/format/useCompact.cjs.map +1 -0
- package/dist/cjs/format/useCurrency.cjs +18 -0
- package/dist/cjs/format/useCurrency.cjs.map +1 -0
- package/dist/cjs/format/useDate.cjs +27 -0
- package/dist/cjs/format/useDate.cjs.map +1 -0
- package/dist/cjs/format/useIntl.cjs +24 -0
- package/dist/cjs/format/useIntl.cjs.map +1 -0
- package/dist/cjs/format/useList.cjs +18 -0
- package/dist/cjs/format/useList.cjs.map +1 -0
- package/dist/cjs/format/useNumber.cjs +21 -0
- package/dist/cjs/format/useNumber.cjs.map +1 -0
- package/dist/cjs/format/usePercentage.cjs +18 -0
- package/dist/cjs/format/usePercentage.cjs.map +1 -0
- package/dist/cjs/format/useRelativeTime.cjs +18 -0
- package/dist/cjs/format/useRelativeTime.cjs.map +1 -0
- package/dist/cjs/format/useUnit.cjs +18 -0
- package/dist/cjs/format/useUnit.cjs.map +1 -0
- package/dist/cjs/html/index.cjs +33 -0
- package/dist/cjs/index.cjs +17 -0
- package/dist/cjs/localeRouting.cjs +211 -0
- package/dist/cjs/localeRouting.cjs.map +1 -0
- package/dist/cjs/markdown/index.cjs +45 -0
- package/dist/cjs/middleware.cjs +92 -0
- package/dist/cjs/middleware.cjs.map +1 -0
- package/dist/cjs/persistLocale.cjs +51 -0
- package/dist/cjs/persistLocale.cjs.map +1 -0
- package/dist/cjs/requestStorage.cjs +25 -0
- package/dist/cjs/requestStorage.cjs.map +1 -0
- package/dist/cjs/resolveLocale.cjs +21 -0
- package/dist/cjs/resolveLocale.cjs.map +1 -0
- package/dist/cjs/useDictionary.cjs +33 -0
- package/dist/cjs/useDictionary.cjs.map +1 -0
- package/dist/cjs/useIntlayer.cjs +31 -0
- package/dist/cjs/useIntlayer.cjs.map +1 -0
- package/dist/cjs/useLocale.cjs +33 -0
- package/dist/cjs/useLocale.cjs.map +1 -0
- package/dist/esm/IntlayerProvider.mjs +35 -0
- package/dist/esm/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/context.mjs +21 -0
- package/dist/esm/context.mjs.map +1 -0
- package/dist/esm/format/index.mjs +11 -0
- package/dist/esm/format/useCompact.mjs +17 -0
- package/dist/esm/format/useCompact.mjs.map +1 -0
- package/dist/esm/format/useCurrency.mjs +17 -0
- package/dist/esm/format/useCurrency.mjs.map +1 -0
- package/dist/esm/format/useDate.mjs +26 -0
- package/dist/esm/format/useDate.mjs.map +1 -0
- package/dist/esm/format/useIntl.mjs +23 -0
- package/dist/esm/format/useIntl.mjs.map +1 -0
- package/dist/esm/format/useList.mjs +17 -0
- package/dist/esm/format/useList.mjs.map +1 -0
- package/dist/esm/format/useNumber.mjs +20 -0
- package/dist/esm/format/useNumber.mjs.map +1 -0
- package/dist/esm/format/usePercentage.mjs +17 -0
- package/dist/esm/format/usePercentage.mjs.map +1 -0
- package/dist/esm/format/useRelativeTime.mjs +17 -0
- package/dist/esm/format/useRelativeTime.mjs.map +1 -0
- package/dist/esm/format/useUnit.mjs +17 -0
- package/dist/esm/format/useUnit.mjs.map +1 -0
- package/dist/esm/html/index.mjs +3 -0
- package/dist/esm/index.mjs +9 -0
- package/dist/esm/localeRouting.mjs +210 -0
- package/dist/esm/localeRouting.mjs.map +1 -0
- package/dist/esm/markdown/index.mjs +3 -0
- package/dist/esm/middleware.mjs +91 -0
- package/dist/esm/middleware.mjs.map +1 -0
- package/dist/esm/persistLocale.mjs +49 -0
- package/dist/esm/persistLocale.mjs.map +1 -0
- package/dist/esm/requestStorage.mjs +22 -0
- package/dist/esm/requestStorage.mjs.map +1 -0
- package/dist/esm/resolveLocale.mjs +20 -0
- package/dist/esm/resolveLocale.mjs.map +1 -0
- package/dist/esm/useDictionary.mjs +32 -0
- package/dist/esm/useDictionary.mjs.map +1 -0
- package/dist/esm/useIntlayer.mjs +30 -0
- package/dist/esm/useIntlayer.mjs.map +1 -0
- package/dist/esm/useLocale.mjs +32 -0
- package/dist/esm/useLocale.mjs.map +1 -0
- package/dist/types/IntlayerProvider.d.ts +39 -0
- package/dist/types/IntlayerProvider.d.ts.map +1 -0
- package/dist/types/context.d.ts +31 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/format/index.d.ts +10 -0
- package/dist/types/format/useCompact.d.ts +5 -0
- package/dist/types/format/useCompact.d.ts.map +1 -0
- package/dist/types/format/useCurrency.d.ts +5 -0
- package/dist/types/format/useCurrency.d.ts.map +1 -0
- package/dist/types/format/useDate.d.ts +8 -0
- package/dist/types/format/useDate.d.ts.map +1 -0
- package/dist/types/format/useIntl.d.ts +15 -0
- package/dist/types/format/useIntl.d.ts.map +1 -0
- package/dist/types/format/useList.d.ts +5 -0
- package/dist/types/format/useList.d.ts.map +1 -0
- package/dist/types/format/useNumber.d.ts +8 -0
- package/dist/types/format/useNumber.d.ts.map +1 -0
- package/dist/types/format/usePercentage.d.ts +5 -0
- package/dist/types/format/usePercentage.d.ts.map +1 -0
- package/dist/types/format/useRelativeTime.d.ts +5 -0
- package/dist/types/format/useRelativeTime.d.ts.map +1 -0
- package/dist/types/format/useUnit.d.ts +5 -0
- package/dist/types/format/useUnit.d.ts.map +1 -0
- package/dist/types/html/index.d.ts +2 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/localeRouting.d.ts +75 -0
- package/dist/types/localeRouting.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +2 -0
- package/dist/types/middleware.d.ts +49 -0
- package/dist/types/middleware.d.ts.map +1 -0
- package/dist/types/persistLocale.d.ts +16 -0
- package/dist/types/persistLocale.d.ts.map +1 -0
- package/dist/types/requestStorage.d.ts +21 -0
- package/dist/types/requestStorage.d.ts.map +1 -0
- package/dist/types/resolveLocale.d.ts +16 -0
- package/dist/types/resolveLocale.d.ts.map +1 -0
- package/dist/types/useDictionary.d.ts +24 -0
- package/dist/types/useDictionary.d.ts.map +1 -0
- package/dist/types/useIntlayer.d.ts +21 -0
- package/dist/types/useIntlayer.d.ts.map +1 -0
- package/dist/types/useLocale.d.ts +25 -0
- package/dist/types/useLocale.d.ts.map +1 -0
- package/package.json +129 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DeclaredLocales } from "@intlayer/types/module_augmentation";
|
|
2
|
+
//#region src/context.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Intlayer state attached to the Remix `RequestContext` by the {@link intlayer} middleware.
|
|
5
|
+
*/
|
|
6
|
+
export type IntlayerState = {
|
|
7
|
+
/** Locale resolved for the current request. */
|
|
8
|
+
locale: DeclaredLocales;
|
|
9
|
+
/** Locale configured as fallback in `intlayer.config.ts`. */
|
|
10
|
+
defaultLocale: DeclaredLocales;
|
|
11
|
+
/** Every locale declared in `intlayer.config.ts`. */
|
|
12
|
+
availableLocales: DeclaredLocales[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Request-context key holding the {@link IntlayerState} of the current request.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* router.get('/', (context) => Response.json({ locale: context.get(Intlayer).locale }));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const Intlayer: {
|
|
23
|
+
defaultValue?: IntlayerState;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Name of the direct property installed on the request context by the middleware,
|
|
27
|
+
* so `context.intlayer` mirrors `context.get(Intlayer)`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const INTLAYER_CONTEXT_PROPERTY = "intlayer";
|
|
30
|
+
//#endregion
|
|
31
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","names":[],"sources":["../../src/context.ts"],"mappings":";;;;;YAMY;;EAEV,QAAQ;;EAER,eAAe;;EAEf,kBAAkB;;;;;;;;;;qBAWP;EAAY,eAAe;;;;;;qBAO3B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useCompact } from "./useCompact.js";
|
|
2
|
+
import { useCurrency } from "./useCurrency.js";
|
|
3
|
+
import { useDate } from "./useDate.js";
|
|
4
|
+
import { useIntl } from "./useIntl.js";
|
|
5
|
+
import { useList } from "./useList.js";
|
|
6
|
+
import { useNumber } from "./useNumber.js";
|
|
7
|
+
import { usePercentage } from "./usePercentage.js";
|
|
8
|
+
import { useRelativeTime } from "./useRelativeTime.js";
|
|
9
|
+
import { useUnit } from "./useUnit.js";
|
|
10
|
+
export { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCompact.d.ts","names":[],"sources":["../../../src/format/useCompact.ts"],"mappings":";;qBAOa,sBAAU,MAGJ,kBAAkB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCurrency.d.ts","names":[],"sources":["../../../src/format/useCurrency.ts"],"mappings":";;qBAOa,uBAAW,MAGL,kBAAkB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { date } from "@intlayer/core/formatters";
|
|
2
|
+
//#region src/format/useDate.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Remix hook that provides a localized date/time formatter bound to the request locale.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useDate: () => (...args: Parameters<typeof date>) => string;
|
|
7
|
+
//#endregion
|
|
8
|
+
//# sourceMappingURL=useDate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDate.d.ts","names":[],"sources":["../../../src/format/useDate.ts"],"mappings":";;;;;qBAUa,mBAAO,MAGD,kBAAkB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
|
+
import { WrappedIntl } from "@intlayer/core/utils";
|
|
3
|
+
//#region src/format/useIntl.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Remix hook that provides a locale-bound `Intl` object.
|
|
6
|
+
*
|
|
7
|
+
* It uses the request locale when running inside a request handler,
|
|
8
|
+
* falling back to the configured default locale.
|
|
9
|
+
*/
|
|
10
|
+
export declare const useIntl: (locale?: LocalesValues) => {
|
|
11
|
+
intl: WrappedIntl;
|
|
12
|
+
subscribe: (callback: (intl: WrappedIntl) => void) => () => void;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//# sourceMappingURL=useIntl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIntl.d.ts","names":[],"sources":["../../../src/format/useIntl.ts"],"mappings":";;;;;;;;;qBAgBa,UAAO,SACT;EAET,MAAM;EACN,YAAY,WAAW,MAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useList.d.ts","names":[],"sources":["../../../src/format/useList.ts"],"mappings":";;qBAOa,mBAAO,MAGD,kBAAkB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { number } from "@intlayer/core/formatters";
|
|
2
|
+
//#region src/format/useNumber.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Remix hook that provides a localized number formatter bound to the request locale.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useNumber: () => (...args: Parameters<typeof number>) => string;
|
|
7
|
+
//#endregion
|
|
8
|
+
//# sourceMappingURL=useNumber.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNumber.d.ts","names":[],"sources":["../../../src/format/useNumber.ts"],"mappings":";;;;;qBAUa,qBAAS,MAGH,kBAAkB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePercentage.d.ts","names":[],"sources":["../../../src/format/usePercentage.ts"],"mappings":";;qBAOa,yBAAa,MAGP,kBAAkB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRelativeTime.d.ts","names":[],"sources":["../../../src/format/useRelativeTime.ts"],"mappings":";;qBAOa,2BAAe,MAGT,kBAAkB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUnit.d.ts","names":[],"sources":["../../../src/format/useUnit.ts"],"mappings":";;qBAOa,mBAAO,MAGD,kBAAkB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { HTMLComponents, IntlayerHTMLPluginOptions, IntlayerHTMLProvider, RenderHTMLFunction, RenderHTMLOptions, RenderHTMLProps, installIntlayerHTML, installIntlayerHTMLDynamic, renderHTML, useHTML, useHTMLRenderer } from "vanilla-intlayer/html";
|
|
2
|
+
export { type HTMLComponents, type IntlayerHTMLPluginOptions, type IntlayerHTMLProvider, type RenderHTMLFunction, type RenderHTMLOptions, type RenderHTMLProps, installIntlayerHTML, installIntlayerHTMLDynamic, renderHTML, useHTML, useHTMLRenderer };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { INTLAYER_CONTEXT_PROPERTY, Intlayer, IntlayerState } from "./context.js";
|
|
2
|
+
import { LocaleRoutingAction, LocaleRoutingOptions, LocaleRoutingRequest, createLocaleRouting } from "./localeRouting.js";
|
|
3
|
+
import { IntlayerMiddlewareOptions, intlayer } from "./middleware.js";
|
|
4
|
+
import { getIntlayerState } from "./requestStorage.js";
|
|
5
|
+
import { useDictionary } from "./useDictionary.js";
|
|
6
|
+
import { useIntlayer } from "./useIntlayer.js";
|
|
7
|
+
import { UseLocaleResult, useLocale } from "./useLocale.js";
|
|
8
|
+
export { INTLAYER_CONTEXT_PROPERTY, Intlayer, type IntlayerMiddlewareOptions, type IntlayerState, type LocaleRoutingAction, type LocaleRoutingOptions, type LocaleRoutingRequest, type UseLocaleResult, createLocaleRouting, getIntlayerState, intlayer, useDictionary, useIntlayer, useLocale };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Locale } from "@intlayer/types/allLocales";
|
|
2
|
+
import { IntlayerConfig } from "@intlayer/types/config";
|
|
3
|
+
//#region src/localeRouting.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The part of an incoming request the locale routing is decided from.
|
|
6
|
+
*/
|
|
7
|
+
export type LocaleRoutingRequest = {
|
|
8
|
+
url: URL;
|
|
9
|
+
headers: Headers;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* What the locale routing decided for a request.
|
|
13
|
+
*
|
|
14
|
+
* - `pass` — leave the request untouched (proxy disabled, ignored path).
|
|
15
|
+
* - `rewrite` — keep serving the request, but from `path` (locale prefix
|
|
16
|
+
* stripped, rewrite rule resolved to its canonical path). `locale` is the
|
|
17
|
+
* locale the request resolved to, absent for a static asset.
|
|
18
|
+
* - `redirect` — answer with a redirect to `location`. `persistLocale` asks
|
|
19
|
+
* for the locale to be stored on the response so the follow-up request
|
|
20
|
+
* resolves the same locale.
|
|
21
|
+
*/
|
|
22
|
+
export type LocaleRoutingAction = {
|
|
23
|
+
kind: 'pass';
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'rewrite';
|
|
26
|
+
path: string;
|
|
27
|
+
locale?: Locale;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'redirect';
|
|
30
|
+
location: string;
|
|
31
|
+
status: 301 | 302;
|
|
32
|
+
persistLocale?: Locale;
|
|
33
|
+
};
|
|
34
|
+
export type LocaleRoutingOptions = {
|
|
35
|
+
/**
|
|
36
|
+
* Whether a development server is serving the app. In `enableProxy: auto`
|
|
37
|
+
* mode, a development server ignores the stored locale (cookie / header)
|
|
38
|
+
* when deciding where a request goes, so a stale cookie cannot keep pulling
|
|
39
|
+
* every navigation to another locale while developing.
|
|
40
|
+
*
|
|
41
|
+
* @default process.env.NODE_ENV === 'development'
|
|
42
|
+
*/
|
|
43
|
+
isDevServer?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Requests to leave untouched, in addition to static assets.
|
|
46
|
+
*/
|
|
47
|
+
ignore?: (request: LocaleRoutingRequest) => boolean;
|
|
48
|
+
};
|
|
49
|
+
export type LocaleRoutingConfiguration = Pick<IntlayerConfig, 'internationalization' | 'routing'>;
|
|
50
|
+
/**
|
|
51
|
+
* Builds the locale-routing resolver of a Remix application.
|
|
52
|
+
*
|
|
53
|
+
* Decides, for each request, whether to serve it as is, serve it from another
|
|
54
|
+
* internal path, or redirect it — mirroring the Intlayer proxies of
|
|
55
|
+
* `next-intlayer` and `vite-intlayer`. Unlike them, an internal rewrite hands
|
|
56
|
+
* the router the path *without* its locale prefix: the Remix router has no
|
|
57
|
+
* trailing-slash normalisation to work around, and this lets an application
|
|
58
|
+
* declare each route once (`/about`) whatever the routing mode, the locale
|
|
59
|
+
* being read from the request context instead of a route param.
|
|
60
|
+
*
|
|
61
|
+
* @param configuration - The `internationalization` and `routing` configuration.
|
|
62
|
+
* @param options - Runtime options.
|
|
63
|
+
* @returns A pure function deciding the routing of a request.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const resolveLocaleRouting = createLocaleRouting(configuration);
|
|
68
|
+
*
|
|
69
|
+
* resolveLocaleRouting({ url: new URL('http://host/fr/about'), headers });
|
|
70
|
+
* // { kind: 'rewrite', path: '/about', locale: 'fr' }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare const createLocaleRouting: (configuration: LocaleRoutingConfiguration, options?: LocaleRoutingOptions) => ((request: LocaleRoutingRequest) => LocaleRoutingAction);
|
|
74
|
+
//#endregion
|
|
75
|
+
//# sourceMappingURL=localeRouting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localeRouting.d.ts","names":[],"sources":["../../src/localeRouting.ts"],"mappings":";;;;;;YAmBY;EACV,KAAK;EACL,SAAS;;;;;;;;;;;;;YAcC;EACN;;EACA;EAAiB;EAAc,SAAS;;EAExC;EACA;EACA;EACA,gBAAgB;;YAGV;;;;;;;;;EASV;;;;EAIA,UAAU,SAAS;;YAGT,6BAA6B,KACvC;;;;;;;;;;;;;;;;;;;;;;;;qBA0DW,sBAAmB,eACf,4BAA0B,UAChC,2BACN,SAAS,yBAAyB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { IntlayerMarkdownPluginOptions, IntlayerMarkdownProvider, MarkdownCompilerOptions, MarkdownProviderOptions, ParsedMarkdown, RenderMarkdownFunction, RenderMarkdownProps, compileMarkdown, installIntlayerMarkdown, installIntlayerMarkdownDynamic, parseMarkdown, renderMarkdown, useMarkdown, useMarkdownRenderer } from "vanilla-intlayer/markdown";
|
|
2
|
+
export { type IntlayerMarkdownPluginOptions, type IntlayerMarkdownProvider, type MarkdownCompilerOptions, type MarkdownProviderOptions, type ParsedMarkdown, type RenderMarkdownFunction, type RenderMarkdownProps, compileMarkdown, installIntlayerMarkdown, installIntlayerMarkdownDynamic, parseMarkdown, renderMarkdown, useMarkdown, useMarkdownRenderer };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { INTLAYER_CONTEXT_PROPERTY, Intlayer, IntlayerState } from "./context.js";
|
|
2
|
+
import { LocaleRoutingOptions } from "./localeRouting.js";
|
|
3
|
+
import { Middleware } from "remix/router";
|
|
4
|
+
//#region src/middleware.d.ts
|
|
5
|
+
export type IntlayerMiddlewareOptions = LocaleRoutingOptions;
|
|
6
|
+
/**
|
|
7
|
+
* Remix 3 router middleware handling the internationalization layer:
|
|
8
|
+
* locale routing (redirects and internal rewrites, as `next-intlayer` and
|
|
9
|
+
* `vite-intlayer` do), locale resolution and locale persistence.
|
|
10
|
+
*
|
|
11
|
+
* Locale routing follows `routing.mode`. In the prefix modes, `/fr/about` is
|
|
12
|
+
* served from the `/about` route as French, `/about` is redirected to the
|
|
13
|
+
* localized URL of the detected locale (cookie / header, then
|
|
14
|
+
* `Accept-Language`) unless that locale needs no prefix, and `routing.rewrite`
|
|
15
|
+
* rules are applied both ways (`/fr/about` → `/fr/a-propos`). The router
|
|
16
|
+
* therefore matches every locale against the same unprefixed routes, and
|
|
17
|
+
* `routing.enableProxy: false` turns the routing off while keeping the
|
|
18
|
+
* locale resolution.
|
|
19
|
+
*
|
|
20
|
+
* The resolved locale is exposed as `context.get(Intlayer)` /
|
|
21
|
+
* `context.intlayer`, and the rest of the request runs inside an
|
|
22
|
+
* `AsyncLocalStorage` scope bound to the request context, so the hooks of this
|
|
23
|
+
* package (`useLocale`, `useIntlayer`, `useDictionary`) read that state from
|
|
24
|
+
* anywhere downstream — route handlers, views, Remix UI components — with the
|
|
25
|
+
* same signature as `react-intlayer`.
|
|
26
|
+
*
|
|
27
|
+
* @param options - Locale-routing options.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { createRouter } from 'remix/router';
|
|
32
|
+
* import { intlayer, useIntlayer } from 'remix-intlayer';
|
|
33
|
+
*
|
|
34
|
+
* const router = createRouter({ middleware: [intlayer()] });
|
|
35
|
+
*
|
|
36
|
+
* // Serves `/`, `/fr`, `/es`… — the locale comes from the request context.
|
|
37
|
+
* router.get('/', () => {
|
|
38
|
+
* const { title } = useIntlayer('home');
|
|
39
|
+
* return new Response(title);
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare const intlayer: (options?: IntlayerMiddlewareOptions) => Middleware<{
|
|
44
|
+
key: typeof Intlayer;
|
|
45
|
+
value: IntlayerState;
|
|
46
|
+
property: typeof INTLAYER_CONTEXT_PROPERTY;
|
|
47
|
+
}>;
|
|
48
|
+
//#endregion
|
|
49
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","names":[],"sources":["../../src/middleware.ts"],"mappings":";;;;YAoBY,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAyD3B,WAAQ,UACV,8BACR;EACD,YAAY;EACZ,OAAO;EACP,iBAAiB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Locale } from "@intlayer/types/allLocales";
|
|
2
|
+
//#region src/persistLocale.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Writes the locale into the storage headers configured in `routing.storage`
|
|
5
|
+
* (custom header, and the cookie when `includeCookie` is set).
|
|
6
|
+
*/
|
|
7
|
+
export declare const writeLocaleHeaders: (headers: Headers, locale: Locale, { includeCookie }?: {
|
|
8
|
+
includeCookie?: boolean;
|
|
9
|
+
}) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the response with the locale headers set. A response whose headers
|
|
12
|
+
* are immutable (`Response.redirect`, `Response.error`) is re-created.
|
|
13
|
+
*/
|
|
14
|
+
export declare const withLocaleHeaders: (response: Response, locale: Locale) => Response;
|
|
15
|
+
//#endregion
|
|
16
|
+
//# sourceMappingURL=persistLocale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistLocale.d.ts","names":[],"sources":["../../src/persistLocale.ts"],"mappings":";;;;;;qBAoCa,qBAAkB,SACpB,SAAO,QACR,UAAM;EACe;;;;;;qBAclB,oBAAiB,UAClB,UAAQ,QACV,WACP"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IntlayerState } from "./context.js";
|
|
2
|
+
import { DeclaredLocales } from "@intlayer/types/module_augmentation";
|
|
3
|
+
import { RequestContext } from "remix/router";
|
|
4
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
//#region src/requestStorage.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Request context of the request being handled, made available to every
|
|
8
|
+
* function running inside the `intlayer()` middleware scope — route handlers,
|
|
9
|
+
* views, Remix UI components rendered from them — without passing it around.
|
|
10
|
+
*/
|
|
11
|
+
export declare const requestStorage: AsyncLocalStorage<RequestContext<any, any>>;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the Intlayer state of the request being handled, if any.
|
|
14
|
+
*/
|
|
15
|
+
export declare const getIntlayerState: () => IntlayerState | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the locale of the request being handled, if any.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getRequestLocale: () => DeclaredLocales | undefined;
|
|
20
|
+
//#endregion
|
|
21
|
+
//# sourceMappingURL=requestStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestStorage.d.ts","names":[],"sources":["../../src/requestStorage.ts"],"mappings":";;;;;;;;;;qBAUa,gBAAc,kBAAA;;;;qBAKd,wBAAuB;;;;qBAMvB,wBAAuB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DeclaredLocales } from "@intlayer/types/module_augmentation";
|
|
2
|
+
import { Handle } from "remix/ui";
|
|
3
|
+
import { RequestContext } from "remix/router";
|
|
4
|
+
//#region src/resolveLocale.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Where a hook reads the current locale from:
|
|
7
|
+
* - a Remix router `RequestContext`, populated by the `intlayer()` middleware
|
|
8
|
+
* - a Remix UI component `Handle`, populated by an ancestor `IntlayerProvider`
|
|
9
|
+
*/
|
|
10
|
+
export type IntlayerSource = RequestContext<any, any> | Handle<any, any>;
|
|
11
|
+
/**
|
|
12
|
+
* Reads the locale published to the given source, if any.
|
|
13
|
+
*/
|
|
14
|
+
export declare const resolveLocale: (source: IntlayerSource) => DeclaredLocales | undefined;
|
|
15
|
+
//#endregion
|
|
16
|
+
//# sourceMappingURL=resolveLocale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveLocale.d.ts","names":[],"sources":["../../src/resolveLocale.ts"],"mappings":";;;;;;;;;YAWY,iBAAiB,2BAA2B;;;;qBAa3C,gBAAa,QAChB,mBACP"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DeclaredLocales, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
|
+
import { Dictionary, DictionarySelectorForGroup, QualifiedDictionaryGroup } from "@intlayer/types/dictionary";
|
|
3
|
+
//#region src/useDictionary.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Transforms an imported dictionary (or qualified dictionary group) and returns
|
|
6
|
+
* its content for the locale of the request being handled.
|
|
7
|
+
*
|
|
8
|
+
* The second argument is either a locale or a selector object
|
|
9
|
+
* (`{ item }`, `{ variant }`, optionally with `locale`); it takes precedence
|
|
10
|
+
* over the request locale.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import homeContent from './home.content';
|
|
15
|
+
*
|
|
16
|
+
* router.get('/', () => {
|
|
17
|
+
* const { title } = useDictionary(homeContent);
|
|
18
|
+
* return new Response(title);
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const useDictionary: <const T extends Dictionary | QualifiedDictionaryGroup, const A extends LocalesValues | DictionarySelectorForGroup<T> = DeclaredLocales>(dictionary: T, localeOrSelector?: A) => import("@intlayer/core/interpreter").DeepTransformContent<import("@intlayer/types").ResolveQualifiedDictionaryContent<T, A>, import("@intlayer/core/interpreter").IInterpreterPluginState, import("@intlayer/types").ExtractSelectorLocale<A>>;
|
|
23
|
+
//#endregion
|
|
24
|
+
//# sourceMappingURL=useDictionary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionary.d.ts","names":[],"sources":["../../src/useDictionary.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;qBA+Ba,sBACL,UAAU,aAAa,gCACvB,UACF,gBACA,2BAA2B,KAAK,iBAAe,YAEvC,GAAC,mBACM,2CAAC,+CAAA,kCAAA,GAAA,yCAAA,mDAAA,sBAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DeclaredLocales, DictionaryKeys, DictionarySelectorForKey, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
|
+
//#region src/useIntlayer.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Picks one dictionary by its key and returns its content for the locale of
|
|
5
|
+
* the request being handled.
|
|
6
|
+
*
|
|
7
|
+
* The second argument is either a locale or a selector object
|
|
8
|
+
* (`{ item }`, `{ variant }`, optionally with `locale`); it takes precedence
|
|
9
|
+
* over the request locale.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* router.get('/', () => {
|
|
14
|
+
* const { title } = useIntlayer('home');
|
|
15
|
+
* return new Response(title);
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const useIntlayer: <const T extends DictionaryKeys, const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales>(key: T, localeOrSelector?: A) => import("@intlayer/core/interpreter").DeepTransformContent<import("@intlayer/types").DictionaryRegistryResult<T, A>, import("@intlayer/core/interpreter").IInterpreterPluginState, import("@intlayer/types").ExtractSelectorLocale<A>>;
|
|
20
|
+
//#endregion
|
|
21
|
+
//# sourceMappingURL=useIntlayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIntlayer.d.ts","names":[],"sources":["../../src/useIntlayer.ts"],"mappings":";;;;;;;;;;;;;;;;;;qBA0Ba,oBACL,UAAU,sBACV,UAAU,gBAAgB,yBAAyB,KAAK,iBAAe,KAExE,GAAC,mBACa,2CAAC,+CAAA,yBAAA,GAAA,yCAAA,mDAAA,sBAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DeclaredLocales } from "@intlayer/types/module_augmentation";
|
|
2
|
+
//#region src/useLocale.d.ts
|
|
3
|
+
export type UseLocaleResult = {
|
|
4
|
+
locale: DeclaredLocales;
|
|
5
|
+
defaultLocale: DeclaredLocales;
|
|
6
|
+
availableLocales: DeclaredLocales[];
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Returns the locale of the request being handled, with the configured
|
|
10
|
+
* default and available locales.
|
|
11
|
+
*
|
|
12
|
+
* Falls back to the default locale outside of a request, i.e. when the
|
|
13
|
+
* `intlayer()` middleware did not run.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* router.get('/', () => {
|
|
18
|
+
* const { locale, availableLocales } = useLocale();
|
|
19
|
+
* return Response.json({ locale, availableLocales });
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const useLocale: () => UseLocaleResult;
|
|
24
|
+
//#endregion
|
|
25
|
+
//# sourceMappingURL=useLocale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../src/useLocale.ts"],"mappings":";;YAIY;EACV,QAAQ;EACR,eAAe;EACf,kBAAkB;;;;;;;;;;;;;;;;;qBAoBP,iBAAgB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "remix-intlayer",
|
|
3
|
+
"version": "9.5.4",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Manage internationalization i18n in a simple way for Remix 3 applications.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"intlayer",
|
|
8
|
+
"remix",
|
|
9
|
+
"remix-3",
|
|
10
|
+
"internationalization",
|
|
11
|
+
"i18n",
|
|
12
|
+
"typescript",
|
|
13
|
+
"javascript",
|
|
14
|
+
"middleware"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://intlayer.org",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/aymericzip/intlayer/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/aymericzip/intlayer.git"
|
|
23
|
+
},
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"author": {
|
|
26
|
+
"name": "Aymeric PINEAU",
|
|
27
|
+
"url": "https://github.com/aymericzip"
|
|
28
|
+
},
|
|
29
|
+
"contributors": [
|
|
30
|
+
{
|
|
31
|
+
"name": "Aymeric Pineau",
|
|
32
|
+
"email": "ay.pineau@gmail.com",
|
|
33
|
+
"url": "https://github.com/aymericzip"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/types/index.d.ts",
|
|
40
|
+
"require": "./dist/cjs/index.cjs",
|
|
41
|
+
"import": "./dist/esm/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./format": {
|
|
44
|
+
"types": "./dist/types/format/index.d.ts",
|
|
45
|
+
"require": "./dist/cjs/format/index.cjs",
|
|
46
|
+
"import": "./dist/esm/format/index.mjs"
|
|
47
|
+
},
|
|
48
|
+
"./html": {
|
|
49
|
+
"types": "./dist/types/html/index.d.ts",
|
|
50
|
+
"require": "./dist/cjs/html/index.cjs",
|
|
51
|
+
"import": "./dist/esm/html/index.mjs"
|
|
52
|
+
},
|
|
53
|
+
"./markdown": {
|
|
54
|
+
"types": "./dist/types/markdown/index.d.ts",
|
|
55
|
+
"require": "./dist/cjs/markdown/index.cjs",
|
|
56
|
+
"import": "./dist/esm/markdown/index.mjs"
|
|
57
|
+
},
|
|
58
|
+
"./package.json": "./package.json"
|
|
59
|
+
},
|
|
60
|
+
"main": "dist/cjs/index.cjs",
|
|
61
|
+
"module": "dist/esm/index.mjs",
|
|
62
|
+
"types": "dist/types/index.d.ts",
|
|
63
|
+
"typesVersions": {
|
|
64
|
+
"*": {
|
|
65
|
+
"format": [
|
|
66
|
+
"./dist/types/format/index.d.ts"
|
|
67
|
+
],
|
|
68
|
+
"html": [
|
|
69
|
+
"./dist/types/html/index.d.ts"
|
|
70
|
+
],
|
|
71
|
+
"markdown": [
|
|
72
|
+
"./dist/types/markdown/index.d.ts"
|
|
73
|
+
],
|
|
74
|
+
"package.json": [
|
|
75
|
+
"./package.json"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"files": [
|
|
80
|
+
"./dist",
|
|
81
|
+
"./package.json"
|
|
82
|
+
],
|
|
83
|
+
"scripts": {
|
|
84
|
+
"build": "bun --bun tsdown --config tsdown.config.ts",
|
|
85
|
+
"build:ci": "bun --bun tsdown --config tsdown.config.ts",
|
|
86
|
+
"clean": "bun --bun rimraf ./dist .turbo",
|
|
87
|
+
"dev": "bun --bun tsdown --config tsdown.config.ts --watch",
|
|
88
|
+
"format": "bun --bun biome format . --check",
|
|
89
|
+
"format:fix": "bun --bun biome format --write .",
|
|
90
|
+
"lint": "bun --bun biome lint .",
|
|
91
|
+
"lint:fix": "bun --bun biome lint --write .",
|
|
92
|
+
"prepublish": "cp -f ../../README.md ./README.md",
|
|
93
|
+
"publish": "bun publish || true",
|
|
94
|
+
"publish:canary": "bun publish --access public --tag canary || true",
|
|
95
|
+
"publish:ci": "bun ../../scripts/publish-package.mjs",
|
|
96
|
+
"publish:latest": "bun publish --access public --tag latest || true",
|
|
97
|
+
"test": "bun --bun vitest run",
|
|
98
|
+
"test:watch": "bun --bun vitest",
|
|
99
|
+
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
100
|
+
},
|
|
101
|
+
"dependencies": {
|
|
102
|
+
"@intlayer/config": "9.5.4",
|
|
103
|
+
"@intlayer/core": "9.5.4",
|
|
104
|
+
"@intlayer/engine": "9.5.4",
|
|
105
|
+
"@intlayer/types": "9.5.4",
|
|
106
|
+
"vanilla-intlayer": "9.5.4"
|
|
107
|
+
},
|
|
108
|
+
"devDependencies": {
|
|
109
|
+
"@intlayer/dictionaries-entry": "9.5.4",
|
|
110
|
+
"@types/node": "^22",
|
|
111
|
+
"@utils/ts-config": "1.0.4",
|
|
112
|
+
"@utils/ts-config-types": "1.0.4",
|
|
113
|
+
"@utils/tsdown-config": "1.0.4",
|
|
114
|
+
"remix": "3.0.0-rc.2",
|
|
115
|
+
"rimraf": "6.1.3",
|
|
116
|
+
"tsdown": "0.23.0",
|
|
117
|
+
"typescript": "7.0.2",
|
|
118
|
+
"vitest": "5.0.1"
|
|
119
|
+
},
|
|
120
|
+
"peerDependencies": {
|
|
121
|
+
"remix": ">=3.0.0-rc.0"
|
|
122
|
+
},
|
|
123
|
+
"engines": {
|
|
124
|
+
"node": ">=14.18"
|
|
125
|
+
},
|
|
126
|
+
"bug": {
|
|
127
|
+
"url": "https://github.com/aymericzip/intlayer/issues"
|
|
128
|
+
}
|
|
129
|
+
}
|