@linguanahq/solid 0.1.0 → 0.1.1
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/compiler-runtime.d.ts +10 -0
- package/dist/dom/compiler-runtime.js +61 -0
- package/dist/dom/index.js +115 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/ssr/compiler-runtime.js +53 -0
- package/dist/ssr/index.js +79 -0
- package/package.json +34 -27
- package/src/compiler-runtime.tsx +0 -19
- package/src/index.tsx +0 -112
- /package/{src → dist}/styles.css +0 -0
|
@@ -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,61 @@
|
|
|
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 { createLinguanaClient } from "@linguanahq/core";
|
|
15
|
+
import { createContext, createMemo, createSignal, For, onCleanup, onMount, useContext } from "solid-js";
|
|
16
|
+
var LinguanaContext = createContext();
|
|
17
|
+
function useTranslation() {
|
|
18
|
+
const client = useContext(LinguanaContext);
|
|
19
|
+
if (!client) throw new Error("useTranslation must be used within LinguanaProvider");
|
|
20
|
+
const [snapshot, setSnapshot] = createSignal(client.getSnapshot());
|
|
21
|
+
const unsubscribe = client.subscribe(() => setSnapshot(client.getSnapshot()));
|
|
22
|
+
onCleanup(unsubscribe);
|
|
23
|
+
return {
|
|
24
|
+
snapshot,
|
|
25
|
+
locale: () => snapshot().locale,
|
|
26
|
+
ready: () => snapshot().ready,
|
|
27
|
+
availableLocales: () => snapshot().availableLocales,
|
|
28
|
+
setLocale: client.setLocale,
|
|
29
|
+
t: (...args) => {
|
|
30
|
+
snapshot();
|
|
31
|
+
return client.t(...args);
|
|
32
|
+
},
|
|
33
|
+
translate: (...args) => {
|
|
34
|
+
snapshot();
|
|
35
|
+
return client.translate(...args);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function T(props) {
|
|
40
|
+
const runtime = useTranslation();
|
|
41
|
+
return createMemo(() => runtime.translate(props.id, props.defaultMessage, props.values));
|
|
42
|
+
}
|
|
43
|
+
_$delegateEvents(["input"]);
|
|
44
|
+
|
|
45
|
+
// src/compiler-runtime.tsx
|
|
46
|
+
function LinguanaAttributes(props) {
|
|
47
|
+
const runtime = useTranslation();
|
|
48
|
+
const values = {};
|
|
49
|
+
for (const item of props.descriptors) {
|
|
50
|
+
Object.defineProperty(values, item.name, {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get: () => String(runtime.translate(item.id, item.defaultMessage))
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return props.children(values);
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
LinguanaAttributes,
|
|
59
|
+
T as LinguanaMessage,
|
|
60
|
+
T as default
|
|
61
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
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 { createLinguanaClient } from "@linguanahq/core";
|
|
15
|
+
import { createContext, createMemo, createSignal, For, onCleanup, onMount, useContext } from "solid-js";
|
|
16
|
+
var _tmpl$ = /* @__PURE__ */ _$template(`<div data-linguana-language-selector><label><span></span><input type=search placeholder="Search languages"></label><select>`);
|
|
17
|
+
var _tmpl$2 = /* @__PURE__ */ _$template(`<option><!$><!/> \u2014 <!$><!/><!$><!/>`);
|
|
18
|
+
var LinguanaContext = createContext();
|
|
19
|
+
function LinguanaProvider(props) {
|
|
20
|
+
const client = createLinguanaClient(props);
|
|
21
|
+
onMount(() => {
|
|
22
|
+
void client.loadRuntimeConfig();
|
|
23
|
+
void client.setLocale(client.getSnapshot().locale);
|
|
24
|
+
});
|
|
25
|
+
onCleanup(() => client.dispose());
|
|
26
|
+
return _$createComponent(LinguanaContext.Provider, {
|
|
27
|
+
value: client,
|
|
28
|
+
get children() {
|
|
29
|
+
return props.children;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function useTranslation() {
|
|
34
|
+
const client = useContext(LinguanaContext);
|
|
35
|
+
if (!client) throw new Error("useTranslation must be used within LinguanaProvider");
|
|
36
|
+
const [snapshot, setSnapshot] = createSignal(client.getSnapshot());
|
|
37
|
+
const unsubscribe = client.subscribe(() => setSnapshot(client.getSnapshot()));
|
|
38
|
+
onCleanup(unsubscribe);
|
|
39
|
+
return {
|
|
40
|
+
snapshot,
|
|
41
|
+
locale: () => snapshot().locale,
|
|
42
|
+
ready: () => snapshot().ready,
|
|
43
|
+
availableLocales: () => snapshot().availableLocales,
|
|
44
|
+
setLocale: client.setLocale,
|
|
45
|
+
t: (...args) => {
|
|
46
|
+
snapshot();
|
|
47
|
+
return client.t(...args);
|
|
48
|
+
},
|
|
49
|
+
translate: (...args) => {
|
|
50
|
+
snapshot();
|
|
51
|
+
return client.translate(...args);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function useLocaleOptions(query = () => "") {
|
|
56
|
+
const runtime = useTranslation();
|
|
57
|
+
const options = createMemo(() => {
|
|
58
|
+
const normalized = query().trim().toLocaleLowerCase();
|
|
59
|
+
return runtime.availableLocales().filter((item) => !normalized || `${item.code} ${item.displayName} ${item.nativeName}`.toLocaleLowerCase().includes(normalized)).sort((a, b) => a.displayName.localeCompare(b.displayName));
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
...runtime,
|
|
63
|
+
options
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function T(props) {
|
|
67
|
+
const runtime = useTranslation();
|
|
68
|
+
return createMemo(() => runtime.translate(props.id, props.defaultMessage, props.values));
|
|
69
|
+
}
|
|
70
|
+
function LanguageSelector(props) {
|
|
71
|
+
const [query, setQuery] = createSignal("");
|
|
72
|
+
const runtime = useLocaleOptions(query);
|
|
73
|
+
return (() => {
|
|
74
|
+
var _el$ = _$getNextElement(_tmpl$), _el$2 = _el$.firstChild, _el$3 = _el$2.firstChild, _el$4 = _el$3.nextSibling, _el$5 = _el$2.nextSibling;
|
|
75
|
+
_$insert(_el$3, () => props.label ?? "Language");
|
|
76
|
+
_el$4.$$input = (event) => setQuery(event.currentTarget.value);
|
|
77
|
+
_el$5.addEventListener("change", (event) => void runtime.setLocale(event.currentTarget.value));
|
|
78
|
+
_$insert(_el$5, _$createComponent(For, {
|
|
79
|
+
get each() {
|
|
80
|
+
return runtime.options();
|
|
81
|
+
},
|
|
82
|
+
children: (item) => (() => {
|
|
83
|
+
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);
|
|
84
|
+
_$insert(_el$6, () => item.nativeName, _el$9, _co$);
|
|
85
|
+
_$insert(_el$6, () => item.displayName, _el$1, _co$2);
|
|
86
|
+
_$insert(_el$6, () => item.tier === "PREVIEW" ? " (Preview)" : "", _el$11, _co$3);
|
|
87
|
+
_$effect(() => _$setProperty(_el$6, "value", item.code));
|
|
88
|
+
return _el$6;
|
|
89
|
+
})()
|
|
90
|
+
}));
|
|
91
|
+
_$effect((_p$) => {
|
|
92
|
+
var _v$ = props.class, _v$2 = props.label ?? "Language", _v$3 = !runtime.ready();
|
|
93
|
+
_v$ !== _p$.e && _$className(_el$, _p$.e = _v$);
|
|
94
|
+
_v$2 !== _p$.t && _$setAttribute(_el$5, "aria-label", _p$.t = _v$2);
|
|
95
|
+
_v$3 !== _p$.a && _$setProperty(_el$5, "disabled", _p$.a = _v$3);
|
|
96
|
+
return _p$;
|
|
97
|
+
}, {
|
|
98
|
+
e: void 0,
|
|
99
|
+
t: void 0,
|
|
100
|
+
a: void 0
|
|
101
|
+
});
|
|
102
|
+
_$effect(() => _$setProperty(_el$4, "value", query()));
|
|
103
|
+
_$effect(() => _$setProperty(_el$5, "value", runtime.locale()));
|
|
104
|
+
_$runHydrationEvents();
|
|
105
|
+
return _el$;
|
|
106
|
+
})();
|
|
107
|
+
}
|
|
108
|
+
_$delegateEvents(["input"]);
|
|
109
|
+
export {
|
|
110
|
+
LanguageSelector,
|
|
111
|
+
LinguanaProvider,
|
|
112
|
+
T,
|
|
113
|
+
useLocaleOptions,
|
|
114
|
+
useTranslation
|
|
115
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { 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
|
+
locale: () => string;
|
|
7
|
+
ready: () => boolean;
|
|
8
|
+
availableLocales: () => readonly import("@linguanahq/core").LocaleOption[];
|
|
9
|
+
setLocale: (locale: string) => Promise<void>;
|
|
10
|
+
t: (source: string, values?: import("@linguanahq/core").MessageValues | undefined, options?: import("@linguanahq/core").TranslationOptions | undefined) => unknown;
|
|
11
|
+
translate: (id: string, source: string, values?: import("@linguanahq/core").MessageValues | undefined, components?: import("@linguanahq/core").MessageComponents | undefined) => unknown;
|
|
12
|
+
};
|
|
13
|
+
export declare function useLocaleOptions(query?: () => string): {
|
|
14
|
+
options: import("solid-js").Accessor<import("@linguanahq/core").LocaleOption[]>;
|
|
15
|
+
snapshot: import("solid-js").Accessor<import("@linguanahq/core").LinguanaSnapshot>;
|
|
16
|
+
locale: () => string;
|
|
17
|
+
ready: () => boolean;
|
|
18
|
+
availableLocales: () => readonly import("@linguanahq/core").LocaleOption[];
|
|
19
|
+
setLocale: (locale: string) => Promise<void>;
|
|
20
|
+
t: (source: string, values?: import("@linguanahq/core").MessageValues | undefined, options?: import("@linguanahq/core").TranslationOptions | undefined) => unknown;
|
|
21
|
+
translate: (id: string, source: string, values?: import("@linguanahq/core").MessageValues | undefined, components?: import("@linguanahq/core").MessageComponents | undefined) => unknown;
|
|
22
|
+
};
|
|
23
|
+
export declare function T(props: {
|
|
24
|
+
id: string;
|
|
25
|
+
defaultMessage: string;
|
|
26
|
+
values?: Record<string, unknown>;
|
|
27
|
+
}): JSX.Element;
|
|
28
|
+
export declare function LanguageSelector(props: {
|
|
29
|
+
label?: string;
|
|
30
|
+
class?: string;
|
|
31
|
+
}): JSX.Element;
|
|
32
|
+
export type { LinguanaClient, LinguanaClientOptions } from "@linguanahq/core";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { createLinguanaClient } from "@linguanahq/core";
|
|
8
|
+
import { createContext, createMemo, createSignal, For, onCleanup, onMount, useContext } from "solid-js";
|
|
9
|
+
var LinguanaContext = createContext();
|
|
10
|
+
function useTranslation() {
|
|
11
|
+
const client = useContext(LinguanaContext);
|
|
12
|
+
if (!client) throw new Error("useTranslation must be used within LinguanaProvider");
|
|
13
|
+
const [snapshot, setSnapshot] = createSignal(client.getSnapshot());
|
|
14
|
+
const unsubscribe = client.subscribe(() => setSnapshot(client.getSnapshot()));
|
|
15
|
+
onCleanup(unsubscribe);
|
|
16
|
+
return {
|
|
17
|
+
snapshot,
|
|
18
|
+
locale: () => snapshot().locale,
|
|
19
|
+
ready: () => snapshot().ready,
|
|
20
|
+
availableLocales: () => snapshot().availableLocales,
|
|
21
|
+
setLocale: client.setLocale,
|
|
22
|
+
t: (...args) => {
|
|
23
|
+
snapshot();
|
|
24
|
+
return client.t(...args);
|
|
25
|
+
},
|
|
26
|
+
translate: (...args) => {
|
|
27
|
+
snapshot();
|
|
28
|
+
return client.translate(...args);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function T(props) {
|
|
33
|
+
const runtime = useTranslation();
|
|
34
|
+
return createMemo(() => runtime.translate(props.id, props.defaultMessage, props.values));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/compiler-runtime.tsx
|
|
38
|
+
function LinguanaAttributes(props) {
|
|
39
|
+
const runtime = useTranslation();
|
|
40
|
+
const values = {};
|
|
41
|
+
for (const item of props.descriptors) {
|
|
42
|
+
Object.defineProperty(values, item.name, {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: () => String(runtime.translate(item.id, item.defaultMessage))
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return props.children(values);
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
LinguanaAttributes,
|
|
51
|
+
T as LinguanaMessage,
|
|
52
|
+
T as default
|
|
53
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
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 { createLinguanaClient } from "@linguanahq/core";
|
|
8
|
+
import { createContext, createMemo, createSignal, For, onCleanup, onMount, useContext } from "solid-js";
|
|
9
|
+
var _tmpl$ = ["<div", " data-linguana-language-selector><label><span>", '</span><input type="search"', ' placeholder="Search languages"></label><select', "", ">", "</select></div>"];
|
|
10
|
+
var _tmpl$2 = ["<option", "><!--$-->", "<!--/--> \u2014 <!--$-->", "<!--/--><!--$-->", "<!--/--></option>"];
|
|
11
|
+
var LinguanaContext = createContext();
|
|
12
|
+
function LinguanaProvider(props) {
|
|
13
|
+
const client = createLinguanaClient(props);
|
|
14
|
+
onMount(() => {
|
|
15
|
+
void client.loadRuntimeConfig();
|
|
16
|
+
void client.setLocale(client.getSnapshot().locale);
|
|
17
|
+
});
|
|
18
|
+
onCleanup(() => client.dispose());
|
|
19
|
+
return _$createComponent(LinguanaContext.Provider, {
|
|
20
|
+
value: client,
|
|
21
|
+
get children() {
|
|
22
|
+
return props.children;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function useTranslation() {
|
|
27
|
+
const client = useContext(LinguanaContext);
|
|
28
|
+
if (!client) throw new Error("useTranslation must be used within LinguanaProvider");
|
|
29
|
+
const [snapshot, setSnapshot] = createSignal(client.getSnapshot());
|
|
30
|
+
const unsubscribe = client.subscribe(() => setSnapshot(client.getSnapshot()));
|
|
31
|
+
onCleanup(unsubscribe);
|
|
32
|
+
return {
|
|
33
|
+
snapshot,
|
|
34
|
+
locale: () => snapshot().locale,
|
|
35
|
+
ready: () => snapshot().ready,
|
|
36
|
+
availableLocales: () => snapshot().availableLocales,
|
|
37
|
+
setLocale: client.setLocale,
|
|
38
|
+
t: (...args) => {
|
|
39
|
+
snapshot();
|
|
40
|
+
return client.t(...args);
|
|
41
|
+
},
|
|
42
|
+
translate: (...args) => {
|
|
43
|
+
snapshot();
|
|
44
|
+
return client.translate(...args);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function useLocaleOptions(query = () => "") {
|
|
49
|
+
const runtime = useTranslation();
|
|
50
|
+
const options = createMemo(() => {
|
|
51
|
+
const normalized = query().trim().toLocaleLowerCase();
|
|
52
|
+
return runtime.availableLocales().filter((item) => !normalized || `${item.code} ${item.displayName} ${item.nativeName}`.toLocaleLowerCase().includes(normalized)).sort((a, b) => a.displayName.localeCompare(b.displayName));
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
...runtime,
|
|
56
|
+
options
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function T(props) {
|
|
60
|
+
const runtime = useTranslation();
|
|
61
|
+
return createMemo(() => runtime.translate(props.id, props.defaultMessage, props.values));
|
|
62
|
+
}
|
|
63
|
+
function LanguageSelector(props) {
|
|
64
|
+
const [query, setQuery] = createSignal("");
|
|
65
|
+
const runtime = useLocaleOptions(query);
|
|
66
|
+
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, {
|
|
67
|
+
get each() {
|
|
68
|
+
return runtime.options();
|
|
69
|
+
},
|
|
70
|
+
children: (item) => _$ssr(_tmpl$2, _$ssrHydrationKey() + _$ssrAttribute("value", _$escape(item.code, true), false), _$escape(item.nativeName), _$escape(item.displayName), item.tier === "PREVIEW" ? " (Preview)" : "")
|
|
71
|
+
})));
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
LanguageSelector,
|
|
75
|
+
LinguanaProvider,
|
|
76
|
+
T,
|
|
77
|
+
useLocaleOptions,
|
|
78
|
+
useTranslation
|
|
79
|
+
};
|
package/package.json
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
2
|
+
"name": "@linguanahq/solid",
|
|
3
|
+
"version": "0.1.1",
|
|
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.1"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"solid-js": ">=1.9"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
}
|
|
29
36
|
}
|
package/src/compiler-runtime.tsx
DELETED
|
@@ -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";
|
/package/{src → dist}/styles.css
RENAMED
|
File without changes
|