@fluenti/solid 0.5.0 → 0.6.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/README.md +5 -5
- package/dist/components-entry-5CGlUlc5.cjs +2 -0
- package/dist/components-entry-5CGlUlc5.cjs.map +1 -0
- package/dist/components-entry-C-Df62O-.js +632 -0
- package/dist/components-entry-C-Df62O-.js.map +1 -0
- package/dist/components-entry.cjs +1 -2
- package/dist/components-entry.js +2 -293
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -4
- package/dist/solid/src/compile-time-t.d.ts +3 -0
- package/dist/solid/src/compile-time-t.d.ts.map +1 -0
- package/dist/solid/src/compiled.d.ts +43 -0
- package/dist/solid/src/compiled.d.ts.map +1 -0
- package/dist/solid/src/components/DateTime.d.ts.map +1 -0
- package/dist/solid/src/components/NumberFormat.d.ts.map +1 -0
- package/dist/{components-entry.d.ts → solid/src/components-entry.d.ts} +1 -1
- package/dist/solid/src/components-entry.d.ts.map +1 -0
- package/dist/{context.d.ts → solid/src/context.d.ts} +5 -4
- package/dist/solid/src/context.d.ts.map +1 -0
- package/dist/solid/src/hooks/__useI18n.d.ts.map +1 -0
- package/dist/solid/src/index.d.ts +9 -0
- package/dist/solid/src/index.d.ts.map +1 -0
- package/dist/solid/src/msg.d.ts +2 -0
- package/dist/solid/src/msg.d.ts.map +1 -0
- package/dist/solid/src/plain-runtime.d.ts +9 -0
- package/dist/solid/src/plain-runtime.d.ts.map +1 -0
- package/dist/{plural.d.ts → solid/src/plural.d.ts} +1 -1
- package/dist/solid/src/plural.d.ts.map +1 -0
- package/dist/solid/src/provider.d.ts.map +1 -0
- package/dist/solid/src/rich-dom.d.ts.map +1 -0
- package/dist/{select.d.ts → solid/src/select.d.ts} +1 -1
- package/dist/solid/src/select.d.ts.map +1 -0
- package/dist/{server.d.ts → solid/src/server.d.ts} +3 -3
- package/dist/solid/src/server.d.ts.map +1 -0
- package/dist/solid/src/solid-runtime.d.ts +3 -0
- package/dist/solid/src/solid-runtime.d.ts.map +1 -0
- package/dist/solid/src/trans.d.ts.map +1 -0
- package/dist/{types.d.ts → solid/src/types.d.ts} +1 -1
- package/dist/solid/src/types.d.ts.map +1 -0
- package/dist/solid/src/use-i18n.d.ts.map +1 -0
- package/dist/{vite-plugin.d.ts → solid/src/vite-plugin.d.ts} +2 -2
- package/dist/solid/src/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.cjs +1 -1
- package/dist/vite-plugin.cjs.map +1 -1
- package/dist/vite-plugin.js +1 -1
- package/dist/vite-plugin.js.map +1 -1
- package/package.json +14 -14
- package/src/compiled.tsx +158 -0
- package/src/components-entry.ts +7 -3
- package/src/context.ts +5 -3
- package/src/index.ts +11 -10
- package/src/plain-runtime.ts +65 -0
- package/src/plural.tsx +23 -11
- package/src/rich-dom.tsx +1 -2
- package/src/select.tsx +16 -5
- package/src/solid-runtime.ts +1 -1
- package/dist/compile-time-t.d.ts +0 -3
- package/dist/compile-time-t.d.ts.map +0 -1
- package/dist/components/DateTime.d.ts.map +0 -1
- package/dist/components/NumberFormat.d.ts.map +0 -1
- package/dist/components-entry.cjs.map +0 -1
- package/dist/components-entry.d.ts.map +0 -1
- package/dist/components-entry.js.map +0 -1
- package/dist/context.d.ts.map +0 -1
- package/dist/hooks/__useI18n.d.ts.map +0 -1
- package/dist/index.d.ts +0 -12
- package/dist/index.d.ts.map +0 -1
- package/dist/msg.d.ts +0 -2
- package/dist/msg.d.ts.map +0 -1
- package/dist/plural.d.ts.map +0 -1
- package/dist/provider.d.ts.map +0 -1
- package/dist/rich-dom.d.ts.map +0 -1
- package/dist/select.d.ts.map +0 -1
- package/dist/server.d.ts.map +0 -1
- package/dist/solid-runtime.d.ts +0 -3
- package/dist/solid-runtime.d.ts.map +0 -1
- package/dist/trans.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/use-i18n-5u9iEPWp.js +0 -204
- package/dist/use-i18n-5u9iEPWp.js.map +0 -1
- package/dist/use-i18n-B8NgKzjN.cjs +0 -2
- package/dist/use-i18n-B8NgKzjN.cjs.map +0 -1
- package/dist/use-i18n.d.ts.map +0 -1
- package/dist/vite-plugin.d.ts.map +0 -1
- /package/dist/{components → solid/src/components}/DateTime.d.ts +0 -0
- /package/dist/{components → solid/src/components}/NumberFormat.d.ts +0 -0
- /package/dist/{hooks → solid/src/hooks}/__useI18n.d.ts +0 -0
- /package/dist/{provider.d.ts → solid/src/provider.d.ts} +0 -0
- /package/dist/{rich-dom.d.ts → solid/src/rich-dom.d.ts} +0 -0
- /package/dist/{trans.d.ts → solid/src/trans.d.ts} +0 -0
- /package/dist/{use-i18n.d.ts → solid/src/use-i18n.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__useI18n.d.ts","sourceRoot":"","sources":["../../../../src/hooks/__useI18n.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9C;;;;;;;;GAQG;AACH,wBAAgB,SAAS,IAAI,cAAc,CAE1C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createFluenti } from './context';
|
|
2
|
+
export type { FluentiContext, FluentiConfig } from './context';
|
|
3
|
+
export { I18nProvider } from './provider';
|
|
4
|
+
export { useI18n, useLocale } from './use-i18n';
|
|
5
|
+
export { t } from './compile-time-t';
|
|
6
|
+
export { Trans, Plural, Select, DateTime, NumberFormat } from './components-entry';
|
|
7
|
+
export type { FluentiTransProps, FluentiPluralProps, FluentiSelectProps, DateTimeProps, FluentiDateTimeProps, NumberProps, FluentiNumberFormatProps, } from './components-entry';
|
|
8
|
+
export { msg } from './msg';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAClF,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACpB,WAAW,EACX,wBAAwB,GACzB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msg.d.ts","sourceRoot":"","sources":["../../../src/msg.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PluralCategory } from '../../core/src/runtime.ts';
|
|
2
|
+
export declare function resolvePropValue(value: unknown): unknown;
|
|
3
|
+
export declare function resolveCompiledMessageId(id: string | undefined, message: string, context: string | undefined): string;
|
|
4
|
+
export declare function buildPlainPluralMessage(forms: Partial<Record<PluralCategory, unknown>>, offset?: number): string | undefined;
|
|
5
|
+
export declare function buildPlainSelectMessage(forms: Record<string, unknown>): {
|
|
6
|
+
message: string;
|
|
7
|
+
valueMap: Record<string, string>;
|
|
8
|
+
} | undefined;
|
|
9
|
+
//# sourceMappingURL=plain-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plain-runtime.d.ts","sourceRoot":"","sources":["../../../src/plain-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,uBAAuB,CAAA;AAE9B,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKxD;AAED,wBAAgB,wBAAwB,CACtC,EAAE,EAAE,MAAM,GAAG,SAAS,EACtB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,MAAM,CAER;AAMD,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,EAC/C,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAYpB;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,SAAS,CAiBnE"}
|
|
@@ -53,7 +53,7 @@ export interface FluentiPluralProps {
|
|
|
53
53
|
*
|
|
54
54
|
* @example
|
|
55
55
|
* ```tsx
|
|
56
|
-
* import { Plural } from '@fluenti/solid'
|
|
56
|
+
* import { Plural } from '@fluenti/solid/components'
|
|
57
57
|
*
|
|
58
58
|
* function ItemCount(props: { count: number }) {
|
|
59
59
|
* return <Plural value={props.count} one="# item" other="# items" />
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../../src/plural.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAM9C,yCAAyC;AACzC,MAAM,WAAW,kBAAkB;IACjC,qCAAqC;IACrC,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,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAA;IAC3B,4CAA4C;IAC5C,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAA;IAC1B,4CAA4C;IAC5C,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAA;IAC1B,4CAA4C;IAC5C,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAA;IAC1B,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAA;IAC3B,8DAA8D;IAC9D,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAA;IAC3B,mEAAmE;IACnE,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,MAAM,EAAE,SAAS,CAAC,kBAAkB,CA0DhD,CAAA"}
|
|
@@ -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,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE9D,mEAAmE;AACnE,eAAO,MAAM,OAAO,wDAAkC,CAAA;AAEtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC,aAAa,CAGvD,CAAA"}
|
|
@@ -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;AAenC,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG;IAC9C,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,IAAI,EAAE,CAAA;CACnB,CAsCA;AAkBD,wBAAgB,WAAW,CACzB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,IAAI,EAAE,GACjB,GAAG,CAAC,OAAO,CAmDb;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"}
|
|
@@ -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;AAO9C,yCAAyC;AACzC,MAAM,WAAW,kBAAkB;IACjC,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,mEAAmE;IACnE,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,iEAAiE;IACjE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,UAAU,EAAE,SAAS,CAAC,kBAAkB,CAuDpD,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FluentiCoreInstanceFull, Locale, Messages, DateFormatOptions, NumberFormatOptions } from '
|
|
2
|
-
export { detectLocale, getSSRLocaleScript, getHydratedLocale, isRTL, getDirection } from '
|
|
3
|
-
export type { DetectLocaleOptions } from '
|
|
1
|
+
import { FluentiCoreInstanceFull, Locale, Messages, DateFormatOptions, NumberFormatOptions } from '../../core/src/index.ts';
|
|
2
|
+
export { detectLocale, getSSRLocaleScript, getHydratedLocale, isRTL, getDirection } from '../../core/src/index.ts';
|
|
3
|
+
export type { DetectLocaleOptions } from '../../core/src/index.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Configuration for `createServerI18n`.
|
|
6
6
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,uBAAuB,EAEvB,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,uBAAuB,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAEpE;;;;;;;;;;;;;;OAcG;IACH,UAAU,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;CACxE;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU,CA6FrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid-runtime.d.ts","sourceRoot":"","sources":["../../../src/solid-runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE5D,eAAO,MAAM,qBAAqB,EAAE,gBAUlC,CAAA"}
|
|
@@ -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,iBAAiB;IAChC,sCAAsC;IACtC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,mEAAmE;IACnE,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;AAyJD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,KAAK,EAAE,SAAS,CAAC,iBAAiB,CAmD9C,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Accessor } from 'solid-js';
|
|
2
|
-
import { FluentiCoreConfig, Locale, LocalizedString, Messages, CompiledMessage, MessageDescriptor, DateFormatOptions, NumberFormatOptions } from '
|
|
2
|
+
import { FluentiCoreConfig, Locale, LocalizedString, Messages, CompiledMessage, MessageDescriptor, DateFormatOptions, NumberFormatOptions } from '../../core/src/index.ts';
|
|
3
3
|
/** Chunk loader for lazy locale loading */
|
|
4
4
|
export type ChunkLoader = (locale: string) => Promise<Record<string, CompiledMessage> | {
|
|
5
5
|
default: Record<string, CompiledMessage>;
|
|
@@ -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,iBAAiB,EACjB,MAAM,EACN,eAAe,EACf,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,aAAc,SAAQ,iBAAiB;IACtD,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,cAAc;IAC7B,+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,eAAe,CAAA;IACpF,6CAA6C;IAC7C,CAAC,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,eAAe,CAAA;IACtE,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,eAAe,CAAA;IACxD,mDAAmD;IACnD,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,eAAe,CAAA;IACjD,gEAAgE;IAChE,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,eAAe,CAAA;IAC1E,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 @@
|
|
|
1
|
+
{"version":3,"file":"use-i18n.d.ts","sourceRoot":"","sources":["../../../src/use-i18n.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE/C;;;;GAIG;AACH,wBAAgB,OAAO,IAAI,cAAc,CASxC;AAED,oEAAoE;AACpE,wBAAgB,SAAS,IAAI,MAAM,MAAM,CAExC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import { FluentiPluginOptions } from '
|
|
3
|
-
export type { FluentiPluginOptions as FluentiSolidOptions } from '
|
|
2
|
+
import { FluentiPluginOptions } from '../../vite-plugin/src/index.ts';
|
|
3
|
+
export type { FluentiPluginOptions as FluentiSolidOptions } from '../../vite-plugin/src/index.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Fluenti SolidJS Vite plugin.
|
|
6
6
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../../../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAIhE,YAAY,EAAE,oBAAoB,IAAI,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAEvF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,EAAE,CAM7E"}
|
package/dist/vite-plugin.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
let e=require(`@fluenti/vite-plugin`);var t=(0,e.createRuntimeGenerator)({imports:`import { createSignal } from 'solid-js'
|
|
2
|
-
import { createStore, reconcile } from 'solid-js/store'`,catalogInit:`const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })`,localeInit:e=>`const [__currentLocale, __setCurrentLocale] = createSignal(
|
|
2
|
+
import { createStore, reconcile } from 'solid-js/store'`,catalogInit:`const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })`,localeInit:e=>`const [__currentLocale, __setCurrentLocale] = createSignal(${JSON.stringify(e)})`,loadingInit:`const [__loading, __setLoading] = createSignal(false)`,catalogUpdate:e=>`__setCatalog(reconcile(${e}))`,localeUpdate:e=>`__setCurrentLocale(${e})`,loadingUpdate:e=>`__setLoading(${e})`,localeRead:`__currentLocale()`,runtimeKey:`fluenti.runtime.solid.v1`});function n(n){return(0,e.createFluentiPlugins)({...n?.config===void 0?{}:{config:n.config},framework:`solid`},[],t)}module.exports=n;
|
|
3
3
|
//# sourceMappingURL=vite-plugin.cjs.map
|
package/dist/vite-plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.cjs","names":[],"sources":["../src/solid-runtime.ts","../src/vite-plugin.ts"],"sourcesContent":["import { createRuntimeGenerator } from '@fluenti/vite-plugin'\nimport type { RuntimeGenerator } from '@fluenti/vite-plugin'\n\nexport const solidRuntimeGenerator: RuntimeGenerator = createRuntimeGenerator({\n imports: `import { createSignal } from 'solid-js'\\nimport { createStore, reconcile } from 'solid-js/store'`,\n catalogInit: 'const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })',\n localeInit: (defaultLocale) => `const [__currentLocale, __setCurrentLocale] = createSignal(
|
|
1
|
+
{"version":3,"file":"vite-plugin.cjs","names":[],"sources":["../src/solid-runtime.ts","../src/vite-plugin.ts"],"sourcesContent":["import { createRuntimeGenerator } from '@fluenti/vite-plugin'\nimport type { RuntimeGenerator } from '@fluenti/vite-plugin'\n\nexport const solidRuntimeGenerator: RuntimeGenerator = createRuntimeGenerator({\n imports: `import { createSignal } from 'solid-js'\\nimport { createStore, reconcile } from 'solid-js/store'`,\n catalogInit: 'const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })',\n localeInit: (defaultLocale) => `const [__currentLocale, __setCurrentLocale] = createSignal(${JSON.stringify(defaultLocale)})`,\n loadingInit: 'const [__loading, __setLoading] = createSignal(false)',\n catalogUpdate: (msgs) => `__setCatalog(reconcile(${msgs}))`,\n localeUpdate: (locale) => `__setCurrentLocale(${locale})`,\n loadingUpdate: (value) => `__setLoading(${value})`,\n localeRead: '__currentLocale()',\n runtimeKey: 'fluenti.runtime.solid.v1',\n})\n","import type { Plugin } from 'vite'\nimport type { FluentiPluginOptions } from '@fluenti/vite-plugin'\nimport { createFluentiPlugins } from '@fluenti/vite-plugin'\nimport { solidRuntimeGenerator } from './solid-runtime'\n\nexport type { FluentiPluginOptions as FluentiSolidOptions } from '@fluenti/vite-plugin'\n\n/**\n * Fluenti SolidJS Vite plugin.\n *\n * @example Minimal — no fluenti.config.ts needed\n * ```ts\n * // vite.config.ts\n * import fluentiSolid from '@fluenti/solid/vite-plugin'\n *\n * export default defineConfig({\n * plugins: [fluentiSolid({ config: { locales: ['en', 'ja'] } })],\n * })\n * ```\n *\n * @example With fluenti.config.ts (for advanced options)\n * ```ts\n * export default defineConfig({\n * plugins: [fluentiSolid()], // auto-reads fluenti.config.ts\n * })\n * ```\n */\nexport default function fluentiSolid(options?: FluentiPluginOptions): Plugin[] {\n return createFluentiPlugins(\n { ...(options?.config !== undefined ? { config: options.config } : {}), framework: 'solid' },\n [],\n solidRuntimeGenerator,\n )\n}\n"],"mappings":"sCAGA,IAAa,GAAA,EAAA,EAAA,wBAAiE,CAC5E,QAAS;yDACT,YAAa,sEACb,WAAa,GAAkB,8DAA8D,KAAK,UAAU,EAAc,CAAC,GAC3H,YAAa,wDACb,cAAgB,GAAS,0BAA0B,EAAK,IACxD,aAAe,GAAW,sBAAsB,EAAO,GACvD,cAAgB,GAAU,gBAAgB,EAAM,GAChD,WAAY,oBACZ,WAAY,2BACb,CAAC,CCcF,SAAwB,EAAa,EAA0C,CAC7E,OAAA,EAAA,EAAA,sBACE,CAAE,GAAI,GAAS,SAAW,IAAA,GAAyC,EAAE,CAA/B,CAAE,OAAQ,EAAQ,OAAQ,CAAQ,UAAW,QAAS,CAC5F,EAAE,CACF,EACD"}
|
package/dist/vite-plugin.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createFluentiPlugins as e, createRuntimeGenerator as t } from "@fluenti
|
|
|
3
3
|
var n = t({
|
|
4
4
|
imports: "import { createSignal } from 'solid-js'\nimport { createStore, reconcile } from 'solid-js/store'",
|
|
5
5
|
catalogInit: "const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })",
|
|
6
|
-
localeInit: (e) => `const [__currentLocale, __setCurrentLocale] = createSignal(
|
|
6
|
+
localeInit: (e) => `const [__currentLocale, __setCurrentLocale] = createSignal(${JSON.stringify(e)})`,
|
|
7
7
|
loadingInit: "const [__loading, __setLoading] = createSignal(false)",
|
|
8
8
|
catalogUpdate: (e) => `__setCatalog(reconcile(${e}))`,
|
|
9
9
|
localeUpdate: (e) => `__setCurrentLocale(${e})`,
|
package/dist/vite-plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.js","names":[],"sources":["../src/solid-runtime.ts","../src/vite-plugin.ts"],"sourcesContent":["import { createRuntimeGenerator } from '@fluenti/vite-plugin'\nimport type { RuntimeGenerator } from '@fluenti/vite-plugin'\n\nexport const solidRuntimeGenerator: RuntimeGenerator = createRuntimeGenerator({\n imports: `import { createSignal } from 'solid-js'\\nimport { createStore, reconcile } from 'solid-js/store'`,\n catalogInit: 'const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })',\n localeInit: (defaultLocale) => `const [__currentLocale, __setCurrentLocale] = createSignal(
|
|
1
|
+
{"version":3,"file":"vite-plugin.js","names":[],"sources":["../src/solid-runtime.ts","../src/vite-plugin.ts"],"sourcesContent":["import { createRuntimeGenerator } from '@fluenti/vite-plugin'\nimport type { RuntimeGenerator } from '@fluenti/vite-plugin'\n\nexport const solidRuntimeGenerator: RuntimeGenerator = createRuntimeGenerator({\n imports: `import { createSignal } from 'solid-js'\\nimport { createStore, reconcile } from 'solid-js/store'`,\n catalogInit: 'const [__catalog, __setCatalog] = createStore({ ...__defaultMsgs })',\n localeInit: (defaultLocale) => `const [__currentLocale, __setCurrentLocale] = createSignal(${JSON.stringify(defaultLocale)})`,\n loadingInit: 'const [__loading, __setLoading] = createSignal(false)',\n catalogUpdate: (msgs) => `__setCatalog(reconcile(${msgs}))`,\n localeUpdate: (locale) => `__setCurrentLocale(${locale})`,\n loadingUpdate: (value) => `__setLoading(${value})`,\n localeRead: '__currentLocale()',\n runtimeKey: 'fluenti.runtime.solid.v1',\n})\n","import type { Plugin } from 'vite'\nimport type { FluentiPluginOptions } from '@fluenti/vite-plugin'\nimport { createFluentiPlugins } from '@fluenti/vite-plugin'\nimport { solidRuntimeGenerator } from './solid-runtime'\n\nexport type { FluentiPluginOptions as FluentiSolidOptions } from '@fluenti/vite-plugin'\n\n/**\n * Fluenti SolidJS Vite plugin.\n *\n * @example Minimal — no fluenti.config.ts needed\n * ```ts\n * // vite.config.ts\n * import fluentiSolid from '@fluenti/solid/vite-plugin'\n *\n * export default defineConfig({\n * plugins: [fluentiSolid({ config: { locales: ['en', 'ja'] } })],\n * })\n * ```\n *\n * @example With fluenti.config.ts (for advanced options)\n * ```ts\n * export default defineConfig({\n * plugins: [fluentiSolid()], // auto-reads fluenti.config.ts\n * })\n * ```\n */\nexport default function fluentiSolid(options?: FluentiPluginOptions): Plugin[] {\n return createFluentiPlugins(\n { ...(options?.config !== undefined ? { config: options.config } : {}), framework: 'solid' },\n [],\n solidRuntimeGenerator,\n )\n}\n"],"mappings":";;AAGA,IAAa,IAA0C,EAAuB;CAC5E,SAAS;CACT,aAAa;CACb,aAAa,MAAkB,8DAA8D,KAAK,UAAU,EAAc,CAAC;CAC3H,aAAa;CACb,gBAAgB,MAAS,0BAA0B,EAAK;CACxD,eAAe,MAAW,sBAAsB,EAAO;CACvD,gBAAgB,MAAU,gBAAgB,EAAM;CAChD,YAAY;CACZ,YAAY;CACb,CAAC;;;ACcF,SAAwB,EAAa,GAA0C;AAC7E,QAAO,EACL;EAAE,GAAI,GAAS,WAAW,KAAA,IAAyC,EAAE,GAA/B,EAAE,QAAQ,EAAQ,QAAQ;EAAQ,WAAW;EAAS,EAC5F,EAAE,EACF,EACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluenti/solid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SolidJS compile-time i18n — Trans/Plural/Select components, I18nProvider, useI18n",
|
|
6
6
|
"homepage": "https://fluenti.dev",
|
|
@@ -29,53 +29,53 @@
|
|
|
29
29
|
],
|
|
30
30
|
"main": "./dist/index.cjs",
|
|
31
31
|
"module": "./dist/index.js",
|
|
32
|
-
"types": "./dist/index.d.ts",
|
|
32
|
+
"types": "./dist/solid/src/index.d.ts",
|
|
33
33
|
"exports": {
|
|
34
34
|
".": {
|
|
35
35
|
"solid": {
|
|
36
|
-
"types": "./dist/index.d.ts",
|
|
36
|
+
"types": "./dist/solid/src/index.d.ts",
|
|
37
37
|
"default": "./src/index.ts"
|
|
38
38
|
},
|
|
39
39
|
"import": {
|
|
40
|
-
"types": "./dist/index.d.ts",
|
|
40
|
+
"types": "./dist/solid/src/index.d.ts",
|
|
41
41
|
"default": "./dist/index.js"
|
|
42
42
|
},
|
|
43
43
|
"require": {
|
|
44
|
-
"types": "./dist/index.d.ts",
|
|
44
|
+
"types": "./dist/solid/src/index.d.ts",
|
|
45
45
|
"default": "./dist/index.cjs"
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"./server": {
|
|
49
49
|
"import": {
|
|
50
|
-
"types": "./dist/server.d.ts",
|
|
50
|
+
"types": "./dist/solid/src/server.d.ts",
|
|
51
51
|
"default": "./dist/server.js"
|
|
52
52
|
},
|
|
53
53
|
"require": {
|
|
54
|
-
"types": "./dist/server.d.ts",
|
|
54
|
+
"types": "./dist/solid/src/server.d.ts",
|
|
55
55
|
"default": "./dist/server.cjs"
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
58
|
"./components": {
|
|
59
59
|
"solid": {
|
|
60
|
-
"types": "./dist/components-entry.d.ts",
|
|
60
|
+
"types": "./dist/solid/src/components-entry.d.ts",
|
|
61
61
|
"default": "./src/components-entry.ts"
|
|
62
62
|
},
|
|
63
63
|
"import": {
|
|
64
|
-
"types": "./dist/components-entry.d.ts",
|
|
64
|
+
"types": "./dist/solid/src/components-entry.d.ts",
|
|
65
65
|
"default": "./dist/components-entry.js"
|
|
66
66
|
},
|
|
67
67
|
"require": {
|
|
68
|
-
"types": "./dist/components-entry.d.ts",
|
|
68
|
+
"types": "./dist/solid/src/components-entry.d.ts",
|
|
69
69
|
"default": "./dist/components-entry.cjs"
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"./vite-plugin": {
|
|
73
73
|
"import": {
|
|
74
|
-
"types": "./dist/vite-plugin.d.ts",
|
|
74
|
+
"types": "./dist/solid/src/vite-plugin.d.ts",
|
|
75
75
|
"default": "./dist/vite-plugin.js"
|
|
76
76
|
},
|
|
77
77
|
"require": {
|
|
78
|
-
"types": "./dist/vite-plugin.d.ts",
|
|
78
|
+
"types": "./dist/solid/src/vite-plugin.d.ts",
|
|
79
79
|
"default": "./dist/vite-plugin.cjs"
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -95,8 +95,8 @@
|
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"@fluenti/
|
|
99
|
-
"@fluenti/
|
|
98
|
+
"@fluenti/vite-plugin": "0.6.0",
|
|
99
|
+
"@fluenti/core": "0.6.0"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@solidjs/testing-library": "^0.8",
|
package/src/compiled.tsx
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { Component, JSX } from 'solid-js'
|
|
2
|
+
import { Dynamic } from 'solid-js/web'
|
|
3
|
+
import { hashMessage } from '@fluenti/core/runtime'
|
|
4
|
+
import { useI18n } from './use-i18n'
|
|
5
|
+
import { resolveCompiledMessageId } from './plain-runtime'
|
|
6
|
+
import { reconstruct } from './rich-dom'
|
|
7
|
+
|
|
8
|
+
export interface FluentiCompiledTransProps {
|
|
9
|
+
message: string
|
|
10
|
+
components?: JSX.Element[]
|
|
11
|
+
id?: string
|
|
12
|
+
context?: string
|
|
13
|
+
comment?: string
|
|
14
|
+
tag?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface FluentiCompiledPluralProps {
|
|
18
|
+
value: number
|
|
19
|
+
message: string
|
|
20
|
+
id?: string
|
|
21
|
+
context?: string
|
|
22
|
+
comment?: string
|
|
23
|
+
tag?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface FluentiCompiledSelectProps {
|
|
27
|
+
value: string
|
|
28
|
+
message: string
|
|
29
|
+
valueMap?: Record<string, string>
|
|
30
|
+
id?: string
|
|
31
|
+
context?: string
|
|
32
|
+
comment?: string
|
|
33
|
+
tag?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface FluentiCompiledRichPluralProps extends FluentiCompiledPluralProps {
|
|
37
|
+
components: JSX.Element[]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface FluentiCompiledRichSelectProps extends FluentiCompiledSelectProps {
|
|
41
|
+
components: JSX.Element[]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @internal Build-plugin fast path for compiled `<Trans>` usage. */
|
|
45
|
+
export const __FluentiCompiledTrans: Component<FluentiCompiledTransProps> = (props) => {
|
|
46
|
+
const { t } = useI18n()
|
|
47
|
+
|
|
48
|
+
return (() => {
|
|
49
|
+
const translated = t({
|
|
50
|
+
id: props.id ?? hashMessage(props.message, props.context),
|
|
51
|
+
message: props.message,
|
|
52
|
+
...(props.context !== undefined ? { context: props.context } : {}),
|
|
53
|
+
...(props.comment !== undefined ? { comment: props.comment } : {}),
|
|
54
|
+
})
|
|
55
|
+
const result = props.components && props.components.length > 0
|
|
56
|
+
? reconstruct(translated, props.components as unknown as Node[])
|
|
57
|
+
: translated
|
|
58
|
+
|
|
59
|
+
if (props.tag) {
|
|
60
|
+
return (<Dynamic component={props.tag}>{result}</Dynamic>) as JSX.Element
|
|
61
|
+
}
|
|
62
|
+
return (<>{result}</>) as unknown as JSX.Element
|
|
63
|
+
}) as unknown as JSX.Element
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @internal Build-plugin fast path for plain-text `<Plural>` usage. */
|
|
67
|
+
export const __FluentiCompiledPlural: Component<FluentiCompiledPluralProps> = (props) => {
|
|
68
|
+
const { t } = useI18n()
|
|
69
|
+
|
|
70
|
+
return (() => {
|
|
71
|
+
const translated = t(
|
|
72
|
+
{
|
|
73
|
+
id: resolveCompiledMessageId(props.id, props.message, props.context),
|
|
74
|
+
message: props.message,
|
|
75
|
+
...(props.context !== undefined ? { context: props.context } : {}),
|
|
76
|
+
...(props.comment !== undefined ? { comment: props.comment } : {}),
|
|
77
|
+
},
|
|
78
|
+
{ count: props.value },
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
if (props.tag) {
|
|
82
|
+
return (<Dynamic component={props.tag}>{translated}</Dynamic>) as JSX.Element
|
|
83
|
+
}
|
|
84
|
+
return (<>{translated}</>) as JSX.Element
|
|
85
|
+
}) as unknown as JSX.Element
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** @internal Build-plugin fast path for plain-text `<Select>` usage. */
|
|
89
|
+
export const __FluentiCompiledSelect: Component<FluentiCompiledSelectProps> = (props) => {
|
|
90
|
+
const { t } = useI18n()
|
|
91
|
+
|
|
92
|
+
return (() => {
|
|
93
|
+
const translated = t(
|
|
94
|
+
{
|
|
95
|
+
id: resolveCompiledMessageId(props.id, props.message, props.context),
|
|
96
|
+
message: props.message,
|
|
97
|
+
...(props.context !== undefined ? { context: props.context } : {}),
|
|
98
|
+
...(props.comment !== undefined ? { comment: props.comment } : {}),
|
|
99
|
+
},
|
|
100
|
+
{ value: props.valueMap?.[props.value] ?? 'other' },
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
if (props.tag) {
|
|
104
|
+
return (<Dynamic component={props.tag}>{translated}</Dynamic>) as JSX.Element
|
|
105
|
+
}
|
|
106
|
+
return (<>{translated}</>) as JSX.Element
|
|
107
|
+
}) as unknown as JSX.Element
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** @internal Build-plugin fast path for rich-text `<Plural>` usage. */
|
|
111
|
+
export const __FluentiCompiledRichPlural: Component<FluentiCompiledRichPluralProps> = (props) => {
|
|
112
|
+
const { t } = useI18n()
|
|
113
|
+
|
|
114
|
+
return (() => {
|
|
115
|
+
const translated = t(
|
|
116
|
+
{
|
|
117
|
+
id: resolveCompiledMessageId(props.id, props.message, props.context),
|
|
118
|
+
message: props.message,
|
|
119
|
+
...(props.context !== undefined ? { context: props.context } : {}),
|
|
120
|
+
...(props.comment !== undefined ? { comment: props.comment } : {}),
|
|
121
|
+
},
|
|
122
|
+
{ count: props.value },
|
|
123
|
+
)
|
|
124
|
+
const result = props.components.length > 0
|
|
125
|
+
? reconstruct(translated, props.components as unknown as Node[])
|
|
126
|
+
: translated
|
|
127
|
+
|
|
128
|
+
if (props.tag) {
|
|
129
|
+
return (<Dynamic component={props.tag}>{result}</Dynamic>) as JSX.Element
|
|
130
|
+
}
|
|
131
|
+
return (<>{result}</>) as JSX.Element
|
|
132
|
+
}) as unknown as JSX.Element
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** @internal Build-plugin fast path for rich-text `<Select>` usage. */
|
|
136
|
+
export const __FluentiCompiledRichSelect: Component<FluentiCompiledRichSelectProps> = (props) => {
|
|
137
|
+
const { t } = useI18n()
|
|
138
|
+
|
|
139
|
+
return (() => {
|
|
140
|
+
const translated = t(
|
|
141
|
+
{
|
|
142
|
+
id: resolveCompiledMessageId(props.id, props.message, props.context),
|
|
143
|
+
message: props.message,
|
|
144
|
+
...(props.context !== undefined ? { context: props.context } : {}),
|
|
145
|
+
...(props.comment !== undefined ? { comment: props.comment } : {}),
|
|
146
|
+
},
|
|
147
|
+
{ value: props.valueMap?.[props.value] ?? 'other' },
|
|
148
|
+
)
|
|
149
|
+
const result = props.components.length > 0
|
|
150
|
+
? reconstruct(translated, props.components as unknown as Node[])
|
|
151
|
+
: translated
|
|
152
|
+
|
|
153
|
+
if (props.tag) {
|
|
154
|
+
return (<Dynamic component={props.tag}>{result}</Dynamic>) as JSX.Element
|
|
155
|
+
}
|
|
156
|
+
return (<>{result}</>) as JSX.Element
|
|
157
|
+
}) as unknown as JSX.Element
|
|
158
|
+
}
|
package/src/components-entry.ts
CHANGED
|
@@ -8,6 +8,10 @@ export { DateTime } from './components/DateTime'
|
|
|
8
8
|
export type { DateTimeProps, FluentiDateTimeProps } from './components/DateTime'
|
|
9
9
|
export { NumberFormat } from './components/NumberFormat'
|
|
10
10
|
export type { NumberProps, FluentiNumberFormatProps } from './components/NumberFormat'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export {
|
|
12
|
+
__FluentiCompiledTrans,
|
|
13
|
+
__FluentiCompiledPlural,
|
|
14
|
+
__FluentiCompiledSelect,
|
|
15
|
+
__FluentiCompiledRichPlural,
|
|
16
|
+
__FluentiCompiledRichSelect,
|
|
17
|
+
} from './compiled'
|
package/src/context.ts
CHANGED
|
@@ -78,7 +78,7 @@ export interface FluentiConfig extends FluentiCoreConfig {
|
|
|
78
78
|
* Custom message interpolation function.
|
|
79
79
|
*
|
|
80
80
|
* By default, the runtime uses a lightweight `{key}` replacer.
|
|
81
|
-
* Pass the full `interpolate` from `@fluenti/core/
|
|
81
|
+
* Pass the full `interpolate` from `@fluenti/core/runtime` for
|
|
82
82
|
* runtime ICU MessageFormat support (plurals, selects, nested arguments).
|
|
83
83
|
*/
|
|
84
84
|
interpolate?: (
|
|
@@ -129,10 +129,10 @@ export interface FluentiContext {
|
|
|
129
129
|
*
|
|
130
130
|
* @example
|
|
131
131
|
* ```tsx
|
|
132
|
-
* import {
|
|
132
|
+
* import { createFluenti } from '@fluenti/solid'
|
|
133
133
|
* import messages from './locales/compiled/en.js'
|
|
134
134
|
*
|
|
135
|
-
* const ctx =
|
|
135
|
+
* const ctx = createFluenti({
|
|
136
136
|
* locale: 'en',
|
|
137
137
|
* messages: { en: messages },
|
|
138
138
|
* })
|
|
@@ -298,3 +298,5 @@ export function createFluentiContext(config: FluentiCoreConfig | FluentiConfig):
|
|
|
298
298
|
|
|
299
299
|
return { locale, setLocale, t, loadMessages, getLocales, d, n, format, isLoading, loadedLocales, preloadLocale, te, tm }
|
|
300
300
|
}
|
|
301
|
+
|
|
302
|
+
export const createFluenti = createFluentiContext
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createFluenti } from './context'
|
|
2
2
|
export type { FluentiContext, FluentiConfig } from './context'
|
|
3
3
|
export { I18nProvider } from './provider'
|
|
4
4
|
export { useI18n, useLocale } from './use-i18n'
|
|
5
5
|
export { t } from './compile-time-t'
|
|
6
|
+
export { Trans, Plural, Select, DateTime, NumberFormat } from './components-entry'
|
|
7
|
+
export type {
|
|
8
|
+
FluentiTransProps,
|
|
9
|
+
FluentiPluralProps,
|
|
10
|
+
FluentiSelectProps,
|
|
11
|
+
DateTimeProps,
|
|
12
|
+
FluentiDateTimeProps,
|
|
13
|
+
NumberProps,
|
|
14
|
+
FluentiNumberFormatProps,
|
|
15
|
+
} from './components-entry'
|
|
6
16
|
export { msg } from './msg'
|
|
7
|
-
|
|
8
|
-
// Components moved to @fluenti/solid/components:
|
|
9
|
-
// import { Trans, Plural, Select, DateTime, NumberFormat } from '@fluenti/solid/components'
|
|
10
|
-
export type { FluentiTransProps } from './trans'
|
|
11
|
-
export type { FluentiPluralProps } from './plural'
|
|
12
|
-
export type { FluentiSelectProps } from './select'
|
|
13
|
-
export type { DateTimeProps, FluentiDateTimeProps } from './components/DateTime'
|
|
14
|
-
export type { NumberProps, FluentiNumberFormatProps } from './components/NumberFormat'
|
|
15
|
-
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PLURAL_CATEGORIES,
|
|
3
|
+
buildICUPluralMessage,
|
|
4
|
+
buildICUSelectMessage,
|
|
5
|
+
hashMessage,
|
|
6
|
+
normalizeSelectForms,
|
|
7
|
+
type PluralCategory,
|
|
8
|
+
} from '@fluenti/core/runtime'
|
|
9
|
+
|
|
10
|
+
export function resolvePropValue(value: unknown): unknown {
|
|
11
|
+
if (typeof value === 'function' && !(value as { length?: number }).length) {
|
|
12
|
+
return (value as () => unknown)()
|
|
13
|
+
}
|
|
14
|
+
return value
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function resolveCompiledMessageId(
|
|
18
|
+
id: string | undefined,
|
|
19
|
+
message: string,
|
|
20
|
+
context: string | undefined,
|
|
21
|
+
): string {
|
|
22
|
+
return id ?? (context === undefined ? message : hashMessage(message, context))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isPlainTextValue(value: unknown): value is string | number {
|
|
26
|
+
return typeof value === 'string' || typeof value === 'number'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function buildPlainPluralMessage(
|
|
30
|
+
forms: Partial<Record<PluralCategory, unknown>>,
|
|
31
|
+
offset?: number,
|
|
32
|
+
): string | undefined {
|
|
33
|
+
const plainForms: Partial<Record<PluralCategory, string>> = {}
|
|
34
|
+
|
|
35
|
+
for (const category of PLURAL_CATEGORIES) {
|
|
36
|
+
const resolved = resolvePropValue(forms[category])
|
|
37
|
+
if (resolved === undefined) continue
|
|
38
|
+
if (!isPlainTextValue(resolved)) return undefined
|
|
39
|
+
plainForms[category] = String(resolved)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (plainForms['other'] === undefined) return undefined
|
|
43
|
+
return buildICUPluralMessage(plainForms as Partial<Record<PluralCategory, string>> & { other: string }, offset)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function buildPlainSelectMessage(
|
|
47
|
+
forms: Record<string, unknown>,
|
|
48
|
+
): { message: string; valueMap: Record<string, string> } | undefined {
|
|
49
|
+
const plainForms: Record<string, string> = {}
|
|
50
|
+
|
|
51
|
+
for (const [key, value] of Object.entries(forms)) {
|
|
52
|
+
const resolved = resolvePropValue(value)
|
|
53
|
+
if (resolved === undefined) continue
|
|
54
|
+
if (!isPlainTextValue(resolved)) return undefined
|
|
55
|
+
plainForms[key] = String(resolved)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (plainForms['other'] === undefined) return undefined
|
|
59
|
+
|
|
60
|
+
const normalized = normalizeSelectForms(plainForms)
|
|
61
|
+
return {
|
|
62
|
+
message: buildICUSelectMessage(normalized.forms),
|
|
63
|
+
valueMap: normalized.valueMap,
|
|
64
|
+
}
|
|
65
|
+
}
|