@linguanahq/solid 0.1.0 → 0.1.2

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.
@@ -0,0 +1,10 @@
1
+ export { T as LinguanaMessage, T as default } from ".";
2
+ import type { JSX } from "solid-js";
3
+ export declare function LinguanaAttributes(props: {
4
+ descriptors: Array<{
5
+ name: string;
6
+ id: string;
7
+ defaultMessage: string;
8
+ }>;
9
+ children: (values: Record<string, string>) => JSX.Element;
10
+ }): JSX.Element;
@@ -0,0 +1,66 @@
1
+ // src/index.tsx
2
+ import { template as _$template } from "solid-js/web";
3
+ import { delegateEvents as _$delegateEvents } from "solid-js/web";
4
+ import { getNextMarker as _$getNextMarker } from "solid-js/web";
5
+ import { setAttribute as _$setAttribute } from "solid-js/web";
6
+ import { className as _$className } from "solid-js/web";
7
+ import { getNextElement as _$getNextElement } from "solid-js/web";
8
+ import { runHydrationEvents as _$runHydrationEvents } from "solid-js/web";
9
+ import { setProperty as _$setProperty } from "solid-js/web";
10
+ import { effect as _$effect } from "solid-js/web";
11
+ import { insert as _$insert } from "solid-js/web";
12
+ import { memo as _$memo } from "solid-js/web";
13
+ import { createComponent as _$createComponent } from "solid-js/web";
14
+ import { bindLocaleAttributes, createLinguanaClient } from "@linguanahq/core";
15
+ import { createContext, createMemo, createSignal, For, onCleanup, onMount, useContext } from "solid-js";
16
+ import { createFormatters, getLocaleAttributes } from "@linguanahq/core";
17
+ var LinguanaContext = createContext();
18
+ function useTranslation() {
19
+ const client = useContext(LinguanaContext);
20
+ if (!client) throw new Error("useTranslation must be used within LinguanaProvider");
21
+ const [snapshot, setSnapshot] = createSignal(client.getSnapshot());
22
+ const unsubscribe = client.subscribe(() => setSnapshot(client.getSnapshot()));
23
+ onCleanup(unsubscribe);
24
+ return {
25
+ snapshot,
26
+ formatters: () => {
27
+ snapshot();
28
+ return client.getFormatters();
29
+ },
30
+ locale: () => snapshot().locale,
31
+ ready: () => snapshot().ready,
32
+ availableLocales: () => snapshot().availableLocales,
33
+ setLocale: client.setLocale,
34
+ t: (...args) => {
35
+ snapshot();
36
+ return client.t(...args);
37
+ },
38
+ translate: (...args) => {
39
+ snapshot();
40
+ return client.translate(...args);
41
+ }
42
+ };
43
+ }
44
+ function T(props) {
45
+ const runtime = useTranslation();
46
+ return createMemo(() => runtime.translate(props.id, props.defaultMessage, props.values));
47
+ }
48
+ _$delegateEvents(["input"]);
49
+
50
+ // src/compiler-runtime.tsx
51
+ function LinguanaAttributes(props) {
52
+ const runtime = useTranslation();
53
+ const values = {};
54
+ for (const item of props.descriptors) {
55
+ Object.defineProperty(values, item.name, {
56
+ enumerable: true,
57
+ get: () => String(runtime.translate(item.id, item.defaultMessage))
58
+ });
59
+ }
60
+ return props.children(values);
61
+ }
62
+ export {
63
+ LinguanaAttributes,
64
+ T as LinguanaMessage,
65
+ T as default
66
+ };
@@ -0,0 +1,140 @@
1
+ // src/index.tsx
2
+ import { template as _$template } from "solid-js/web";
3
+ import { delegateEvents as _$delegateEvents } from "solid-js/web";
4
+ import { getNextMarker as _$getNextMarker } from "solid-js/web";
5
+ import { setAttribute as _$setAttribute } from "solid-js/web";
6
+ import { className as _$className } from "solid-js/web";
7
+ import { getNextElement as _$getNextElement } from "solid-js/web";
8
+ import { runHydrationEvents as _$runHydrationEvents } from "solid-js/web";
9
+ import { setProperty as _$setProperty } from "solid-js/web";
10
+ import { effect as _$effect } from "solid-js/web";
11
+ import { insert as _$insert } from "solid-js/web";
12
+ import { memo as _$memo } from "solid-js/web";
13
+ import { createComponent as _$createComponent } from "solid-js/web";
14
+ import { bindLocaleAttributes, createLinguanaClient } from "@linguanahq/core";
15
+ import { createContext, createMemo, createSignal, For, onCleanup, onMount, useContext } from "solid-js";
16
+ import { createFormatters, getLocaleAttributes } from "@linguanahq/core";
17
+ var _tmpl$ = /* @__PURE__ */ _$template(`<div data-linguana-language-selector><label><span></span><input type=search placeholder="Search languages"></label><select>`);
18
+ var _tmpl$2 = /* @__PURE__ */ _$template(`<option><!$><!/> \u2014 <!$><!/><!$><!/>`);
19
+ var LinguanaContext = createContext();
20
+ function LinguanaProvider(props) {
21
+ const parent = useContext(LinguanaContext);
22
+ const client = createLinguanaClient(props);
23
+ onMount(() => {
24
+ void client.loadRuntimeConfig();
25
+ if (props.manageDocumentLocale !== false && (!parent || props.localeRoot)) {
26
+ const unbind = bindLocaleAttributes(client.getSnapshot, client.subscribe, props.localeRoot);
27
+ onCleanup(unbind);
28
+ }
29
+ void client.setLocale(client.getSnapshot().locale);
30
+ });
31
+ onCleanup(() => client.dispose());
32
+ return _$createComponent(LinguanaContext.Provider, {
33
+ value: client,
34
+ get children() {
35
+ return props.children;
36
+ }
37
+ });
38
+ }
39
+ function useTranslation() {
40
+ const client = useContext(LinguanaContext);
41
+ if (!client) throw new Error("useTranslation must be used within LinguanaProvider");
42
+ const [snapshot, setSnapshot] = createSignal(client.getSnapshot());
43
+ const unsubscribe = client.subscribe(() => setSnapshot(client.getSnapshot()));
44
+ onCleanup(unsubscribe);
45
+ return {
46
+ snapshot,
47
+ formatters: () => {
48
+ snapshot();
49
+ return client.getFormatters();
50
+ },
51
+ locale: () => snapshot().locale,
52
+ ready: () => snapshot().ready,
53
+ availableLocales: () => snapshot().availableLocales,
54
+ setLocale: client.setLocale,
55
+ t: (...args) => {
56
+ snapshot();
57
+ return client.t(...args);
58
+ },
59
+ translate: (...args) => {
60
+ snapshot();
61
+ return client.translate(...args);
62
+ }
63
+ };
64
+ }
65
+ function useLocaleOptions(query = () => "") {
66
+ const runtime = useTranslation();
67
+ const options = createMemo(() => {
68
+ const normalized = query().trim().toLocaleLowerCase();
69
+ return runtime.availableLocales().filter((item) => !normalized || `${item.code} ${item.displayName} ${item.nativeName}`.toLocaleLowerCase().includes(normalized)).sort((a, b) => a.displayName.localeCompare(b.displayName));
70
+ });
71
+ return {
72
+ ...runtime,
73
+ options
74
+ };
75
+ }
76
+ function T(props) {
77
+ const runtime = useTranslation();
78
+ return createMemo(() => runtime.translate(props.id, props.defaultMessage, props.values));
79
+ }
80
+ function LanguageSelector(props) {
81
+ const [query, setQuery] = createSignal("");
82
+ const runtime = useLocaleOptions(query);
83
+ return (() => {
84
+ var _el$ = _$getNextElement(_tmpl$), _el$2 = _el$.firstChild, _el$3 = _el$2.firstChild, _el$4 = _el$3.nextSibling, _el$5 = _el$2.nextSibling;
85
+ _$insert(_el$3, () => props.label ?? "Language");
86
+ _el$4.$$input = (event) => setQuery(event.currentTarget.value);
87
+ _el$5.addEventListener("change", (event) => void runtime.setLocale(event.currentTarget.value));
88
+ _$insert(_el$5, _$createComponent(For, {
89
+ get each() {
90
+ return runtime.options();
91
+ },
92
+ children: (item) => (() => {
93
+ var _el$6 = _$getNextElement(_tmpl$2), _el$8 = _el$6.firstChild, [_el$9, _co$] = _$getNextMarker(_el$8.nextSibling), _el$7 = _el$9.nextSibling, _el$0 = _el$7.nextSibling, [_el$1, _co$2] = _$getNextMarker(_el$0.nextSibling), _el$10 = _el$1.nextSibling, [_el$11, _co$3] = _$getNextMarker(_el$10.nextSibling);
94
+ _$insert(_el$6, () => item.nativeName, _el$9, _co$);
95
+ _$insert(_el$6, () => item.displayName, _el$1, _co$2);
96
+ _$insert(_el$6, () => item.tier === "PREVIEW" ? " (Preview)" : "", _el$11, _co$3);
97
+ _$effect(() => _$setProperty(_el$6, "value", item.code));
98
+ return _el$6;
99
+ })()
100
+ }));
101
+ _$effect((_p$) => {
102
+ var _v$ = props.class, _v$2 = props.label ?? "Language", _v$3 = !runtime.ready();
103
+ _v$ !== _p$.e && _$className(_el$, _p$.e = _v$);
104
+ _v$2 !== _p$.t && _$setAttribute(_el$5, "aria-label", _p$.t = _v$2);
105
+ _v$3 !== _p$.a && _$setProperty(_el$5, "disabled", _p$.a = _v$3);
106
+ return _p$;
107
+ }, {
108
+ e: void 0,
109
+ t: void 0,
110
+ a: void 0
111
+ });
112
+ _$effect(() => _$setProperty(_el$4, "value", query()));
113
+ _$effect(() => _$setProperty(_el$5, "value", runtime.locale()));
114
+ _$runHydrationEvents();
115
+ return _el$;
116
+ })();
117
+ }
118
+ function useFormatters() {
119
+ return useTranslation().formatters;
120
+ }
121
+ function useRuntimeContent(client, value, fields) {
122
+ const [revision, setRevision] = createSignal(client.getSnapshot());
123
+ onCleanup(client.subscribe(() => setRevision(client.getSnapshot())));
124
+ return createMemo(() => {
125
+ revision();
126
+ return client.localize(value(), fields);
127
+ });
128
+ }
129
+ _$delegateEvents(["input"]);
130
+ export {
131
+ LanguageSelector,
132
+ LinguanaProvider,
133
+ T,
134
+ createFormatters,
135
+ getLocaleAttributes,
136
+ useFormatters,
137
+ useLocaleOptions,
138
+ useRuntimeContent,
139
+ useTranslation
140
+ };
@@ -0,0 +1,93 @@
1
+ import { type LinguanaClient, type LinguanaClientOptions } from "@linguanahq/core";
2
+ import { type JSX, type ParentProps } from "solid-js";
3
+ export declare function LinguanaProvider(props: ParentProps<LinguanaClientOptions>): JSX.Element;
4
+ export declare function useTranslation(): {
5
+ snapshot: import("solid-js").Accessor<import("@linguanahq/core").LinguanaSnapshot>;
6
+ formatters: () => {
7
+ locale: string;
8
+ timeZone: string;
9
+ formatNumber: (value: number | bigint, options?: Intl.NumberFormatOptions) => string;
10
+ formatNumberToParts: (value: number | bigint, options?: Intl.NumberFormatOptions) => Intl.NumberFormatPart[];
11
+ formatCurrency: (value: number | bigint, currency: string, options?: Intl.NumberFormatOptions) => string;
12
+ formatCurrencyToParts: (value: number | bigint, currency: string, options?: Intl.NumberFormatOptions) => Intl.NumberFormatPart[];
13
+ formatDateTime: (value: Date | number, options?: Intl.DateTimeFormatOptions) => string;
14
+ formatDateTimeToParts: (value: Date | number, options?: Intl.DateTimeFormatOptions) => Intl.DateTimeFormatPart[];
15
+ formatRelativeTime: (value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions) => string;
16
+ formatRelativeTimeToParts: (value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions) => Intl.RelativeTimeFormatPart[];
17
+ formatList: (values: string[], options?: Intl.ListFormatOptions) => string;
18
+ formatListToParts: (values: string[], options?: Intl.ListFormatOptions) => {
19
+ type: "element" | "literal";
20
+ value: string;
21
+ }[];
22
+ selectPlural: (value: number, options?: Intl.PluralRulesOptions) => Intl.LDMLPluralRule;
23
+ };
24
+ locale: () => string;
25
+ ready: () => boolean;
26
+ availableLocales: () => readonly import("@linguanahq/core").LocaleOption[];
27
+ setLocale: (locale: string) => Promise<void>;
28
+ t: LinguanaClient["t"];
29
+ translate: LinguanaClient["translate"];
30
+ };
31
+ export declare function useLocaleOptions(query?: () => string): {
32
+ options: import("solid-js").Accessor<import("@linguanahq/core").LocaleOption[]>;
33
+ snapshot: import("solid-js").Accessor<import("@linguanahq/core").LinguanaSnapshot>;
34
+ formatters: () => {
35
+ locale: string;
36
+ timeZone: string;
37
+ formatNumber: (value: number | bigint, options?: Intl.NumberFormatOptions) => string;
38
+ formatNumberToParts: (value: number | bigint, options?: Intl.NumberFormatOptions) => Intl.NumberFormatPart[];
39
+ formatCurrency: (value: number | bigint, currency: string, options?: Intl.NumberFormatOptions) => string;
40
+ formatCurrencyToParts: (value: number | bigint, currency: string, options?: Intl.NumberFormatOptions) => Intl.NumberFormatPart[];
41
+ formatDateTime: (value: Date | number, options?: Intl.DateTimeFormatOptions) => string;
42
+ formatDateTimeToParts: (value: Date | number, options?: Intl.DateTimeFormatOptions) => Intl.DateTimeFormatPart[];
43
+ formatRelativeTime: (value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions) => string;
44
+ formatRelativeTimeToParts: (value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions) => Intl.RelativeTimeFormatPart[];
45
+ formatList: (values: string[], options?: Intl.ListFormatOptions) => string;
46
+ formatListToParts: (values: string[], options?: Intl.ListFormatOptions) => {
47
+ type: "element" | "literal";
48
+ value: string;
49
+ }[];
50
+ selectPlural: (value: number, options?: Intl.PluralRulesOptions) => Intl.LDMLPluralRule;
51
+ };
52
+ locale: () => string;
53
+ ready: () => boolean;
54
+ availableLocales: () => readonly import("@linguanahq/core").LocaleOption[];
55
+ setLocale: (locale: string) => Promise<void>;
56
+ t: LinguanaClient["t"];
57
+ translate: LinguanaClient["translate"];
58
+ };
59
+ export declare function T(props: {
60
+ id: string;
61
+ defaultMessage: string;
62
+ values?: Record<string, unknown>;
63
+ }): JSX.Element;
64
+ export declare function LanguageSelector(props: {
65
+ label?: string;
66
+ class?: string;
67
+ }): JSX.Element;
68
+ export type { LinguanaClient, LinguanaClientOptions } from "@linguanahq/core";
69
+ export declare function useFormatters(): () => {
70
+ locale: string;
71
+ timeZone: string;
72
+ formatNumber: (value: number | bigint, options?: Intl.NumberFormatOptions) => string;
73
+ formatNumberToParts: (value: number | bigint, options?: Intl.NumberFormatOptions) => Intl.NumberFormatPart[];
74
+ formatCurrency: (value: number | bigint, currency: string, options?: Intl.NumberFormatOptions) => string;
75
+ formatCurrencyToParts: (value: number | bigint, currency: string, options?: Intl.NumberFormatOptions) => Intl.NumberFormatPart[];
76
+ formatDateTime: (value: Date | number, options?: Intl.DateTimeFormatOptions) => string;
77
+ formatDateTimeToParts: (value: Date | number, options?: Intl.DateTimeFormatOptions) => Intl.DateTimeFormatPart[];
78
+ formatRelativeTime: (value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions) => string;
79
+ formatRelativeTimeToParts: (value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions) => Intl.RelativeTimeFormatPart[];
80
+ formatList: (values: string[], options?: Intl.ListFormatOptions) => string;
81
+ formatListToParts: (values: string[], options?: Intl.ListFormatOptions) => {
82
+ type: "element" | "literal";
83
+ value: string;
84
+ }[];
85
+ selectPlural: (value: number, options?: Intl.PluralRulesOptions) => Intl.LDMLPluralRule;
86
+ };
87
+ export { createFormatters, getLocaleAttributes } from "@linguanahq/core";
88
+ export declare function useRuntimeContent<T extends Record<string, unknown>>(client: import("@linguanahq/core/runtime").RuntimeClient, value: () => T, fields: readonly import("@linguanahq/core/runtime").RuntimeField<T>[]): import("solid-js").Accessor<{
89
+ value: T;
90
+ fields: Record<string, import("@linguanahq/core/runtime").RuntimeEntry | {
91
+ state: "skipped";
92
+ }>;
93
+ }>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ // src/index.tsx
2
+ import { ssr as _$ssr } from "solid-js/web";
3
+ import { ssrAttribute as _$ssrAttribute } from "solid-js/web";
4
+ import { escape as _$escape } from "solid-js/web";
5
+ import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web";
6
+ import { createComponent as _$createComponent } from "solid-js/web";
7
+ import { bindLocaleAttributes, createLinguanaClient } from "@linguanahq/core";
8
+ import { createContext, createMemo, createSignal, For, onCleanup, onMount, useContext } from "solid-js";
9
+ import { createFormatters, getLocaleAttributes } from "@linguanahq/core";
10
+ var LinguanaContext = createContext();
11
+ function useTranslation() {
12
+ const client = useContext(LinguanaContext);
13
+ if (!client) throw new Error("useTranslation must be used within LinguanaProvider");
14
+ const [snapshot, setSnapshot] = createSignal(client.getSnapshot());
15
+ const unsubscribe = client.subscribe(() => setSnapshot(client.getSnapshot()));
16
+ onCleanup(unsubscribe);
17
+ return {
18
+ snapshot,
19
+ formatters: () => {
20
+ snapshot();
21
+ return client.getFormatters();
22
+ },
23
+ locale: () => snapshot().locale,
24
+ ready: () => snapshot().ready,
25
+ availableLocales: () => snapshot().availableLocales,
26
+ setLocale: client.setLocale,
27
+ t: (...args) => {
28
+ snapshot();
29
+ return client.t(...args);
30
+ },
31
+ translate: (...args) => {
32
+ snapshot();
33
+ return client.translate(...args);
34
+ }
35
+ };
36
+ }
37
+ function T(props) {
38
+ const runtime = useTranslation();
39
+ return createMemo(() => runtime.translate(props.id, props.defaultMessage, props.values));
40
+ }
41
+
42
+ // src/compiler-runtime.tsx
43
+ function LinguanaAttributes(props) {
44
+ const runtime = useTranslation();
45
+ const values = {};
46
+ for (const item of props.descriptors) {
47
+ Object.defineProperty(values, item.name, {
48
+ enumerable: true,
49
+ get: () => String(runtime.translate(item.id, item.defaultMessage))
50
+ });
51
+ }
52
+ return props.children(values);
53
+ }
54
+ export {
55
+ LinguanaAttributes,
56
+ T as LinguanaMessage,
57
+ T as default
58
+ };
@@ -0,0 +1,104 @@
1
+ // src/index.tsx
2
+ import { ssr as _$ssr } from "solid-js/web";
3
+ import { ssrAttribute as _$ssrAttribute } from "solid-js/web";
4
+ import { escape as _$escape } from "solid-js/web";
5
+ import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web";
6
+ import { createComponent as _$createComponent } from "solid-js/web";
7
+ import { bindLocaleAttributes, createLinguanaClient } from "@linguanahq/core";
8
+ import { createContext, createMemo, createSignal, For, onCleanup, onMount, useContext } from "solid-js";
9
+ import { createFormatters, getLocaleAttributes } from "@linguanahq/core";
10
+ var _tmpl$ = ["<div", " data-linguana-language-selector><label><span>", '</span><input type="search"', ' placeholder="Search languages"></label><select', "", ">", "</select></div>"];
11
+ var _tmpl$2 = ["<option", "><!--$-->", "<!--/--> \u2014 <!--$-->", "<!--/--><!--$-->", "<!--/--></option>"];
12
+ var LinguanaContext = createContext();
13
+ function LinguanaProvider(props) {
14
+ const parent = useContext(LinguanaContext);
15
+ const client = createLinguanaClient(props);
16
+ onMount(() => {
17
+ void client.loadRuntimeConfig();
18
+ if (props.manageDocumentLocale !== false && (!parent || props.localeRoot)) {
19
+ const unbind = bindLocaleAttributes(client.getSnapshot, client.subscribe, props.localeRoot);
20
+ onCleanup(unbind);
21
+ }
22
+ void client.setLocale(client.getSnapshot().locale);
23
+ });
24
+ onCleanup(() => client.dispose());
25
+ return _$createComponent(LinguanaContext.Provider, {
26
+ value: client,
27
+ get children() {
28
+ return props.children;
29
+ }
30
+ });
31
+ }
32
+ function useTranslation() {
33
+ const client = useContext(LinguanaContext);
34
+ if (!client) throw new Error("useTranslation must be used within LinguanaProvider");
35
+ const [snapshot, setSnapshot] = createSignal(client.getSnapshot());
36
+ const unsubscribe = client.subscribe(() => setSnapshot(client.getSnapshot()));
37
+ onCleanup(unsubscribe);
38
+ return {
39
+ snapshot,
40
+ formatters: () => {
41
+ snapshot();
42
+ return client.getFormatters();
43
+ },
44
+ locale: () => snapshot().locale,
45
+ ready: () => snapshot().ready,
46
+ availableLocales: () => snapshot().availableLocales,
47
+ setLocale: client.setLocale,
48
+ t: (...args) => {
49
+ snapshot();
50
+ return client.t(...args);
51
+ },
52
+ translate: (...args) => {
53
+ snapshot();
54
+ return client.translate(...args);
55
+ }
56
+ };
57
+ }
58
+ function useLocaleOptions(query = () => "") {
59
+ const runtime = useTranslation();
60
+ const options = createMemo(() => {
61
+ const normalized = query().trim().toLocaleLowerCase();
62
+ return runtime.availableLocales().filter((item) => !normalized || `${item.code} ${item.displayName} ${item.nativeName}`.toLocaleLowerCase().includes(normalized)).sort((a, b) => a.displayName.localeCompare(b.displayName));
63
+ });
64
+ return {
65
+ ...runtime,
66
+ options
67
+ };
68
+ }
69
+ function T(props) {
70
+ const runtime = useTranslation();
71
+ return createMemo(() => runtime.translate(props.id, props.defaultMessage, props.values));
72
+ }
73
+ function LanguageSelector(props) {
74
+ const [query, setQuery] = createSignal("");
75
+ const runtime = useLocaleOptions(query);
76
+ return _$ssr(_tmpl$, _$ssrHydrationKey() + _$ssrAttribute("class", _$escape(props.class, true), false), _$escape(props.label ?? "Language"), _$ssrAttribute("value", _$escape(query(), true), false), _$ssrAttribute("aria-label", _$escape(props.label ?? "Language", true), false) + _$ssrAttribute("value", _$escape(runtime.locale(), true), false), _$ssrAttribute("disabled", !runtime.ready(), true), _$escape(_$createComponent(For, {
77
+ get each() {
78
+ return runtime.options();
79
+ },
80
+ children: (item) => _$ssr(_tmpl$2, _$ssrHydrationKey() + _$ssrAttribute("value", _$escape(item.code, true), false), _$escape(item.nativeName), _$escape(item.displayName), item.tier === "PREVIEW" ? " (Preview)" : "")
81
+ })));
82
+ }
83
+ function useFormatters() {
84
+ return useTranslation().formatters;
85
+ }
86
+ function useRuntimeContent(client, value, fields) {
87
+ const [revision, setRevision] = createSignal(client.getSnapshot());
88
+ onCleanup(client.subscribe(() => setRevision(client.getSnapshot())));
89
+ return createMemo(() => {
90
+ revision();
91
+ return client.localize(value(), fields);
92
+ });
93
+ }
94
+ export {
95
+ LanguageSelector,
96
+ LinguanaProvider,
97
+ T,
98
+ createFormatters,
99
+ getLocaleAttributes,
100
+ useFormatters,
101
+ useLocaleOptions,
102
+ useRuntimeContent,
103
+ useTranslation
104
+ };
package/package.json CHANGED
@@ -1,29 +1,36 @@
1
1
  {
2
- "name": "@linguanahq/solid",
3
- "version": "0.1.0",
4
- "publishConfig": {
5
- "access": "public"
6
- },
7
- "type": "module",
8
- "exports": {
9
- ".": "./src/index.tsx",
10
- "./compiler-runtime": "./src/compiler-runtime.tsx",
11
- "./styles.css": "./src/styles.css"
12
- },
13
- "scripts": {
14
- "check-types": "tsc --noEmit",
15
- "test": "bun test"
16
- },
17
- "dependencies": {
18
- "@linguanahq/core": "0.1.0"
19
- },
20
- "devDependencies": {
21
- "@linguana/config": "0.0.0",
22
- "@linguanahq/catalog": "0.1.0",
23
- "typescript": "^6",
24
- "solid-js": "^1.9.10"
25
- },
26
- "peerDependencies": {
27
- "solid-js": ">=1.9"
28
- }
2
+ "name": "@linguanahq/solid",
3
+ "version": "0.1.2",
4
+ "type": "module",
5
+ "description": "Linguana solid integration",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "browser": "./dist/dom/index.js",
10
+ "node": "./dist/ssr/index.js",
11
+ "default": "./dist/dom/index.js"
12
+ },
13
+ "./compiler-runtime": {
14
+ "types": "./dist/compiler-runtime.d.ts",
15
+ "browser": "./dist/dom/compiler-runtime.js",
16
+ "node": "./dist/ssr/compiler-runtime.js",
17
+ "default": "./dist/dom/compiler-runtime.js"
18
+ },
19
+ "./styles.css": "./dist/styles.css"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "engines": {
25
+ "node": ">=22.12.0"
26
+ },
27
+ "dependencies": {
28
+ "@linguanahq/core": "0.1.2"
29
+ },
30
+ "peerDependencies": {
31
+ "solid-js": ">=1.9"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ }
29
36
  }
@@ -1,19 +0,0 @@
1
- export { T as LinguanaMessage, T as default } from ".";
2
-
3
- import type { JSX } from "solid-js";
4
- import { useTranslation } from ".";
5
-
6
- export function LinguanaAttributes(props: {
7
- descriptors: Array<{ name: string; id: string; defaultMessage: string }>;
8
- children: (values: Record<string, string>) => JSX.Element;
9
- }) {
10
- const runtime = useTranslation();
11
- return props.children(
12
- Object.fromEntries(
13
- props.descriptors.map((item) => [
14
- item.name,
15
- String(runtime.translate(item.id, item.defaultMessage)),
16
- ]),
17
- ),
18
- );
19
- }
package/src/index.tsx DELETED
@@ -1,112 +0,0 @@
1
- import {
2
- createLinguanaClient,
3
- type LinguanaClient,
4
- type LinguanaClientOptions,
5
- } from "@linguanahq/core";
6
- import {
7
- createContext,
8
- createMemo,
9
- createSignal,
10
- For,
11
- type JSX,
12
- onCleanup,
13
- onMount,
14
- type ParentProps,
15
- useContext,
16
- } from "solid-js";
17
-
18
- const LinguanaContext = createContext<LinguanaClient>();
19
-
20
- export function LinguanaProvider(props: ParentProps<LinguanaClientOptions>) {
21
- const client = createLinguanaClient(props);
22
- onMount(() => void client.loadRuntimeConfig());
23
- onCleanup(() => client.dispose());
24
- return (
25
- <LinguanaContext.Provider value={client}>
26
- {props.children}
27
- </LinguanaContext.Provider>
28
- );
29
- }
30
-
31
- export function useTranslation() {
32
- const client = useContext(LinguanaContext);
33
- if (!client)
34
- throw new Error("useTranslation must be used within LinguanaProvider");
35
- const [snapshot, setSnapshot] = createSignal(client.getSnapshot());
36
- const unsubscribe = client.subscribe(() => setSnapshot(client.getSnapshot()));
37
- onCleanup(unsubscribe);
38
- return {
39
- snapshot,
40
- locale: () => snapshot().locale,
41
- ready: () => snapshot().ready,
42
- availableLocales: () => snapshot().availableLocales,
43
- setLocale: client.setLocale,
44
- t: client.t,
45
- translate: client.translate,
46
- };
47
- }
48
-
49
- export function useLocaleOptions(query = () => "") {
50
- const runtime = useTranslation();
51
- const options = createMemo(() => {
52
- const normalized = query().trim().toLocaleLowerCase();
53
- return runtime
54
- .availableLocales()
55
- .filter(
56
- (item) =>
57
- !normalized ||
58
- `${item.code} ${item.displayName} ${item.nativeName}`
59
- .toLocaleLowerCase()
60
- .includes(normalized),
61
- )
62
- .sort((a, b) => a.displayName.localeCompare(b.displayName));
63
- });
64
- return { ...runtime, options };
65
- }
66
-
67
- export function T(props: {
68
- id: string;
69
- defaultMessage: string;
70
- values?: Record<string, unknown>;
71
- }) {
72
- return useTranslation().translate(
73
- props.id,
74
- props.defaultMessage,
75
- props.values,
76
- ) as JSX.Element;
77
- }
78
-
79
- export function LanguageSelector(props: { label?: string; class?: string }) {
80
- const [query, setQuery] = createSignal("");
81
- const runtime = useLocaleOptions(query);
82
- return (
83
- <div class={props.class} data-linguana-language-selector="">
84
- <label>
85
- <span>{props.label ?? "Language"}</span>
86
- <input
87
- type="search"
88
- value={query()}
89
- onInput={(event) => setQuery(event.currentTarget.value)}
90
- placeholder="Search languages"
91
- />
92
- </label>
93
- <select
94
- aria-label={props.label ?? "Language"}
95
- value={runtime.locale()}
96
- disabled={!runtime.ready()}
97
- onChange={(event) => void runtime.setLocale(event.currentTarget.value)}
98
- >
99
- <For each={runtime.options()}>
100
- {(item) => (
101
- <option value={item.code}>
102
- {item.nativeName} — {item.displayName}
103
- {item.tier === "PREVIEW" ? " (Preview)" : ""}
104
- </option>
105
- )}
106
- </For>
107
- </select>
108
- </div>
109
- );
110
- }
111
-
112
- export type { LinguanaClient, LinguanaClientOptions } from "@linguanahq/core";
File without changes