@fluenti/solid 0.1.0
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/LICENSE +21 -0
- package/README.md +317 -0
- package/dist/compile-time-t.d.ts +3 -0
- package/dist/compile-time-t.d.ts.map +1 -0
- package/dist/components/DateTime.d.ts +16 -0
- package/dist/components/DateTime.d.ts.map +1 -0
- package/dist/components/NumberFormat.d.ts +16 -0
- package/dist/components/NumberFormat.d.ts.map +1 -0
- package/dist/context.d.ts +69 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/hooks/__useI18n.d.ts +12 -0
- package/dist/hooks/__useI18n.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +446 -0
- package/dist/index.js.map +1 -0
- package/dist/msg.d.ts +2 -0
- package/dist/msg.d.ts.map +1 -0
- package/dist/plural.d.ts +55 -0
- package/dist/plural.d.ts.map +1 -0
- package/dist/provider.d.ts +10 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/rich-dom.d.ts +17 -0
- package/dist/rich-dom.d.ts.map +1 -0
- package/dist/select.d.ts +49 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/server.d.ts +77 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/trans.d.ts +46 -0
- package/dist/trans.d.ts.map +1 -0
- package/dist/types.d.ts +45 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/use-i18n.d.ts +12 -0
- package/dist/use-i18n.d.ts.map +1 -0
- package/package.json +75 -0
- package/src/compile-time-t.ts +9 -0
- package/src/components/DateTime.tsx +21 -0
- package/src/components/NumberFormat.tsx +21 -0
- package/src/context.ts +337 -0
- package/src/hooks/__useI18n.ts +15 -0
- package/src/index.ts +14 -0
- package/src/msg.ts +4 -0
- package/src/plural.tsx +136 -0
- package/src/provider.tsx +16 -0
- package/src/rich-dom.tsx +170 -0
- package/src/select.tsx +90 -0
- package/src/server.ts +153 -0
- package/src/trans.tsx +243 -0
- package/src/types.ts +55 -0
- package/src/use-i18n.ts +30 -0
- package/src/vite-runtime.d.ts +4 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ParentComponent } from 'solid-js';
|
|
2
|
+
import { I18nConfig, I18nContext } from './context';
|
|
3
|
+
/** Solid context object for i18n — used internally by useI18n() */
|
|
4
|
+
export declare const I18nCtx: import('solid-js').Context<I18nContext | undefined>;
|
|
5
|
+
/**
|
|
6
|
+
* Provide i18n context to the component tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export declare const I18nProvider: ParentComponent<I18nConfig>;
|
|
10
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAExD,mEAAmE;AACnE,eAAO,MAAM,OAAO,qDAA+B,CAAA;AAEnD;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC,UAAU,CAGpD,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { JSX } from 'solid-js';
|
|
2
|
+
export declare function offsetIndices(message: string, offset: number): string;
|
|
3
|
+
export declare function extractMessage(value: unknown): {
|
|
4
|
+
message: string;
|
|
5
|
+
components: Node[];
|
|
6
|
+
};
|
|
7
|
+
export declare function reconstruct(translated: string, components: Node[]): JSX.Element;
|
|
8
|
+
export declare function serializeRichForms<T extends string>(keys: readonly T[], forms: Partial<Record<T, unknown>> & Record<string, unknown>): {
|
|
9
|
+
messages: Record<string, string>;
|
|
10
|
+
components: Node[];
|
|
11
|
+
};
|
|
12
|
+
export declare function buildICUSelectMessage(forms: Record<string, string>): string;
|
|
13
|
+
export declare function normalizeSelectForms(forms: Record<string, string>): {
|
|
14
|
+
forms: Record<string, string>;
|
|
15
|
+
valueMap: Record<string, string>;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=rich-dom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rich-dom.d.ts","sourceRoot":"","sources":["../src/rich-dom.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAanC,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG;IAC9C,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,IAAI,EAAE,CAAA;CACnB,CAkCA;AAkBD,wBAAgB,WAAW,CACzB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,IAAI,EAAE,GACjB,GAAG,CAAC,OAAO,CAiCb;AAED,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,EACjD,IAAI,EAAE,SAAS,CAAC,EAAE,EAClB,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3D;IACD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,UAAU,EAAE,IAAI,EAAE,CAAA;CACnB,CAoBA;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAE3E;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;IACnE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC,CAqBA"}
|
package/dist/select.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Component, JSX } from 'solid-js';
|
|
2
|
+
/** Props for the `<Select>` component */
|
|
3
|
+
export interface SelectProps {
|
|
4
|
+
/** The value to match against prop keys */
|
|
5
|
+
value: string;
|
|
6
|
+
/** Override the auto-generated synthetic ICU message id */
|
|
7
|
+
id?: string;
|
|
8
|
+
/** Message context used for identity and translator disambiguation */
|
|
9
|
+
context?: string;
|
|
10
|
+
/** Translator-facing note preserved in extraction catalogs */
|
|
11
|
+
comment?: string;
|
|
12
|
+
/** Fallback message when no key matches */
|
|
13
|
+
other: string | JSX.Element;
|
|
14
|
+
/**
|
|
15
|
+
* Named options map. Keys are match values, values are display strings or JSX.
|
|
16
|
+
* Takes precedence over dynamic attrs when both are provided.
|
|
17
|
+
*
|
|
18
|
+
* @example `{ male: 'He', female: 'She' }`
|
|
19
|
+
*/
|
|
20
|
+
options?: Record<string, string | JSX.Element>;
|
|
21
|
+
/** Wrapper element tag name (default: `span`) */
|
|
22
|
+
tag?: string;
|
|
23
|
+
/** Additional key/message pairs for matching (attrs fallback) */
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Render a message selected by matching `value` against prop keys.
|
|
28
|
+
*
|
|
29
|
+
* Options can be provided via the type-safe `options` prop (recommended)
|
|
30
|
+
* or as direct attrs (convenience). When both are present, `options` takes
|
|
31
|
+
* precedence.
|
|
32
|
+
*
|
|
33
|
+
* Rich text is supported via JSX element values in the `options` prop or
|
|
34
|
+
* as direct JSX element props:
|
|
35
|
+
* ```tsx
|
|
36
|
+
* <Select
|
|
37
|
+
* value={gender()}
|
|
38
|
+
* options={{
|
|
39
|
+
* male: <><strong>He</strong> liked this</>,
|
|
40
|
+
* female: <><strong>She</strong> liked this</>,
|
|
41
|
+
* }}
|
|
42
|
+
* other={<><em>They</em> liked this</>}
|
|
43
|
+
* />
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* Falls back to the `other` prop when no key matches.
|
|
47
|
+
*/
|
|
48
|
+
export declare const SelectComp: Component<SelectProps>;
|
|
49
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../src/select.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAM9C,yCAAyC;AACzC,MAAM,WAAW,WAAW;IAC1B,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAA;IACb,2DAA2D;IAC3D,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAA;IAC3B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,CAAA;IAC9C,iDAAiD;IACjD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,iEAAiE;IACjE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,UAAU,EAAE,SAAS,CAAC,WAAW,CAoC7C,CAAA"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { FluentInstanceExtended, Locale, Messages, DateFormatOptions, NumberFormatOptions } from '@fluenti/core';
|
|
2
|
+
export { detectLocale, getSSRLocaleScript, getHydratedLocale, isRTL, getDirection } from '@fluenti/core';
|
|
3
|
+
export type { DetectLocaleOptions } from '@fluenti/core';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for `createServerI18n`.
|
|
6
|
+
*/
|
|
7
|
+
export interface ServerI18nConfig {
|
|
8
|
+
/** Load messages for a given locale. Called once per locale per request. */
|
|
9
|
+
loadMessages: (locale: string) => Promise<Messages | {
|
|
10
|
+
default: Messages;
|
|
11
|
+
}>;
|
|
12
|
+
/** Fallback locale when a translation is missing */
|
|
13
|
+
fallbackLocale?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Auto-resolve locale when `setLocale()` was not called.
|
|
16
|
+
*
|
|
17
|
+
* This is the fallback for contexts where the layout doesn't run — most
|
|
18
|
+
* notably `"use server"` functions, which are independent requests
|
|
19
|
+
* that skip the layout tree entirely.
|
|
20
|
+
*
|
|
21
|
+
* Common patterns:
|
|
22
|
+
* - Read from a cookie via `getRequestEvent()`
|
|
23
|
+
* - Read from a request header set by middleware
|
|
24
|
+
*
|
|
25
|
+
* If omitted and `setLocale()` was not called, `getI18n()` will throw.
|
|
26
|
+
*/
|
|
27
|
+
resolveLocale?: () => string | Promise<string>;
|
|
28
|
+
/** Custom fallback chains per locale */
|
|
29
|
+
fallbackChain?: Record<string, Locale[]>;
|
|
30
|
+
/** Custom date format styles */
|
|
31
|
+
dateFormats?: DateFormatOptions;
|
|
32
|
+
/** Custom number format styles */
|
|
33
|
+
numberFormats?: NumberFormatOptions;
|
|
34
|
+
/** Handler for missing translation keys */
|
|
35
|
+
missing?: (locale: Locale, id: string) => string | undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The object returned by `createServerI18n`.
|
|
39
|
+
*/
|
|
40
|
+
export interface ServerI18n {
|
|
41
|
+
/**
|
|
42
|
+
* Set the locale for the current server request.
|
|
43
|
+
* Call this once in your entry-server or root layout before any `getI18n()` calls.
|
|
44
|
+
*/
|
|
45
|
+
setLocale: (locale: string) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Get a fully configured i18n instance for the current request.
|
|
48
|
+
* Messages are loaded lazily and cached.
|
|
49
|
+
*/
|
|
50
|
+
getI18n: () => Promise<FluentInstanceExtended & {
|
|
51
|
+
locale: string;
|
|
52
|
+
}>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create server-side i18n utilities for SolidStart.
|
|
56
|
+
*
|
|
57
|
+
* Unlike React's `createServerI18n` which uses `React.cache()` for RSC
|
|
58
|
+
* per-request isolation, this version uses a simple module-level store
|
|
59
|
+
* matching SolidStart's synchronous rendering model.
|
|
60
|
+
*
|
|
61
|
+
* For per-request isolation in SolidStart, use `getRequestEvent()` in
|
|
62
|
+
* your `resolveLocale` callback, or call `setLocale()` in your
|
|
63
|
+
* entry-server middleware.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* // lib/i18n.server.ts
|
|
68
|
+
* import { createServerI18n } from '@fluenti/solid/server'
|
|
69
|
+
*
|
|
70
|
+
* export const { setLocale, getI18n } = createServerI18n({
|
|
71
|
+
* loadMessages: (locale) => import(`../locales/compiled/${locale}.ts`),
|
|
72
|
+
* fallbackLocale: 'en',
|
|
73
|
+
* })
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function createServerI18n(config: ServerI18nConfig): ServerI18n;
|
|
77
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,sBAAsB,EAEtB,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,eAAe,CAAA;AAGtB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACxG,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAExD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4EAA4E;IAC5E,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,GAAG;QAAE,OAAO,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAA;IAC3E,oDAAoD;IACpD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAC9C,wCAAwC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IACxC,gCAAgC;IAChC,WAAW,CAAC,EAAE,iBAAiB,CAAA;IAC/B,kCAAkC;IAClC,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC,2CAA2C;IAC3C,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAA;CAC7D;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IAEnC;;;OAGG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,sBAAsB,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACpE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU,CAmErE"}
|
package/dist/trans.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Component, JSX } from 'solid-js';
|
|
2
|
+
/** A Solid component that accepts children */
|
|
3
|
+
export type RichComponent = Component<{
|
|
4
|
+
children?: JSX.Element;
|
|
5
|
+
}>;
|
|
6
|
+
/** Props for the `<Trans>` component */
|
|
7
|
+
export interface TransProps {
|
|
8
|
+
/** Override auto-generated hash ID */
|
|
9
|
+
id?: string;
|
|
10
|
+
/** Message context used for identity and translator disambiguation */
|
|
11
|
+
context?: string;
|
|
12
|
+
/** Translator-facing note preserved in extraction catalogs */
|
|
13
|
+
comment?: string;
|
|
14
|
+
/** Wrapper element tag name (default: `'span'`) — used in children-only mode */
|
|
15
|
+
tag?: string;
|
|
16
|
+
/** Children — the content to translate (legacy API) */
|
|
17
|
+
children?: JSX.Element;
|
|
18
|
+
/** Translated message string with XML-like tags (e.g. `<bold>text</bold>`) */
|
|
19
|
+
message?: string;
|
|
20
|
+
/** Map of tag names to Solid components */
|
|
21
|
+
components?: Record<string, RichComponent>;
|
|
22
|
+
/** @internal Pre-computed message from build plugin */
|
|
23
|
+
__message?: string;
|
|
24
|
+
/** @internal Pre-computed component map from build plugin */
|
|
25
|
+
__components?: Record<string, RichComponent>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Render translated content with inline components.
|
|
29
|
+
*
|
|
30
|
+
* Supports two APIs:
|
|
31
|
+
*
|
|
32
|
+
* 1. **message + components** (recommended for rich text):
|
|
33
|
+
* ```tsx
|
|
34
|
+
* <Trans
|
|
35
|
+
* message={t`Welcome to <bold>Fluenti</bold>!`}
|
|
36
|
+
* components={{ bold: (props) => <strong>{props.children}</strong> }}
|
|
37
|
+
* />
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* 2. **children** (legacy / simple passthrough):
|
|
41
|
+
* ```tsx
|
|
42
|
+
* <Trans>Click <a href="/next">here</a> to continue</Trans>
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const Trans: Component<TransProps>;
|
|
46
|
+
//# sourceMappingURL=trans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trans.d.ts","sourceRoot":"","sources":["../src/trans.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAI9C,8CAA8C;AAC9C,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC;IAAE,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;CAAE,CAAC,CAAA;AAEjE,wCAAwC;AACxC,MAAM,WAAW,UAAU;IACzB,sCAAsC;IACtC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gFAAgF;IAChF,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,uDAAuD;IACvD,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;IACtB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC1C,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,6DAA6D;IAC7D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CAC7C;AAmJD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,KAAK,EAAE,SAAS,CAAC,UAAU,CAgDvC,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Accessor } from 'solid-js';
|
|
2
|
+
import { FluentConfig, Locale, Messages, CompiledMessage, MessageDescriptor, DateFormatOptions, NumberFormatOptions } from '@fluenti/core';
|
|
3
|
+
/** Chunk loader for lazy locale loading */
|
|
4
|
+
export type ChunkLoader = (locale: string) => Promise<Record<string, CompiledMessage> | {
|
|
5
|
+
default: Record<string, CompiledMessage>;
|
|
6
|
+
}>;
|
|
7
|
+
/** Extended config with lazy locale loading support */
|
|
8
|
+
export interface I18nConfig extends FluentConfig {
|
|
9
|
+
/** Async chunk loader for lazy locale loading */
|
|
10
|
+
chunkLoader?: ChunkLoader;
|
|
11
|
+
/** Enable lazy locale loading through chunkLoader */
|
|
12
|
+
lazyLocaleLoading?: boolean;
|
|
13
|
+
/** Named date format styles */
|
|
14
|
+
dateFormats?: DateFormatOptions;
|
|
15
|
+
/** Named number format styles */
|
|
16
|
+
numberFormats?: NumberFormatOptions;
|
|
17
|
+
}
|
|
18
|
+
/** Reactive i18n context holding locale signal and translation utilities */
|
|
19
|
+
export interface I18nContext {
|
|
20
|
+
/** Reactive accessor for the current locale */
|
|
21
|
+
locale(): Locale;
|
|
22
|
+
/** Set the active locale (async when lazy locale loading is enabled) */
|
|
23
|
+
setLocale(locale: Locale): Promise<void>;
|
|
24
|
+
/** Translate a message by id with optional interpolation values */
|
|
25
|
+
t(id: string | MessageDescriptor, values?: Record<string, unknown>): string;
|
|
26
|
+
/** Tagged template form: t`Hello ${name}` */
|
|
27
|
+
t(strings: TemplateStringsArray, ...exprs: unknown[]): string;
|
|
28
|
+
/** Merge additional messages into a locale catalog at runtime */
|
|
29
|
+
loadMessages(locale: Locale, messages: Messages): void;
|
|
30
|
+
/** Return all locale codes that have loaded messages */
|
|
31
|
+
getLocales(): Locale[];
|
|
32
|
+
/** Format a date value for the current locale */
|
|
33
|
+
d(value: Date | number, style?: string): string;
|
|
34
|
+
/** Format a number value for the current locale */
|
|
35
|
+
n(value: number, style?: string): string;
|
|
36
|
+
/** Format an ICU message string directly (no catalog lookup) */
|
|
37
|
+
format(message: string, values?: Record<string, unknown>): string;
|
|
38
|
+
/** Whether a locale chunk is currently being loaded */
|
|
39
|
+
isLoading: Accessor<boolean>;
|
|
40
|
+
/** Set of locales whose messages have been loaded */
|
|
41
|
+
loadedLocales: Accessor<Set<string>>;
|
|
42
|
+
/** Preload a locale in the background without switching to it */
|
|
43
|
+
preloadLocale(locale: string): void;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,eAAe,CAAA;AAEtB,2CAA2C;AAC3C,MAAM,MAAM,WAAW,GAAG,CACxB,MAAM,EAAE,MAAM,KACX,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CAAE,CAAC,CAAA;AAE5F,uDAAuD;AACvD,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C,iDAAiD;IACjD,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,qDAAqD;IACrD,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,+BAA+B;IAC/B,WAAW,CAAC,EAAE,iBAAiB,CAAA;IAC/B,iCAAiC;IACjC,aAAa,CAAC,EAAE,mBAAmB,CAAA;CACpC;AAED,4EAA4E;AAC5E,MAAM,WAAW,WAAW;IAC1B,+CAA+C;IAC/C,MAAM,IAAI,MAAM,CAAA;IAChB,wEAAwE;IACxE,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACxC,mEAAmE;IACnE,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAA;IAC3E,6CAA6C;IAC7C,CAAC,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAC7D,iEAAiE;IACjE,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAA;IACtD,wDAAwD;IACxD,UAAU,IAAI,MAAM,EAAE,CAAA;IACtB,iDAAiD;IACjD,CAAC,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC/C,mDAAmD;IACnD,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxC,gEAAgE;IAChE,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAA;IACjE,uDAAuD;IACvD,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC5B,qDAAqD;IACrD,aAAa,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;IACpC,iEAAiE;IACjE,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CACpC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { I18nContext } from './context';
|
|
2
|
+
/**
|
|
3
|
+
* Access the i18n context.
|
|
4
|
+
*
|
|
5
|
+
* Resolution order:
|
|
6
|
+
* 1. Nearest `<I18nProvider>` in the component tree
|
|
7
|
+
* 2. Module-level singleton created by `createI18n()`
|
|
8
|
+
*
|
|
9
|
+
* Throws if neither is available.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useI18n(): I18nContext;
|
|
12
|
+
//# sourceMappingURL=use-i18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-i18n.d.ts","sourceRoot":"","sources":["../src/use-i18n.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAE5C;;;;;;;;GAQG;AACH,wBAAgB,OAAO,IAAI,WAAW,CAerC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluenti/solid",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "SolidJS compile-time i18n — Trans/Plural/Select components, I18nProvider, useI18n",
|
|
6
|
+
"homepage": "https://fluenti.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/usefluenti/fluenti.git",
|
|
10
|
+
"directory": "packages/solid"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/usefluenti/fluenti/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"i18n",
|
|
21
|
+
"internationalization",
|
|
22
|
+
"compile-time",
|
|
23
|
+
"icu",
|
|
24
|
+
"messageformat",
|
|
25
|
+
"solid",
|
|
26
|
+
"solidjs",
|
|
27
|
+
"signals"
|
|
28
|
+
],
|
|
29
|
+
"main": "./dist/index.cjs",
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"solid": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"default": "./src/index.ts"
|
|
37
|
+
},
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"default": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"default": "./dist/index.cjs"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist",
|
|
50
|
+
"src"
|
|
51
|
+
],
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"solid-js": "^1.8"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@fluenti/core": "0.1.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@solidjs/testing-library": "^0.8",
|
|
60
|
+
"@vitest/coverage-v8": "^4",
|
|
61
|
+
"happy-dom": "^20",
|
|
62
|
+
"solid-js": "^1.9",
|
|
63
|
+
"typescript": "^5.9",
|
|
64
|
+
"vite": "^8",
|
|
65
|
+
"vite-plugin-dts": "^4",
|
|
66
|
+
"vite-plugin-solid": "^2.11.11",
|
|
67
|
+
"vitest": "^4"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"build": "vite build",
|
|
71
|
+
"dev": "vite build --watch",
|
|
72
|
+
"test": "vitest run",
|
|
73
|
+
"typecheck": "tsc --noEmit"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CompileTimeT } from '@fluenti/core'
|
|
2
|
+
|
|
3
|
+
export const t: CompileTimeT = ((..._args: unknown[]) => {
|
|
4
|
+
throw new Error(
|
|
5
|
+
"[fluenti] `t` imported from '@fluenti/solid' is a compile-time API. " +
|
|
6
|
+
'Use it only with the Fluenti build transform inside a component or custom hook. ' +
|
|
7
|
+
'For runtime lookups, use useI18n().t(...).',
|
|
8
|
+
)
|
|
9
|
+
}) as CompileTimeT
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useI18n } from '../use-i18n'
|
|
2
|
+
|
|
3
|
+
export interface DateTimeProps {
|
|
4
|
+
/** Date value to format */
|
|
5
|
+
value: Date | number
|
|
6
|
+
/** Named format style */
|
|
7
|
+
style?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `<DateTime>` — date formatting component using Intl APIs.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* <DateTime value={new Date()} style="long" />
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function DateTime(props: DateTimeProps) {
|
|
19
|
+
const { d } = useI18n()
|
|
20
|
+
return <>{d(props.value, props.style)}</>
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useI18n } from '../use-i18n'
|
|
2
|
+
|
|
3
|
+
export interface NumberProps {
|
|
4
|
+
/** Number value to format */
|
|
5
|
+
value: number
|
|
6
|
+
/** Named format style */
|
|
7
|
+
style?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `<NumberFormat>` — number formatting component using Intl APIs.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* <NumberFormat value={1234.56} style="currency" />
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function NumberFormat(props: NumberProps) {
|
|
19
|
+
const { n } = useI18n()
|
|
20
|
+
return <>{n(props.value, props.style)}</>
|
|
21
|
+
}
|