@linguanahq/solid 0.1.1 → 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.
- package/dist/dom/compiler-runtime.js +6 -1
- package/dist/dom/index.js +26 -1
- package/dist/index.d.ts +66 -5
- package/dist/ssr/compiler-runtime.js +6 -1
- package/dist/ssr/index.js +26 -1
- package/package.json +2 -2
|
@@ -11,8 +11,9 @@ import { effect as _$effect } from "solid-js/web";
|
|
|
11
11
|
import { insert as _$insert } from "solid-js/web";
|
|
12
12
|
import { memo as _$memo } from "solid-js/web";
|
|
13
13
|
import { createComponent as _$createComponent } from "solid-js/web";
|
|
14
|
-
import { createLinguanaClient } from "@linguanahq/core";
|
|
14
|
+
import { bindLocaleAttributes, createLinguanaClient } from "@linguanahq/core";
|
|
15
15
|
import { createContext, createMemo, createSignal, For, onCleanup, onMount, useContext } from "solid-js";
|
|
16
|
+
import { createFormatters, getLocaleAttributes } from "@linguanahq/core";
|
|
16
17
|
var LinguanaContext = createContext();
|
|
17
18
|
function useTranslation() {
|
|
18
19
|
const client = useContext(LinguanaContext);
|
|
@@ -22,6 +23,10 @@ function useTranslation() {
|
|
|
22
23
|
onCleanup(unsubscribe);
|
|
23
24
|
return {
|
|
24
25
|
snapshot,
|
|
26
|
+
formatters: () => {
|
|
27
|
+
snapshot();
|
|
28
|
+
return client.getFormatters();
|
|
29
|
+
},
|
|
25
30
|
locale: () => snapshot().locale,
|
|
26
31
|
ready: () => snapshot().ready,
|
|
27
32
|
availableLocales: () => snapshot().availableLocales,
|
package/dist/dom/index.js
CHANGED
|
@@ -11,15 +11,21 @@ import { effect as _$effect } from "solid-js/web";
|
|
|
11
11
|
import { insert as _$insert } from "solid-js/web";
|
|
12
12
|
import { memo as _$memo } from "solid-js/web";
|
|
13
13
|
import { createComponent as _$createComponent } from "solid-js/web";
|
|
14
|
-
import { createLinguanaClient } from "@linguanahq/core";
|
|
14
|
+
import { bindLocaleAttributes, createLinguanaClient } from "@linguanahq/core";
|
|
15
15
|
import { createContext, createMemo, createSignal, For, onCleanup, onMount, useContext } from "solid-js";
|
|
16
|
+
import { createFormatters, getLocaleAttributes } from "@linguanahq/core";
|
|
16
17
|
var _tmpl$ = /* @__PURE__ */ _$template(`<div data-linguana-language-selector><label><span></span><input type=search placeholder="Search languages"></label><select>`);
|
|
17
18
|
var _tmpl$2 = /* @__PURE__ */ _$template(`<option><!$><!/> \u2014 <!$><!/><!$><!/>`);
|
|
18
19
|
var LinguanaContext = createContext();
|
|
19
20
|
function LinguanaProvider(props) {
|
|
21
|
+
const parent = useContext(LinguanaContext);
|
|
20
22
|
const client = createLinguanaClient(props);
|
|
21
23
|
onMount(() => {
|
|
22
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
|
+
}
|
|
23
29
|
void client.setLocale(client.getSnapshot().locale);
|
|
24
30
|
});
|
|
25
31
|
onCleanup(() => client.dispose());
|
|
@@ -38,6 +44,10 @@ function useTranslation() {
|
|
|
38
44
|
onCleanup(unsubscribe);
|
|
39
45
|
return {
|
|
40
46
|
snapshot,
|
|
47
|
+
formatters: () => {
|
|
48
|
+
snapshot();
|
|
49
|
+
return client.getFormatters();
|
|
50
|
+
},
|
|
41
51
|
locale: () => snapshot().locale,
|
|
42
52
|
ready: () => snapshot().ready,
|
|
43
53
|
availableLocales: () => snapshot().availableLocales,
|
|
@@ -105,11 +115,26 @@ function LanguageSelector(props) {
|
|
|
105
115
|
return _el$;
|
|
106
116
|
})();
|
|
107
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
|
+
}
|
|
108
129
|
_$delegateEvents(["input"]);
|
|
109
130
|
export {
|
|
110
131
|
LanguageSelector,
|
|
111
132
|
LinguanaProvider,
|
|
112
133
|
T,
|
|
134
|
+
createFormatters,
|
|
135
|
+
getLocaleAttributes,
|
|
136
|
+
useFormatters,
|
|
113
137
|
useLocaleOptions,
|
|
138
|
+
useRuntimeContent,
|
|
114
139
|
useTranslation
|
|
115
140
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,60 @@
|
|
|
1
|
-
import { type LinguanaClientOptions } from "@linguanahq/core";
|
|
1
|
+
import { type LinguanaClient, type LinguanaClientOptions } from "@linguanahq/core";
|
|
2
2
|
import { type JSX, type ParentProps } from "solid-js";
|
|
3
3
|
export declare function LinguanaProvider(props: ParentProps<LinguanaClientOptions>): JSX.Element;
|
|
4
4
|
export declare function useTranslation(): {
|
|
5
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
|
+
};
|
|
6
24
|
locale: () => string;
|
|
7
25
|
ready: () => boolean;
|
|
8
26
|
availableLocales: () => readonly import("@linguanahq/core").LocaleOption[];
|
|
9
27
|
setLocale: (locale: string) => Promise<void>;
|
|
10
|
-
t:
|
|
11
|
-
translate:
|
|
28
|
+
t: LinguanaClient["t"];
|
|
29
|
+
translate: LinguanaClient["translate"];
|
|
12
30
|
};
|
|
13
31
|
export declare function useLocaleOptions(query?: () => string): {
|
|
14
32
|
options: import("solid-js").Accessor<import("@linguanahq/core").LocaleOption[]>;
|
|
15
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
|
+
};
|
|
16
52
|
locale: () => string;
|
|
17
53
|
ready: () => boolean;
|
|
18
54
|
availableLocales: () => readonly import("@linguanahq/core").LocaleOption[];
|
|
19
55
|
setLocale: (locale: string) => Promise<void>;
|
|
20
|
-
t:
|
|
21
|
-
translate:
|
|
56
|
+
t: LinguanaClient["t"];
|
|
57
|
+
translate: LinguanaClient["translate"];
|
|
22
58
|
};
|
|
23
59
|
export declare function T(props: {
|
|
24
60
|
id: string;
|
|
@@ -30,3 +66,28 @@ export declare function LanguageSelector(props: {
|
|
|
30
66
|
class?: string;
|
|
31
67
|
}): JSX.Element;
|
|
32
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
|
+
}>;
|
|
@@ -4,8 +4,9 @@ import { ssrAttribute as _$ssrAttribute } from "solid-js/web";
|
|
|
4
4
|
import { escape as _$escape } from "solid-js/web";
|
|
5
5
|
import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web";
|
|
6
6
|
import { createComponent as _$createComponent } from "solid-js/web";
|
|
7
|
-
import { createLinguanaClient } from "@linguanahq/core";
|
|
7
|
+
import { bindLocaleAttributes, createLinguanaClient } from "@linguanahq/core";
|
|
8
8
|
import { createContext, createMemo, createSignal, For, onCleanup, onMount, useContext } from "solid-js";
|
|
9
|
+
import { createFormatters, getLocaleAttributes } from "@linguanahq/core";
|
|
9
10
|
var LinguanaContext = createContext();
|
|
10
11
|
function useTranslation() {
|
|
11
12
|
const client = useContext(LinguanaContext);
|
|
@@ -15,6 +16,10 @@ function useTranslation() {
|
|
|
15
16
|
onCleanup(unsubscribe);
|
|
16
17
|
return {
|
|
17
18
|
snapshot,
|
|
19
|
+
formatters: () => {
|
|
20
|
+
snapshot();
|
|
21
|
+
return client.getFormatters();
|
|
22
|
+
},
|
|
18
23
|
locale: () => snapshot().locale,
|
|
19
24
|
ready: () => snapshot().ready,
|
|
20
25
|
availableLocales: () => snapshot().availableLocales,
|
package/dist/ssr/index.js
CHANGED
|
@@ -4,15 +4,21 @@ import { ssrAttribute as _$ssrAttribute } from "solid-js/web";
|
|
|
4
4
|
import { escape as _$escape } from "solid-js/web";
|
|
5
5
|
import { ssrHydrationKey as _$ssrHydrationKey } from "solid-js/web";
|
|
6
6
|
import { createComponent as _$createComponent } from "solid-js/web";
|
|
7
|
-
import { createLinguanaClient } from "@linguanahq/core";
|
|
7
|
+
import { bindLocaleAttributes, createLinguanaClient } from "@linguanahq/core";
|
|
8
8
|
import { createContext, createMemo, createSignal, For, onCleanup, onMount, useContext } from "solid-js";
|
|
9
|
+
import { createFormatters, getLocaleAttributes } from "@linguanahq/core";
|
|
9
10
|
var _tmpl$ = ["<div", " data-linguana-language-selector><label><span>", '</span><input type="search"', ' placeholder="Search languages"></label><select', "", ">", "</select></div>"];
|
|
10
11
|
var _tmpl$2 = ["<option", "><!--$-->", "<!--/--> \u2014 <!--$-->", "<!--/--><!--$-->", "<!--/--></option>"];
|
|
11
12
|
var LinguanaContext = createContext();
|
|
12
13
|
function LinguanaProvider(props) {
|
|
14
|
+
const parent = useContext(LinguanaContext);
|
|
13
15
|
const client = createLinguanaClient(props);
|
|
14
16
|
onMount(() => {
|
|
15
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
|
+
}
|
|
16
22
|
void client.setLocale(client.getSnapshot().locale);
|
|
17
23
|
});
|
|
18
24
|
onCleanup(() => client.dispose());
|
|
@@ -31,6 +37,10 @@ function useTranslation() {
|
|
|
31
37
|
onCleanup(unsubscribe);
|
|
32
38
|
return {
|
|
33
39
|
snapshot,
|
|
40
|
+
formatters: () => {
|
|
41
|
+
snapshot();
|
|
42
|
+
return client.getFormatters();
|
|
43
|
+
},
|
|
34
44
|
locale: () => snapshot().locale,
|
|
35
45
|
ready: () => snapshot().ready,
|
|
36
46
|
availableLocales: () => snapshot().availableLocales,
|
|
@@ -70,10 +80,25 @@ function LanguageSelector(props) {
|
|
|
70
80
|
children: (item) => _$ssr(_tmpl$2, _$ssrHydrationKey() + _$ssrAttribute("value", _$escape(item.code, true), false), _$escape(item.nativeName), _$escape(item.displayName), item.tier === "PREVIEW" ? " (Preview)" : "")
|
|
71
81
|
})));
|
|
72
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
|
+
}
|
|
73
94
|
export {
|
|
74
95
|
LanguageSelector,
|
|
75
96
|
LinguanaProvider,
|
|
76
97
|
T,
|
|
98
|
+
createFormatters,
|
|
99
|
+
getLocaleAttributes,
|
|
100
|
+
useFormatters,
|
|
77
101
|
useLocaleOptions,
|
|
102
|
+
useRuntimeContent,
|
|
78
103
|
useTranslation
|
|
79
104
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linguanahq/solid",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Linguana solid integration",
|
|
6
6
|
"exports": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"node": ">=22.12.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@linguanahq/core": "0.1.
|
|
28
|
+
"@linguanahq/core": "0.1.2"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"solid-js": ">=1.9"
|