@nerimity/solid-i18lite 1.7.2 → 1.8.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/browser.mjs +72 -47
- package/dist/browser.mjs.map +1 -1
- package/dist/ssr.js +1 -1
- package/dist/ssr.js.map +1 -1
- package/dist/ssr.mjs +74 -49
- package/dist/ssr.mjs.map +1 -1
- package/dist/types/Trans.d.ts +3 -1
- package/dist/types/Trans.d.ts.map +1 -0
- package/dist/types/TransProvider.d.ts +1 -0
- package/dist/types/TransProvider.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/utils/decodeHtmlEntities.d.ts +1 -0
- package/dist/types/utils/decodeHtmlEntities.d.ts.map +1 -0
- package/dist/types/utils/has-interpolation.d.ts +1 -0
- package/dist/types/utils/has-interpolation.d.ts.map +1 -0
- package/dist/types/utils/replace-elements.d.ts +1 -0
- package/dist/types/utils/replace-elements.d.ts.map +1 -0
- package/dist/types/utils/translate-jsx.d.ts +4 -1
- package/dist/types/utils/translate-jsx.d.ts.map +1 -0
- package/dist/types/utils/translate-with-interpolation.d.ts +1 -0
- package/dist/types/utils/translate-with-interpolation.d.ts.map +1 -0
- package/package.json +76 -76
package/dist/browser.mjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { createComponent as
|
|
2
|
-
import {
|
|
3
|
-
import E from "
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { createComponent as d, memo as u, Dynamic as T } from "solid-js/web";
|
|
2
|
+
import { stringify as w } from "html-parse-string";
|
|
3
|
+
import { useContext as I, createContext as p, createSignal as E, children as L } from "solid-js";
|
|
4
|
+
import S from "@nerimity/i18lite";
|
|
5
|
+
const h = p();
|
|
6
|
+
function k(t, e) {
|
|
7
|
+
const [n, r] = E(null);
|
|
8
|
+
t.init(e, () => r(() => t.language));
|
|
9
|
+
async function o(i) {
|
|
10
|
+
await t.changeLanguage(i), r(() => i);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
return t.addResourceBundle(
|
|
12
|
+
function c(i, x, C, f = {}) {
|
|
13
|
+
return t.addResourceBundle(i, x, C, f.deep, f.overwrite);
|
|
14
14
|
}
|
|
15
|
-
return [(
|
|
16
|
-
addResources:
|
|
15
|
+
return [(...i) => (n(), t.t(...i)), {
|
|
16
|
+
addResources: c,
|
|
17
17
|
getI18next: () => t,
|
|
18
|
-
changeLanguage:
|
|
18
|
+
changeLanguage: o
|
|
19
19
|
}];
|
|
20
20
|
}
|
|
21
|
-
const v = () =>
|
|
21
|
+
const v = () => I(h), B = (t) => d(h.Provider, {
|
|
22
22
|
get value() {
|
|
23
|
-
return
|
|
23
|
+
return k(t.instance || S, {
|
|
24
24
|
lng: t.lng,
|
|
25
25
|
...t.options
|
|
26
26
|
});
|
|
@@ -28,60 +28,85 @@ const v = () => x(f), N = (t) => y(f.Provider, {
|
|
|
28
28
|
get children() {
|
|
29
29
|
return t.children;
|
|
30
30
|
}
|
|
31
|
-
}),
|
|
31
|
+
}), m = document.createElement("textarea");
|
|
32
32
|
function l(t) {
|
|
33
|
-
return
|
|
33
|
+
return m.innerHTML = t || "", m.value;
|
|
34
34
|
}
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
return l(t(
|
|
39
|
-
if (
|
|
40
|
-
const
|
|
41
|
-
|
|
35
|
+
const g = (t, { prefix: e, suffix: n }) => t.includes(e) && t.includes(n), H = (t, { interpolation: e }) => (n, r) => typeof n == "string" ? g(n, e) ? l(t.children[r].children?.[0].content) : l(t.children[r].content) : (n.textContent = l(t.children[r].children?.[0].content), n), P = !globalThis.window, b = (t, e, n) => (r) => {
|
|
36
|
+
const o = typeof r;
|
|
37
|
+
if (o === "string" && g(r, e.interpolation))
|
|
38
|
+
return l(t(r, n.options));
|
|
39
|
+
if (o === "object") {
|
|
40
|
+
const c = r.textContent ?? r.t;
|
|
41
|
+
c && g(c, e.interpolation) && (r[P ? "t" : "textContent"] = t(c, n.options));
|
|
42
42
|
}
|
|
43
|
-
return
|
|
43
|
+
return r;
|
|
44
44
|
};
|
|
45
|
-
let
|
|
45
|
+
let s, J;
|
|
46
46
|
(async () => {
|
|
47
47
|
try {
|
|
48
|
-
|
|
48
|
+
const t = await import("html-parse-string");
|
|
49
|
+
s = t.parse, J = t.stringify;
|
|
49
50
|
} catch {
|
|
50
51
|
}
|
|
51
52
|
})();
|
|
52
|
-
const
|
|
53
|
+
const y = () => {
|
|
53
54
|
console.error(
|
|
54
55
|
"In order to use JSX nesting, install %chtml-parse-string",
|
|
55
56
|
"font-weight: 700",
|
|
56
57
|
"https://github.com/ryansolid/html-parse-string."
|
|
57
58
|
);
|
|
58
|
-
},
|
|
59
|
-
const
|
|
60
|
-
if (!n.children) return
|
|
61
|
-
if (
|
|
62
|
-
if (!
|
|
63
|
-
|
|
59
|
+
}, M = ({ i18n: { options: t }, t: e, props: n }, r) => {
|
|
60
|
+
const o = e(n.key, n.options);
|
|
61
|
+
if (!n.children) return o;
|
|
62
|
+
if (o === n.key) return r.map(b(e, t, n));
|
|
63
|
+
if (!s) {
|
|
64
|
+
y();
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
66
67
|
try {
|
|
67
|
-
const [
|
|
68
|
-
return
|
|
69
|
-
} catch (
|
|
70
|
-
console.error(
|
|
68
|
+
const [c] = s(`<0>${o}</0>`);
|
|
69
|
+
return r.map(H(c, t));
|
|
70
|
+
} catch (c) {
|
|
71
|
+
console.error(c);
|
|
71
72
|
}
|
|
72
|
-
},
|
|
73
|
-
const [
|
|
73
|
+
}, D = (t) => {
|
|
74
|
+
const [e, {
|
|
74
75
|
getI18next: n
|
|
75
76
|
}] = v();
|
|
76
|
-
return
|
|
77
|
+
return u(() => u(() => !!t.components)() ? N({
|
|
78
|
+
t: e,
|
|
79
|
+
props: t
|
|
80
|
+
}) : u(() => typeof t.children == "string")() ? e(t.key, t.children, t.options) : M({
|
|
77
81
|
i18n: n(),
|
|
78
|
-
t:
|
|
82
|
+
t: e,
|
|
79
83
|
props: t
|
|
80
|
-
},
|
|
84
|
+
}, L(() => t.children)()));
|
|
85
|
+
}, N = ({
|
|
86
|
+
t,
|
|
87
|
+
props: e
|
|
88
|
+
}) => {
|
|
89
|
+
const n = t(e.key, e.options);
|
|
90
|
+
if (!s) {
|
|
91
|
+
y();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const [r] = s(`<0>${n}</0>`);
|
|
95
|
+
return r.children.map((o) => {
|
|
96
|
+
if (o.type === "text")
|
|
97
|
+
return o.content;
|
|
98
|
+
const c = o.name, a = e.components?.[c];
|
|
99
|
+
return a ? typeof a == "function" ? d(T, {
|
|
100
|
+
component: a,
|
|
101
|
+
get children() {
|
|
102
|
+
return w(o.children);
|
|
103
|
+
}
|
|
104
|
+
}) : a : o.content;
|
|
105
|
+
});
|
|
81
106
|
};
|
|
82
107
|
export {
|
|
83
|
-
|
|
84
|
-
|
|
108
|
+
D as Trans,
|
|
109
|
+
B as TransProvider,
|
|
85
110
|
v as useTransContext
|
|
86
111
|
};
|
|
87
112
|
//# sourceMappingURL=browser.mjs.map
|
package/dist/browser.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.mjs","sources":["../src/TransProvider.tsx","../src/utils/decodeHtmlEntities.ts","../src/utils/has-interpolation.ts","../src/utils/replace-elements.ts","../src/utils/translate-with-interpolation.ts","../src/utils/translate-jsx.ts","../src/Trans.tsx"],"sourcesContent":["import i18next, { type InitOptions, type TFunction, type i18n } from '@nerimity/i18lite';\r\nimport { createContext, createSignal, useContext, type ParentComponent } from 'solid-js';\r\n\r\nexport type TransProviderActions = {\r\n addResources(lng: string, ns: string, resources: any): i18n;\r\n changeLanguage(lng: string): Promise<void>;\r\n getI18next(): i18n;\r\n};\r\n\r\nconst TransContext = createContext<[TFunction, TransProviderActions]>();\r\n\r\nfunction createTransContext(instance: i18n, options: InitOptions): [TFunction, TransProviderActions] {\r\n const [translate, setTranslate] = createSignal<TFunction | (() => null)>(\r\n !!options.resources ? instance.t : () => null\r\n );\r\n\r\n instance.on('loaded', () => setTranslate(() => instance.t));\r\n instance.init(options, (_, t) => setTranslate(() => t));\r\n\r\n async function changeLanguage(lng: string) {\r\n const t = await instance.changeLanguage(lng);\r\n setTranslate(() => t);\r\n }\r\n\r\n function addResources(\r\n lng: string,\r\n ns: string,\r\n resources: any,\r\n bundleOptions: { deep?: boolean; overwrite?: boolean } = {}\r\n ): i18n {\r\n return instance.addResourceBundle(lng, ns, resources, bundleOptions.deep, bundleOptions.overwrite);\r\n }\r\n\r\n return [\r\n ((...args: Parameters<TFunction>) => translate().apply(null, args)) as TFunction,\r\n {\r\n addResources,\r\n getI18next: () => instance,\r\n changeLanguage,\r\n },\r\n ];\r\n}\r\n\r\nexport const useTransContext = () => useContext(TransContext);\r\n\r\nexport const TransProvider: ParentComponent<{ instance?: i18n; lng?: string; options?: InitOptions }> = (props) => {\r\n return (\r\n <TransContext.Provider\r\n value={createTransContext(props.instance || i18next, { lng: props.lng, ...props.options })}\r\n children={props.children}\r\n />\r\n );\r\n};\r\n","const tempElement = document.createElement('textarea');\r\nexport function decodeHtmlEntities(encodedText: string) {\r\n tempElement.innerHTML = encodedText || '';\r\n\r\n return tempElement.value;\r\n}\r\n","import type { InterpolationOptions } from '@nerimity/i18lite';\r\n\r\nexport const hasInterpolation = (value: string, { prefix, suffix }: InterpolationOptions) =>\r\n value.includes(prefix) && value.includes(suffix);\r\n","import type { InitOptions } from '@nerimity/i18lite';\r\nimport type { IDom } from 'html-parse-string';\r\nimport { decodeHtmlEntities } from './decodeHtmlEntities';\r\nimport { hasInterpolation } from './has-interpolation';\r\n\r\nexport const replaceElements =\r\n (ast: IDom, { interpolation }: InitOptions) =>\r\n (child: Node, index: number) => {\r\n if (typeof child === 'string') {\r\n if (hasInterpolation(child, interpolation)) return decodeHtmlEntities(ast.children[index].children?.[0].content);\r\n\r\n return decodeHtmlEntities(ast.children[index].content);\r\n }\r\n\r\n child.textContent = decodeHtmlEntities(ast.children[index].children?.[0].content);\r\n\r\n return child;\r\n };\r\n","import type { InitOptions, TFunction } from '@nerimity/i18lite';\r\nimport type { TransProps } from '../Trans';\r\nimport { decodeHtmlEntities } from './decodeHtmlEntities';\r\nimport { hasInterpolation } from './has-interpolation';\r\n\r\nconst isNode = !globalThis.window;\r\n\r\nexport const translateWithInterpolation = (t: TFunction, options: InitOptions, props: TransProps) => (item) => {\r\n const type = typeof item;\r\n\r\n if (type === 'string' && hasInterpolation(item, options.interpolation)) {\r\n return decodeHtmlEntities(t(item, props.options));\r\n }\r\n\r\n if (type === 'object') {\r\n const textContent = item.textContent ?? item.t;\r\n if (textContent && hasInterpolation(textContent, options.interpolation)) {\r\n item[isNode ? 't' : 'textContent'] = t(textContent, props.options);\r\n }\r\n }\r\n\r\n return item;\r\n};\r\n","import type { TFunction, i18n } from '@nerimity/i18lite';\r\nimport type { parse } from 'html-parse-string';\r\nimport type { ParentProps } from 'solid-js';\r\nimport type { TransProps } from '../Trans';\r\nimport { replaceElements } from './replace-elements';\r\nimport { translateWithInterpolation } from './translate-with-interpolation';\r\n\r\nexport let parseHTML: typeof parse;\r\n\r\n(async () => {\r\n try {\r\n // @ts-ignore\r\n const module = await import('html-parse-string');\r\n parseHTML = module.parse;\r\n } catch {}\r\n})();\r\n\r\nconst htmlParseStringNotFoundError = () => {\r\n console.error(\r\n 'In order to use JSX nesting, install %chtml-parse-string',\r\n 'font-weight: 700',\r\n 'https://github.com/ryansolid/html-parse-string.'\r\n );\r\n};\r\nexport const translateJSX = (\r\n { i18n: { options }, t, props }: { t: TFunction; props: ParentProps<TransProps>; i18n: i18n },\r\n children: Node[]\r\n) => {\r\n const translation = t(props.key, props.options);\r\n\r\n if (!props.children) return translation;\r\n\r\n if (translation === props.key) return children.map(translateWithInterpolation(t, options, props));\r\n\r\n if (!parseHTML) {\r\n htmlParseStringNotFoundError();\r\n return;\r\n }\r\n try {\r\n const [ast] = parseHTML(`<0>${translation}</0>`);\r\n return children.map(replaceElements(ast, options));\r\n } catch (e) {\r\n console.error(e);\r\n }\r\n};\r\n","import type { TOptions } from '@nerimity/i18lite';\r\nimport { children, type ParentComponent } from 'solid-js';\r\nimport { useTransContext } from './TransProvider';\r\nimport { translateJSX } from './utils/translate-jsx';\r\n\r\nexport type TransProps = { key: string; options?: TOptions };\r\n\r\nexport const Trans: ParentComponent<TransProps> = (props) => {\r\n const [t, { getI18next }] = useTransContext();\r\n\r\n return (\r\n <>\r\n {typeof props.children === 'string'\r\n ? t(props.key, props.children, props.options)\r\n : translateJSX({ i18n: getI18next(), t, props }, children(() => props.children)() as Node[])}\r\n </>\r\n );\r\n};\r\n"],"names":["TransContext","createContext","createTransContext","instance","options","translate","setTranslate","createSignal","resources","t","on","init","_","changeLanguage","lng","addResources","ns","bundleOptions","addResourceBundle","deep","overwrite","args","apply","getI18next","useTransContext","useContext","TransProvider","props","_$createComponent","Provider","value","i18next","children","tempElement","decodeHtmlEntities","encodedText","hasInterpolation","prefix","suffix","replaceElements","ast","interpolation","child","index","isNode","translateWithInterpolation","item","type","textContent","parseHTML","htmlParseStringNotFoundError","translateJSX","translation","e","Trans","_$memo","key","i18n"],"mappings":";;;AASA,MAAMA,IAAeC,EAAAA;AAErB,SAASC,EAAmBC,GAAgBC,GAAyD;AACnG,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAC9BH,EAAQI,YAAYL,EAASM,IAAI,MAAM,IAC3C;AAEAN,EAAAA,EAASO,GAAG,UAAU,MAAMJ,EAAa,MAAMH,EAASM,CAAC,CAAC,GAC1DN,EAASQ,KAAKP,GAAS,CAACQ,GAAGH,MAAMH,EAAa,MAAMG,CAAC,CAAC;AAEtD,iBAAeI,EAAeC,GAAa;AACzC,UAAML,IAAI,MAAMN,EAASU,eAAeC,CAAG;AAC3CR,IAAAA,EAAa,M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,IAAEc,YAAAA;AAAAA,EAAAA,CAAY,IAAIC,EAAAA;AAE5B,SAAA+B,EAAA,MAEKA,EAAA,MAAA,OAAO5B,EAAMK,YAAa,QAAQ,EAAA,IAC/BvB,EAAEkB,EAAM6B,KAAK7B,EAAMK,UAAUL,EAAMvB,OAAO,IAC1C+C,EAAa;AAAA,IAAEM,MAAMlC,EAAAA;AAAAA,IAAcd,GAAAA;AAAAA,IAAGkB,OAAAA;AAAAA,EAAAA,GAASK,EAAS,MAAML,EAAMK,QAAQ,EAAA,CAAa,CAAC;AAGpG;"}
|
|
1
|
+
{"version":3,"file":"browser.mjs","sources":["../src/TransProvider.tsx","../src/utils/decodeHtmlEntities.ts","../src/utils/has-interpolation.ts","../src/utils/replace-elements.ts","../src/utils/translate-with-interpolation.ts","../src/utils/translate-jsx.ts","../src/Trans.tsx"],"sourcesContent":["import i18next, { type InitOptions, type TFunction, type i18n } from '@nerimity/i18lite';\r\nimport { createContext, createSignal, useContext, type ParentComponent } from 'solid-js';\r\n\r\nexport type TransProviderActions = {\r\n addResources(lng: string, ns: string, resources: any): i18n;\r\n changeLanguage(lng: string): Promise<void>;\r\n getI18next(): i18n;\r\n};\r\n\r\nconst TransContext = createContext<[TFunction, TransProviderActions]>();\r\n\r\nfunction createTransContext(instance: i18n, options: InitOptions): [TFunction, TransProviderActions] {\r\n const [language, setLanguage] = createSignal(null);\r\n\r\n instance.init(options, () => setLanguage(() => instance.language));\r\n\r\n async function changeLanguage(lng: string) {\r\n await instance.changeLanguage(lng);\r\n setLanguage(() => lng);\r\n }\r\n\r\n function addResources(\r\n lng: string,\r\n ns: string,\r\n resources: any,\r\n bundleOptions: { deep?: boolean; overwrite?: boolean } = {},\r\n ): i18n {\r\n return instance.addResourceBundle(lng, ns, resources, bundleOptions.deep, bundleOptions.overwrite);\r\n }\r\n\r\n const t = (...args: Parameters<TFunction>) => {\r\n // Access the signal to track it - this ensures components re-render when language changes\r\n language();\r\n return instance.t(...args);\r\n };\r\n\r\n return [\r\n t,\r\n {\r\n addResources,\r\n getI18next: () => instance,\r\n changeLanguage,\r\n },\r\n ];\r\n}\r\n\r\nexport const useTransContext = () => useContext(TransContext);\r\n\r\nexport const TransProvider: ParentComponent<{ instance?: i18n; lng?: string; options?: InitOptions }> = (props) => {\r\n return (\r\n <TransContext.Provider\r\n value={createTransContext(props.instance || i18next, { lng: props.lng, ...props.options })}\r\n children={props.children}\r\n />\r\n );\r\n};\r\n","const tempElement = document.createElement('textarea');\r\nexport function decodeHtmlEntities(encodedText: string) {\r\n tempElement.innerHTML = encodedText || '';\r\n\r\n return tempElement.value;\r\n}\r\n","import type { InterpolationOptions } from '@nerimity/i18lite';\r\n\r\nexport const hasInterpolation = (value: string, { prefix, suffix }: InterpolationOptions) =>\r\n value.includes(prefix) && value.includes(suffix);\r\n","import type { InitOptions } from '@nerimity/i18lite';\r\nimport type { IDom } from 'html-parse-string';\r\nimport { decodeHtmlEntities } from './decodeHtmlEntities';\r\nimport { hasInterpolation } from './has-interpolation';\r\n\r\nexport const replaceElements =\r\n (ast: IDom, { interpolation }: InitOptions) =>\r\n (child: Node, index: number) => {\r\n if (typeof child === 'string') {\r\n if (hasInterpolation(child, interpolation)) return decodeHtmlEntities(ast.children[index].children?.[0].content);\r\n\r\n return decodeHtmlEntities(ast.children[index].content);\r\n }\r\n\r\n child.textContent = decodeHtmlEntities(ast.children[index].children?.[0].content);\r\n\r\n return child;\r\n };\r\n","import type { InitOptions, TFunction } from '@nerimity/i18lite';\r\nimport type { TransProps } from '../Trans';\r\nimport { decodeHtmlEntities } from './decodeHtmlEntities';\r\nimport { hasInterpolation } from './has-interpolation';\r\n\r\nconst isNode = !globalThis.window;\r\n\r\nexport const translateWithInterpolation = (t: TFunction, options: InitOptions, props: TransProps) => (item) => {\r\n const type = typeof item;\r\n\r\n if (type === 'string' && hasInterpolation(item, options.interpolation)) {\r\n return decodeHtmlEntities(t(item, props.options));\r\n }\r\n\r\n if (type === 'object') {\r\n const textContent = item.textContent ?? item.t;\r\n if (textContent && hasInterpolation(textContent, options.interpolation)) {\r\n item[isNode ? 't' : 'textContent'] = t(textContent, props.options);\r\n }\r\n }\r\n\r\n return item;\r\n};\r\n","import type { TFunction, i18n } from '@nerimity/i18lite';\r\nimport type { parse, stringify } from 'html-parse-string';\r\nimport type { ParentProps } from 'solid-js';\r\nimport type { TransProps } from '../Trans';\r\nimport { replaceElements } from './replace-elements';\r\nimport { translateWithInterpolation } from './translate-with-interpolation';\r\n\r\nexport let parseHTML: typeof parse;\r\nexport let stringifyHtml: typeof stringify;\r\n(async () => {\r\n try {\r\n // @ts-ignore\r\n const module = await import('html-parse-string');\r\n parseHTML = module.parse;\r\n stringifyHtml = module.stringify;\r\n } catch {}\r\n})();\r\n\r\nexport const htmlParseStringNotFoundError = () => {\r\n console.error(\r\n 'In order to use JSX nesting, install %chtml-parse-string',\r\n 'font-weight: 700',\r\n 'https://github.com/ryansolid/html-parse-string.'\r\n );\r\n};\r\nexport const translateJSX = (\r\n { i18n: { options }, t, props }: { t: TFunction; props: ParentProps<TransProps>; i18n: i18n },\r\n children: Node[]\r\n) => {\r\n const translation = t(props.key, props.options);\r\n\r\n if (!props.children) return translation;\r\n\r\n if (translation === props.key) return children.map(translateWithInterpolation(t, options, props));\r\n\r\n if (!parseHTML) {\r\n htmlParseStringNotFoundError();\r\n return;\r\n }\r\n try {\r\n const [ast] = parseHTML(`<0>${translation}</0>`);\r\n return children.map(replaceElements(ast, options));\r\n } catch (e) {\r\n console.error(e);\r\n }\r\n};\r\n","import type { TFunction, TOptions } from '@nerimity/i18lite';\r\nimport { stringify } from 'html-parse-string';\r\nimport { children, type JSXElement, type ParentComponent, type ParentProps } from 'solid-js';\r\nimport { Dynamic } from 'solid-js/web';\r\nimport { useTransContext } from './TransProvider';\r\nimport { htmlParseStringNotFoundError, parseHTML, translateJSX } from './utils/translate-jsx';\r\n\r\nexport type TransProps = {\r\n key: string;\r\n options?: TOptions;\r\n components?: Record<string, JSXElement | ((props: any) => JSXElement)>;\r\n};\r\n\r\nexport const Trans: ParentComponent<TransProps> = (props) => {\r\n const [t, { getI18next }] = useTransContext();\r\n\r\n return (\r\n <>\r\n {props.components\r\n ? renderInterpolatedTranslation({ t, props })\r\n : typeof props.children === 'string'\r\n ? t(props.key, props.children, props.options)\r\n : translateJSX({ i18n: getI18next(), t, props }, children(() => props.children)() as Node[])}\r\n </>\r\n );\r\n};\r\n\r\nconst renderInterpolatedTranslation = ({ t, props }: { t: TFunction; props: ParentProps<TransProps> }) => {\r\n const translatedString = t(props.key, props.options);\r\n\r\n if (!parseHTML) {\r\n htmlParseStringNotFoundError();\r\n return;\r\n }\r\n\r\n const [ast] = parseHTML(`<0>${translatedString}</0>`);\r\n\r\n return ast.children.map((node) => {\r\n if (node.type === 'text') {\r\n return node.content;\r\n }\r\n\r\n const componentKey = node.name;\r\n const mappedComponent = props.components?.[componentKey];\r\n\r\n if (!mappedComponent) {\r\n return node.content;\r\n }\r\n\r\n if (typeof mappedComponent === 'function') {\r\n return <Dynamic component={mappedComponent} children={stringify(node.children)} />;\r\n }\r\n\r\n return mappedComponent;\r\n });\r\n};\r\n"],"names":["TransContext","createContext","createTransContext","instance","options","language","setLanguage","createSignal","init","changeLanguage","lng","addResources","ns","resources","bundleOptions","addResourceBundle","deep","overwrite","t","args","getI18next","useTransContext","useContext","TransProvider","props","_$createComponent","Provider","value","i18next","children","tempElement","decodeHtmlEntities","encodedText","hasInterpolation","prefix","suffix","replaceElements","ast","interpolation","child","index","isNode","translateWithInterpolation","item","type","textContent","parseHTML","stringifyHtml","module","htmlParseStringNotFoundError","translateJSX","translation","e","Trans","_$memo","components","renderInterpolatedTranslation","key","i18n","translatedString","map","node","content","componentKey","name","mappedComponent","Dynamic","component","stringify"],"mappings":";;;;AASA,MAAMA,IAAeC,EAAAA;AAErB,SAASC,EAAmBC,GAAgBC,GAAyD;AACnG,QAAM,CAACC,GAAUC,CAAW,IAAIC,EAAa,IAAI;AAEjDJ,EAAAA,EAASK,KAAKJ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A,IAGzEoC,IAPEJ,EAAKC;AAAAA,EAQhB,CAAC;AACH;"}
|
package/dist/ssr.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var w=Object.create;var h=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var E=(t,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of I(n))!b.call(t,o)&&o!==e&&h(t,o,{get:()=>n[o],enumerable:!(r=v(n,o))||r.enumerable});return t};var L=(t,n,e)=>(e=t!=null?w(P(t)):{},E(n||!t||!t.__esModule?h(e,"default",{value:t,enumerable:!0}):e,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("solid-js/web"),k=require("html-parse-string"),l=require("solid-js"),q=require("@nerimity/i18lite"),y=l.createContext();function H(t,n){const[e,r]=l.createSignal(null);t.init(n,()=>r(()=>t.language));async function o(i){await t.changeLanguage(i),r(()=>i)}function c(i,T,S,f={}){return t.addResourceBundle(i,T,S,f.deep,f.overwrite)}return[(...i)=>(e(),t.t(...i)),{addResources:c,getI18next:()=>t,changeLanguage:o}]}const x=()=>l.useContext(y),J=t=>g.createComponent(y.Provider,{get value(){return H(t.instance||q,{lng:t.lng,...t.options})},get children(){return t.children}}),m=document.createElement("textarea");function u(t){return m.innerHTML=t||"",m.value}const d=(t,{prefix:n,suffix:e})=>t.includes(n)&&t.includes(e),M=(t,{interpolation:n})=>(e,r)=>typeof e=="string"?d(e,n)?u(t.children[r].children?.[0].content):u(t.children[r].content):(e.textContent=u(t.children[r].children?.[0].content),e),j=!globalThis.window,p=(t,n,e)=>r=>{const o=typeof r;if(o==="string"&&d(r,n.interpolation))return u(t(r,e.options));if(o==="object"){const c=r.textContent??r.t;c&&d(c,n.interpolation)&&(r[j?"t":"textContent"]=t(c,e.options))}return r};let s,N;(async()=>{try{const t=await import("html-parse-string");s=t.parse,N=t.stringify}catch{}})();const C=()=>{console.error("In order to use JSX nesting, install %chtml-parse-string","font-weight: 700","https://github.com/ryansolid/html-parse-string.")},R=({i18n:{options:t},t:n,props:e},r)=>{const o=n(e.key,e.options);if(!e.children)return o;if(o===e.key)return r.map(p(n,t,e));if(!s){C();return}try{const[c]=s(`<0>${o}</0>`);return r.map(M(c,t))}catch(c){console.error(c)}},X=t=>{const[n,{getI18next:e}]=x();return t.components?$({t:n,props:t}):typeof t.children=="string"?n(t.key,t.children,t.options):R({i18n:e(),t:n,props:t},l.children(()=>t.children)())},$=({t,props:n})=>{const e=t(n.key,n.options);if(!s){C();return}const[r]=s(`<0>${e}</0>`);return r.children.map(o=>{if(o.type==="text")return o.content;const c=o.name,a=n.components?.[c];return a?typeof a=="function"?g.createComponent(g.Dynamic,{component:a,get children(){return k.stringify(o.children)}}):a:o.content})};exports.Trans=X;exports.TransProvider=J;exports.useTransContext=x;
|
|
2
2
|
//# sourceMappingURL=ssr.js.map
|
package/dist/ssr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr.js","sources":["../src/TransProvider.tsx","../src/utils/decodeHtmlEntities.ts","../src/utils/has-interpolation.ts","../src/utils/replace-elements.ts","../src/utils/translate-with-interpolation.ts","../src/utils/translate-jsx.ts","../src/Trans.tsx"],"sourcesContent":["import i18next, { type InitOptions, type TFunction, type i18n } from '@nerimity/i18lite';\r\nimport { createContext, createSignal, useContext, type ParentComponent } from 'solid-js';\r\n\r\nexport type TransProviderActions = {\r\n addResources(lng: string, ns: string, resources: any): i18n;\r\n changeLanguage(lng: string): Promise<void>;\r\n getI18next(): i18n;\r\n};\r\n\r\nconst TransContext = createContext<[TFunction, TransProviderActions]>();\r\n\r\nfunction createTransContext(instance: i18n, options: InitOptions): [TFunction, TransProviderActions] {\r\n const [translate, setTranslate] = createSignal<TFunction | (() => null)>(\r\n !!options.resources ? instance.t : () => null\r\n );\r\n\r\n instance.on('loaded', () => setTranslate(() => instance.t));\r\n instance.init(options, (_, t) => setTranslate(() => t));\r\n\r\n async function changeLanguage(lng: string) {\r\n const t = await instance.changeLanguage(lng);\r\n setTranslate(() => t);\r\n }\r\n\r\n function addResources(\r\n lng: string,\r\n ns: string,\r\n resources: any,\r\n bundleOptions: { deep?: boolean; overwrite?: boolean } = {}\r\n ): i18n {\r\n return instance.addResourceBundle(lng, ns, resources, bundleOptions.deep, bundleOptions.overwrite);\r\n }\r\n\r\n return [\r\n ((...args: Parameters<TFunction>) => translate().apply(null, args)) as TFunction,\r\n {\r\n addResources,\r\n getI18next: () => instance,\r\n changeLanguage,\r\n },\r\n ];\r\n}\r\n\r\nexport const useTransContext = () => useContext(TransContext);\r\n\r\nexport const TransProvider: ParentComponent<{ instance?: i18n; lng?: string; options?: InitOptions }> = (props) => {\r\n return (\r\n <TransContext.Provider\r\n value={createTransContext(props.instance || i18next, { lng: props.lng, ...props.options })}\r\n children={props.children}\r\n />\r\n );\r\n};\r\n","const tempElement = document.createElement('textarea');\r\nexport function decodeHtmlEntities(encodedText: string) {\r\n tempElement.innerHTML = encodedText || '';\r\n\r\n return tempElement.value;\r\n}\r\n","import type { InterpolationOptions } from '@nerimity/i18lite';\r\n\r\nexport const hasInterpolation = (value: string, { prefix, suffix }: InterpolationOptions) =>\r\n value.includes(prefix) && value.includes(suffix);\r\n","import type { InitOptions } from '@nerimity/i18lite';\r\nimport type { IDom } from 'html-parse-string';\r\nimport { decodeHtmlEntities } from './decodeHtmlEntities';\r\nimport { hasInterpolation } from './has-interpolation';\r\n\r\nexport const replaceElements =\r\n (ast: IDom, { interpolation }: InitOptions) =>\r\n (child: Node, index: number) => {\r\n if (typeof child === 'string') {\r\n if (hasInterpolation(child, interpolation)) return decodeHtmlEntities(ast.children[index].children?.[0].content);\r\n\r\n return decodeHtmlEntities(ast.children[index].content);\r\n }\r\n\r\n child.textContent = decodeHtmlEntities(ast.children[index].children?.[0].content);\r\n\r\n return child;\r\n };\r\n","import type { InitOptions, TFunction } from '@nerimity/i18lite';\r\nimport type { TransProps } from '../Trans';\r\nimport { decodeHtmlEntities } from './decodeHtmlEntities';\r\nimport { hasInterpolation } from './has-interpolation';\r\n\r\nconst isNode = !globalThis.window;\r\n\r\nexport const translateWithInterpolation = (t: TFunction, options: InitOptions, props: TransProps) => (item) => {\r\n const type = typeof item;\r\n\r\n if (type === 'string' && hasInterpolation(item, options.interpolation)) {\r\n return decodeHtmlEntities(t(item, props.options));\r\n }\r\n\r\n if (type === 'object') {\r\n const textContent = item.textContent ?? item.t;\r\n if (textContent && hasInterpolation(textContent, options.interpolation)) {\r\n item[isNode ? 't' : 'textContent'] = t(textContent, props.options);\r\n }\r\n }\r\n\r\n return item;\r\n};\r\n","import type { TFunction, i18n } from '@nerimity/i18lite';\r\nimport type { parse } from 'html-parse-string';\r\nimport type { ParentProps } from 'solid-js';\r\nimport type { TransProps } from '../Trans';\r\nimport { replaceElements } from './replace-elements';\r\nimport { translateWithInterpolation } from './translate-with-interpolation';\r\n\r\nexport let parseHTML: typeof parse;\r\n\r\n(async () => {\r\n try {\r\n // @ts-ignore\r\n const module = await import('html-parse-string');\r\n parseHTML = module.parse;\r\n } catch {}\r\n})();\r\n\r\nconst htmlParseStringNotFoundError = () => {\r\n console.error(\r\n 'In order to use JSX nesting, install %chtml-parse-string',\r\n 'font-weight: 700',\r\n 'https://github.com/ryansolid/html-parse-string.'\r\n );\r\n};\r\nexport const translateJSX = (\r\n { i18n: { options }, t, props }: { t: TFunction; props: ParentProps<TransProps>; i18n: i18n },\r\n children: Node[]\r\n) => {\r\n const translation = t(props.key, props.options);\r\n\r\n if (!props.children) return translation;\r\n\r\n if (translation === props.key) return children.map(translateWithInterpolation(t, options, props));\r\n\r\n if (!parseHTML) {\r\n htmlParseStringNotFoundError();\r\n return;\r\n }\r\n try {\r\n const [ast] = parseHTML(`<0>${translation}</0>`);\r\n return children.map(replaceElements(ast, options));\r\n } catch (e) {\r\n console.error(e);\r\n }\r\n};\r\n","import type { TOptions } from '@nerimity/i18lite';\r\nimport { children, type ParentComponent } from 'solid-js';\r\nimport { useTransContext } from './TransProvider';\r\nimport { translateJSX } from './utils/translate-jsx';\r\n\r\nexport type TransProps = { key: string; options?: TOptions };\r\n\r\nexport const Trans: ParentComponent<TransProps> = (props) => {\r\n const [t, { getI18next }] = useTransContext();\r\n\r\n return (\r\n <>\r\n {typeof props.children === 'string'\r\n ? t(props.key, props.children, props.options)\r\n : translateJSX({ i18n: getI18next(), t, props }, children(() => props.children)() as Node[])}\r\n </>\r\n );\r\n};\r\n"],"names":["TransContext","createContext","createTransContext","instance","options","translate","setTranslate","createSignal","resources","t","on","init","_","changeLanguage","lng","addResources","ns","bundleOptions","addResourceBundle","deep","overwrite","args","apply","getI18next","useTransContext","useContext","TransProvider","props","_$createComponent","Provider","value","i18next","children","tempElement","decodeHtmlEntities","encodedText","hasInterpolation","prefix","suffix","replaceElements","ast","interpolation","child","index","isNode","translateWithInterpolation","item","type","textContent","parseHTML","htmlParseStringNotFoundError","translateJSX","translation","e","Trans","key","i18n"],"mappings":"gnBASMA,EAAeC,EAAAA,cAAAA,EAErB,SAASC,EAAmBC,EAAgBC,EAAyD,CACnG,KAAM,CAACC,EAAWC,CAAY,EAAIC,eAC9BH,EAAQI,UAAYL,EAASM,EAAI,IAAM,IAC3C,EAEAN,EAASO,GAAG,SAAU,IAAMJ,EAAa,IAAMH,EAASM,CAAC,CAAC,EAC1DN,EAASQ,KAAKP,EAAS,CAACQ,EAAGH,IAAMH,EAAa,IAAMG,CAAC,CAAC,EAEtD,eAAeI,EAAeC,EAAa,CACzC,MAAML,EAAI,MAAMN,EAASU,eAAeC,CAAG,EAC3CR,EAAa,IAAMG,CAAC,CACtB,CAEA,SAASM,EACPD,EACAE,EACAR,EACAS,EAAyD,CAAA,EACnD,CACN,OAAOd,EAASe,kBAAkBJ,EAAKE,EAAIR,EAAWS,EAAcE,KAAMF,EAAcG,SAAS,CACnG,CAEA,MAAO,EACJ,IAAIC,IAAgChB,EAAAA,EA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AAiBY,EAAa5C,EAAQ,aAAa,IACpE0C,EAAKF,EAAS,IAAM,aAAa,EAAI,EAAEI,EAAarB,EAAM,OAAO,EAErE,CAEA,OAAOmB,CACT,ECfO,IAAIG,GAEV,SAAY,CACX,GAAI,CAGFA,GADe,KAAM,QAAO,mBAAmB,GAC5B,KACrB,MAAQ,CAAC,CACX,GAAA,EAEA,MAAMC,EAA+B,IAAM,CACzC,QAAQ,MACN,2DACA,mBACA,iDAAA,CAEJ,EACaC,EAAe,CAC1B,CAAE,KAAM,CAAE,QAAA/C,GAAW,EAAAK,EAAG,MAAAkB,CAAA,EACxBK,IACG,CACH,MAAMoB,EAAc3C,EAAEkB,EAAM,IAAKA,EAAM,OAAO,EAE9C,GAAI,CAACA,EAAM,SAAU,OAAOyB,EAE5B,GAAIA,IAAgBzB,EAAM,IAAK,OAAOK,EAAS,IAAIa,EAA2BpC,EAAGL,EAASuB,CAAK,CAAC,EAEhG,GAAI,CAACsB,EAAW,CACdC,EAAA,EACA,MACF,CACA,GAAI,CACF,KAAM,CAACV,CAAG,EAAIS,EAAU,MAAMG,CAAW,MAAM,EAC/C,OAAOpB,EAAS,IAAIO,EAAgBC,EAAKpC,CAAO,CAAC,CACnD,OAASiD,EAAG,CACV,QAAQ,MAAMA,CAAC,CACjB,CACF,ECrCaC,EAAsC3B,GAAU,CAC3D,KAAM,CAAClB,EAAG,CAAEc,WAAAA,CAAAA,CAAY,EAAIC,EAAAA,EAE5B,OAEK,OAAOG,EAAMK,UAAa,SACvBvB,EAAEkB,EAAM4B,IAAK5B,EAAMK,SAAUL,EAAMvB,OAAO,EAC1C+C,EAAa,CAAEK,KAAMjC,EAAAA,EAAcd,EAAAA,EAAGkB,MAAAA,CAAAA,EAASK,WAAS,IAAML,EAAMK,QAAQ,GAAa,CAGnG"}
|
|
1
|
+
{"version":3,"file":"ssr.js","sources":["../src/TransProvider.tsx","../src/utils/decodeHtmlEntities.ts","../src/utils/has-interpolation.ts","../src/utils/replace-elements.ts","../src/utils/translate-with-interpolation.ts","../src/utils/translate-jsx.ts","../src/Trans.tsx"],"sourcesContent":["import i18next, { type InitOptions, type TFunction, type i18n } from '@nerimity/i18lite';\r\nimport { createContext, createSignal, useContext, type ParentComponent } from 'solid-js';\r\n\r\nexport type TransProviderActions = {\r\n addResources(lng: string, ns: string, resources: any): i18n;\r\n changeLanguage(lng: string): Promise<void>;\r\n getI18next(): i18n;\r\n};\r\n\r\nconst TransContext = createContext<[TFunction, TransProviderActions]>();\r\n\r\nfunction createTransContext(instance: i18n, options: InitOptions): [TFunction, TransProviderActions] {\r\n const [language, setLanguage] = createSignal(null);\r\n\r\n instance.init(options, () => setLanguage(() => instance.language));\r\n\r\n async function changeLanguage(lng: string) {\r\n await instance.changeLanguage(lng);\r\n setLanguage(() => lng);\r\n }\r\n\r\n function addResources(\r\n lng: string,\r\n ns: string,\r\n resources: any,\r\n bundleOptions: { deep?: boolean; overwrite?: boolean } = {},\r\n ): i18n {\r\n return instance.addResourceBundle(lng, ns, resources, bundleOptions.deep, bundleOptions.overwrite);\r\n }\r\n\r\n const t = (...args: Parameters<TFunction>) => {\r\n // Access the signal to track it - this ensures components re-render when language changes\r\n language();\r\n return instance.t(...args);\r\n };\r\n\r\n return [\r\n t,\r\n {\r\n addResources,\r\n getI18next: () => instance,\r\n changeLanguage,\r\n },\r\n ];\r\n}\r\n\r\nexport const useTransContext = () => useContext(TransContext);\r\n\r\nexport const TransProvider: ParentComponent<{ instance?: i18n; lng?: string; options?: InitOptions }> = (props) => {\r\n return (\r\n <TransContext.Provider\r\n value={createTransContext(props.instance || i18next, { lng: props.lng, ...props.options })}\r\n children={props.children}\r\n />\r\n );\r\n};\r\n","const tempElement = document.createElement('textarea');\r\nexport function decodeHtmlEntities(encodedText: string) {\r\n tempElement.innerHTML = encodedText || '';\r\n\r\n return tempElement.value;\r\n}\r\n","import type { InterpolationOptions } from '@nerimity/i18lite';\r\n\r\nexport const hasInterpolation = (value: string, { prefix, suffix }: InterpolationOptions) =>\r\n value.includes(prefix) && value.includes(suffix);\r\n","import type { InitOptions } from '@nerimity/i18lite';\r\nimport type { IDom } from 'html-parse-string';\r\nimport { decodeHtmlEntities } from './decodeHtmlEntities';\r\nimport { hasInterpolation } from './has-interpolation';\r\n\r\nexport const replaceElements =\r\n (ast: IDom, { interpolation }: InitOptions) =>\r\n (child: Node, index: number) => {\r\n if (typeof child === 'string') {\r\n if (hasInterpolation(child, interpolation)) return decodeHtmlEntities(ast.children[index].children?.[0].content);\r\n\r\n return decodeHtmlEntities(ast.children[index].content);\r\n }\r\n\r\n child.textContent = decodeHtmlEntities(ast.children[index].children?.[0].content);\r\n\r\n return child;\r\n };\r\n","import type { InitOptions, TFunction } from '@nerimity/i18lite';\r\nimport type { TransProps } from '../Trans';\r\nimport { decodeHtmlEntities } from './decodeHtmlEntities';\r\nimport { hasInterpolation } from './has-interpolation';\r\n\r\nconst isNode = !globalThis.window;\r\n\r\nexport const translateWithInterpolation = (t: TFunction, options: InitOptions, props: TransProps) => (item) => {\r\n const type = typeof item;\r\n\r\n if (type === 'string' && hasInterpolation(item, options.interpolation)) {\r\n return decodeHtmlEntities(t(item, props.options));\r\n }\r\n\r\n if (type === 'object') {\r\n const textContent = item.textContent ?? item.t;\r\n if (textContent && hasInterpolation(textContent, options.interpolation)) {\r\n item[isNode ? 't' : 'textContent'] = t(textContent, props.options);\r\n }\r\n }\r\n\r\n return item;\r\n};\r\n","import type { TFunction, i18n } from '@nerimity/i18lite';\r\nimport type { parse, stringify } from 'html-parse-string';\r\nimport type { ParentProps } from 'solid-js';\r\nimport type { TransProps } from '../Trans';\r\nimport { replaceElements } from './replace-elements';\r\nimport { translateWithInterpolation } from './translate-with-interpolation';\r\n\r\nexport let parseHTML: typeof parse;\r\nexport let stringifyHtml: typeof stringify;\r\n(async () => {\r\n try {\r\n // @ts-ignore\r\n const module = await import('html-parse-string');\r\n parseHTML = module.parse;\r\n stringifyHtml = module.stringify;\r\n } catch {}\r\n})();\r\n\r\nexport const htmlParseStringNotFoundError = () => {\r\n console.error(\r\n 'In order to use JSX nesting, install %chtml-parse-string',\r\n 'font-weight: 700',\r\n 'https://github.com/ryansolid/html-parse-string.'\r\n );\r\n};\r\nexport const translateJSX = (\r\n { i18n: { options }, t, props }: { t: TFunction; props: ParentProps<TransProps>; i18n: i18n },\r\n children: Node[]\r\n) => {\r\n const translation = t(props.key, props.options);\r\n\r\n if (!props.children) return translation;\r\n\r\n if (translation === props.key) return children.map(translateWithInterpolation(t, options, props));\r\n\r\n if (!parseHTML) {\r\n htmlParseStringNotFoundError();\r\n return;\r\n }\r\n try {\r\n const [ast] = parseHTML(`<0>${translation}</0>`);\r\n return children.map(replaceElements(ast, options));\r\n } catch (e) {\r\n console.error(e);\r\n }\r\n};\r\n","import type { TFunction, TOptions } from '@nerimity/i18lite';\r\nimport { stringify } from 'html-parse-string';\r\nimport { children, type JSXElement, type ParentComponent, type ParentProps } from 'solid-js';\r\nimport { Dynamic } from 'solid-js/web';\r\nimport { useTransContext } from './TransProvider';\r\nimport { htmlParseStringNotFoundError, parseHTML, translateJSX } from './utils/translate-jsx';\r\n\r\nexport type TransProps = {\r\n key: string;\r\n options?: TOptions;\r\n components?: Record<string, JSXElement | ((props: any) => JSXElement)>;\r\n};\r\n\r\nexport const Trans: ParentComponent<TransProps> = (props) => {\r\n const [t, { getI18next }] = useTransContext();\r\n\r\n return (\r\n <>\r\n {props.components\r\n ? renderInterpolatedTranslation({ t, props })\r\n : typeof props.children === 'string'\r\n ? t(props.key, props.children, props.options)\r\n : translateJSX({ i18n: getI18next(), t, props }, children(() => props.children)() as Node[])}\r\n </>\r\n );\r\n};\r\n\r\nconst renderInterpolatedTranslation = ({ t, props }: { t: TFunction; props: ParentProps<TransProps> }) => {\r\n const translatedString = t(props.key, props.options);\r\n\r\n if (!parseHTML) {\r\n htmlParseStringNotFoundError();\r\n return;\r\n }\r\n\r\n const [ast] = parseHTML(`<0>${translatedString}</0>`);\r\n\r\n return ast.children.map((node) => {\r\n if (node.type === 'text') {\r\n return node.content;\r\n }\r\n\r\n const componentKey = node.name;\r\n const mappedComponent = props.components?.[componentKey];\r\n\r\n if (!mappedComponent) {\r\n return node.content;\r\n }\r\n\r\n if (typeof mappedComponent === 'function') {\r\n return <Dynamic component={mappedComponent} children={stringify(node.children)} />;\r\n }\r\n\r\n return mappedComponent;\r\n });\r\n};\r\n"],"names":["TransContext","createContext","createTransContext","instance","options","language","setLanguage","createSignal","init","changeLanguage","lng","addResources","ns","resources","bundleOptions","addResourceBundle","deep","overwrite","t","args","getI18next","useTransContext","useContext","TransProvider","props","_$createComponent","Provider","value","i18next","children","tempElement","decodeHtmlEntities","encodedText","hasInterpolation","prefix","suffix","replaceElements","ast","interpolation","child","index","isNode","translateWithInterpolation","item","type","textContent","parseHTML","stringifyHtml","module","htmlParseStringNotFoundError","translateJSX","translation","e","Trans","components","renderInterpolatedTranslation","key","i18n","translatedString","map","node","content","componentKey","name","mappedComponent","Dynamic","component","stringify"],"mappings":"+oBASMA,EAAeC,EAAAA,cAAAA,EAErB,SAASC,EAAmBC,EAAgBC,EAAyD,CACnG,KAAM,CAACC,EAAUC,CAAW,EAAIC,EAAAA,aAAa,IAAI,EAEjDJ,EAASK,KAAKJ,EAAS,IAAME,EAAY,IAAMH,EAASE,QAAQ,CAAC,EAEjE,eAAeI,EAAeC,EAAa,CACzC,MAAMP,EAASM,eAAeC,CAAG,EACjCJ,EAAY,IAAMI,CAAG,CACvB,CAEA,SAASC,EACPD,EACAE,EACAC,EACAC,EAAyD,CAAA,EACnD,CACN,OAAOX,EAASY,kBAAkBL,EAAKE,EAAIC,EAAWC,EAAcE,KAAMF,EAAcG,SAAS,CACnG,CAQA,MAAO,CANGC,IAAIC,KAEZd,EAAAA,EACOF,EAASe,EAAE,GAAGC,CAAI,GAKzB,CACER,aAAAA,EACAS,WAAYA,IAAMjB,EAClBM,eAAAA,CAAAA,CACD,CAEL,CAEO,MAAMY,EAAkBA,IAAMC,EAAAA,WAAWtB,CAAY,EAE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,EACA,MACF,CAEA,KAAM,CAACZ,CAAG,EAAIS,EAAU,MAAMY,CAAgB,MAAM,EAEpD,OAAOrB,EAAIR,SAAS8B,IAAKC,GAAS,CAChC,GAAIA,EAAKhB,OAAS,OAChB,OAAOgB,EAAKC,QAGd,MAAMC,EAAeF,EAAKG,KACpBC,EAAkBxC,EAAM8B,aAAaQ,CAAY,EAEvD,OAAKE,EAID,OAAOA,GAAoB,WAC7BvC,EAAAA,gBAAQwC,EAAAA,QAAO,CAACC,UAAWF,EAAe,IAAEnC,UAAQ,CAAA,OAAEsC,EAAAA,UAAUP,EAAK/B,QAAQ,CAAC,CAAA,CAAA,EAGzEmC,EAPEJ,EAAKC,OAQhB,CAAC,CACH"}
|
package/dist/ssr.mjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import w from "
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { createComponent as d, Dynamic as C } from "solid-js/web";
|
|
2
|
+
import { stringify as T } from "html-parse-string";
|
|
3
|
+
import { useContext as w, createContext as I, createSignal as p, children as E } from "solid-js";
|
|
4
|
+
import L from "@nerimity/i18lite";
|
|
5
|
+
const m = I();
|
|
6
|
+
function S(t, e) {
|
|
7
|
+
const [n, r] = p(null);
|
|
8
|
+
t.init(e, () => r(() => t.language));
|
|
9
|
+
async function o(i) {
|
|
10
|
+
await t.changeLanguage(i), r(() => i);
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
return t.addResourceBundle(
|
|
12
|
+
function c(i, y, x, g = {}) {
|
|
13
|
+
return t.addResourceBundle(i, y, x, g.deep, g.overwrite);
|
|
14
14
|
}
|
|
15
|
-
return [(
|
|
16
|
-
addResources:
|
|
15
|
+
return [(...i) => (n(), t.t(...i)), {
|
|
16
|
+
addResources: c,
|
|
17
17
|
getI18next: () => t,
|
|
18
|
-
changeLanguage:
|
|
18
|
+
changeLanguage: o
|
|
19
19
|
}];
|
|
20
20
|
}
|
|
21
|
-
const
|
|
21
|
+
const k = () => w(m), j = (t) => d(m.Provider, {
|
|
22
22
|
get value() {
|
|
23
|
-
return
|
|
23
|
+
return S(t.instance || L, {
|
|
24
24
|
lng: t.lng,
|
|
25
25
|
...t.options
|
|
26
26
|
});
|
|
@@ -28,60 +28,85 @@ const I = () => m(h), M = (t) => T(h.Provider, {
|
|
|
28
28
|
get children() {
|
|
29
29
|
return t.children;
|
|
30
30
|
}
|
|
31
|
-
}),
|
|
31
|
+
}), f = document.createElement("textarea");
|
|
32
32
|
function l(t) {
|
|
33
|
-
return
|
|
33
|
+
return f.innerHTML = t || "", f.value;
|
|
34
34
|
}
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
return l(t(
|
|
39
|
-
if (
|
|
40
|
-
const
|
|
41
|
-
|
|
35
|
+
const u = (t, { prefix: e, suffix: n }) => t.includes(e) && t.includes(n), v = (t, { interpolation: e }) => (n, r) => typeof n == "string" ? u(n, e) ? l(t.children[r].children?.[0].content) : l(t.children[r].content) : (n.textContent = l(t.children[r].children?.[0].content), n), H = !globalThis.window, P = (t, e, n) => (r) => {
|
|
36
|
+
const o = typeof r;
|
|
37
|
+
if (o === "string" && u(r, e.interpolation))
|
|
38
|
+
return l(t(r, n.options));
|
|
39
|
+
if (o === "object") {
|
|
40
|
+
const c = r.textContent ?? r.t;
|
|
41
|
+
c && u(c, e.interpolation) && (r[H ? "t" : "textContent"] = t(c, n.options));
|
|
42
42
|
}
|
|
43
|
-
return
|
|
43
|
+
return r;
|
|
44
44
|
};
|
|
45
|
-
let
|
|
45
|
+
let s, b;
|
|
46
46
|
(async () => {
|
|
47
47
|
try {
|
|
48
|
-
|
|
48
|
+
const t = await import("html-parse-string");
|
|
49
|
+
s = t.parse, b = t.stringify;
|
|
49
50
|
} catch {
|
|
50
51
|
}
|
|
51
52
|
})();
|
|
52
|
-
const
|
|
53
|
+
const h = () => {
|
|
53
54
|
console.error(
|
|
54
55
|
"In order to use JSX nesting, install %chtml-parse-string",
|
|
55
56
|
"font-weight: 700",
|
|
56
57
|
"https://github.com/ryansolid/html-parse-string."
|
|
57
58
|
);
|
|
58
|
-
},
|
|
59
|
-
const
|
|
60
|
-
if (!n.children) return
|
|
61
|
-
if (
|
|
62
|
-
if (!
|
|
63
|
-
|
|
59
|
+
}, J = ({ i18n: { options: t }, t: e, props: n }, r) => {
|
|
60
|
+
const o = e(n.key, n.options);
|
|
61
|
+
if (!n.children) return o;
|
|
62
|
+
if (o === n.key) return r.map(P(e, t, n));
|
|
63
|
+
if (!s) {
|
|
64
|
+
h();
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
66
67
|
try {
|
|
67
|
-
const [
|
|
68
|
-
return
|
|
69
|
-
} catch (
|
|
70
|
-
console.error(
|
|
68
|
+
const [c] = s(`<0>${o}</0>`);
|
|
69
|
+
return r.map(v(c, t));
|
|
70
|
+
} catch (c) {
|
|
71
|
+
console.error(c);
|
|
71
72
|
}
|
|
72
|
-
},
|
|
73
|
-
const [
|
|
73
|
+
}, B = (t) => {
|
|
74
|
+
const [e, {
|
|
74
75
|
getI18next: n
|
|
75
|
-
}] =
|
|
76
|
-
return
|
|
76
|
+
}] = k();
|
|
77
|
+
return t.components ? M({
|
|
78
|
+
t: e,
|
|
79
|
+
props: t
|
|
80
|
+
}) : typeof t.children == "string" ? e(t.key, t.children, t.options) : J({
|
|
77
81
|
i18n: n(),
|
|
78
|
-
t:
|
|
82
|
+
t: e,
|
|
79
83
|
props: t
|
|
80
|
-
},
|
|
84
|
+
}, E(() => t.children)());
|
|
85
|
+
}, M = ({
|
|
86
|
+
t,
|
|
87
|
+
props: e
|
|
88
|
+
}) => {
|
|
89
|
+
const n = t(e.key, e.options);
|
|
90
|
+
if (!s) {
|
|
91
|
+
h();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const [r] = s(`<0>${n}</0>`);
|
|
95
|
+
return r.children.map((o) => {
|
|
96
|
+
if (o.type === "text")
|
|
97
|
+
return o.content;
|
|
98
|
+
const c = o.name, a = e.components?.[c];
|
|
99
|
+
return a ? typeof a == "function" ? d(C, {
|
|
100
|
+
component: a,
|
|
101
|
+
get children() {
|
|
102
|
+
return T(o.children);
|
|
103
|
+
}
|
|
104
|
+
}) : a : o.content;
|
|
105
|
+
});
|
|
81
106
|
};
|
|
82
107
|
export {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
108
|
+
B as Trans,
|
|
109
|
+
j as TransProvider,
|
|
110
|
+
k as useTransContext
|
|
86
111
|
};
|
|
87
112
|
//# sourceMappingURL=ssr.mjs.map
|
package/dist/ssr.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr.mjs","sources":["../src/TransProvider.tsx","../src/utils/decodeHtmlEntities.ts","../src/utils/has-interpolation.ts","../src/utils/replace-elements.ts","../src/utils/translate-with-interpolation.ts","../src/utils/translate-jsx.ts","../src/Trans.tsx"],"sourcesContent":["import i18next, { type InitOptions, type TFunction, type i18n } from '@nerimity/i18lite';\r\nimport { createContext, createSignal, useContext, type ParentComponent } from 'solid-js';\r\n\r\nexport type TransProviderActions = {\r\n addResources(lng: string, ns: string, resources: any): i18n;\r\n changeLanguage(lng: string): Promise<void>;\r\n getI18next(): i18n;\r\n};\r\n\r\nconst TransContext = createContext<[TFunction, TransProviderActions]>();\r\n\r\nfunction createTransContext(instance: i18n, options: InitOptions): [TFunction, TransProviderActions] {\r\n const [translate, setTranslate] = createSignal<TFunction | (() => null)>(\r\n !!options.resources ? instance.t : () => null\r\n );\r\n\r\n instance.on('loaded', () => setTranslate(() => instance.t));\r\n instance.init(options, (_, t) => setTranslate(() => t));\r\n\r\n async function changeLanguage(lng: string) {\r\n const t = await instance.changeLanguage(lng);\r\n setTranslate(() => t);\r\n }\r\n\r\n function addResources(\r\n lng: string,\r\n ns: string,\r\n resources: any,\r\n bundleOptions: { deep?: boolean; overwrite?: boolean } = {}\r\n ): i18n {\r\n return instance.addResourceBundle(lng, ns, resources, bundleOptions.deep, bundleOptions.overwrite);\r\n }\r\n\r\n return [\r\n ((...args: Parameters<TFunction>) => translate().apply(null, args)) as TFunction,\r\n {\r\n addResources,\r\n getI18next: () => instance,\r\n changeLanguage,\r\n },\r\n ];\r\n}\r\n\r\nexport const useTransContext = () => useContext(TransContext);\r\n\r\nexport const TransProvider: ParentComponent<{ instance?: i18n; lng?: string; options?: InitOptions }> = (props) => {\r\n return (\r\n <TransContext.Provider\r\n value={createTransContext(props.instance || i18next, { lng: props.lng, ...props.options })}\r\n children={props.children}\r\n />\r\n );\r\n};\r\n","const tempElement = document.createElement('textarea');\r\nexport function decodeHtmlEntities(encodedText: string) {\r\n tempElement.innerHTML = encodedText || '';\r\n\r\n return tempElement.value;\r\n}\r\n","import type { InterpolationOptions } from '@nerimity/i18lite';\r\n\r\nexport const hasInterpolation = (value: string, { prefix, suffix }: InterpolationOptions) =>\r\n value.includes(prefix) && value.includes(suffix);\r\n","import type { InitOptions } from '@nerimity/i18lite';\r\nimport type { IDom } from 'html-parse-string';\r\nimport { decodeHtmlEntities } from './decodeHtmlEntities';\r\nimport { hasInterpolation } from './has-interpolation';\r\n\r\nexport const replaceElements =\r\n (ast: IDom, { interpolation }: InitOptions) =>\r\n (child: Node, index: number) => {\r\n if (typeof child === 'string') {\r\n if (hasInterpolation(child, interpolation)) return decodeHtmlEntities(ast.children[index].children?.[0].content);\r\n\r\n return decodeHtmlEntities(ast.children[index].content);\r\n }\r\n\r\n child.textContent = decodeHtmlEntities(ast.children[index].children?.[0].content);\r\n\r\n return child;\r\n };\r\n","import type { InitOptions, TFunction } from '@nerimity/i18lite';\r\nimport type { TransProps } from '../Trans';\r\nimport { decodeHtmlEntities } from './decodeHtmlEntities';\r\nimport { hasInterpolation } from './has-interpolation';\r\n\r\nconst isNode = !globalThis.window;\r\n\r\nexport const translateWithInterpolation = (t: TFunction, options: InitOptions, props: TransProps) => (item) => {\r\n const type = typeof item;\r\n\r\n if (type === 'string' && hasInterpolation(item, options.interpolation)) {\r\n return decodeHtmlEntities(t(item, props.options));\r\n }\r\n\r\n if (type === 'object') {\r\n const textContent = item.textContent ?? item.t;\r\n if (textContent && hasInterpolation(textContent, options.interpolation)) {\r\n item[isNode ? 't' : 'textContent'] = t(textContent, props.options);\r\n }\r\n }\r\n\r\n return item;\r\n};\r\n","import type { TFunction, i18n } from '@nerimity/i18lite';\r\nimport type { parse } from 'html-parse-string';\r\nimport type { ParentProps } from 'solid-js';\r\nimport type { TransProps } from '../Trans';\r\nimport { replaceElements } from './replace-elements';\r\nimport { translateWithInterpolation } from './translate-with-interpolation';\r\n\r\nexport let parseHTML: typeof parse;\r\n\r\n(async () => {\r\n try {\r\n // @ts-ignore\r\n const module = await import('html-parse-string');\r\n parseHTML = module.parse;\r\n } catch {}\r\n})();\r\n\r\nconst htmlParseStringNotFoundError = () => {\r\n console.error(\r\n 'In order to use JSX nesting, install %chtml-parse-string',\r\n 'font-weight: 700',\r\n 'https://github.com/ryansolid/html-parse-string.'\r\n );\r\n};\r\nexport const translateJSX = (\r\n { i18n: { options }, t, props }: { t: TFunction; props: ParentProps<TransProps>; i18n: i18n },\r\n children: Node[]\r\n) => {\r\n const translation = t(props.key, props.options);\r\n\r\n if (!props.children) return translation;\r\n\r\n if (translation === props.key) return children.map(translateWithInterpolation(t, options, props));\r\n\r\n if (!parseHTML) {\r\n htmlParseStringNotFoundError();\r\n return;\r\n }\r\n try {\r\n const [ast] = parseHTML(`<0>${translation}</0>`);\r\n return children.map(replaceElements(ast, options));\r\n } catch (e) {\r\n console.error(e);\r\n }\r\n};\r\n","import type { TOptions } from '@nerimity/i18lite';\r\nimport { children, type ParentComponent } from 'solid-js';\r\nimport { useTransContext } from './TransProvider';\r\nimport { translateJSX } from './utils/translate-jsx';\r\n\r\nexport type TransProps = { key: string; options?: TOptions };\r\n\r\nexport const Trans: ParentComponent<TransProps> = (props) => {\r\n const [t, { getI18next }] = useTransContext();\r\n\r\n return (\r\n <>\r\n {typeof props.children === 'string'\r\n ? t(props.key, props.children, props.options)\r\n : translateJSX({ i18n: getI18next(), t, props }, children(() => props.children)() as Node[])}\r\n </>\r\n );\r\n};\r\n"],"names":["TransContext","createContext","createTransContext","instance","options","translate","setTranslate","createSignal","resources","t","on","init","_","changeLanguage","lng","addResources","ns","bundleOptions","addResourceBundle","deep","overwrite","args","apply","getI18next","useTransContext","useContext","TransProvider","props","_$createComponent","Provider","value","i18next","children","tempElement","decodeHtmlEntities","encodedText","hasInterpolation","prefix","suffix","replaceElements","ast","interpolation","child","index","isNode","translateWithInterpolation","item","type","textContent","parseHTML","htmlParseStringNotFoundError","translateJSX","translation","e","Trans","key","i18n"],"mappings":";;;AASA,MAAMA,IAAeC,EAAAA;AAErB,SAASC,EAAmBC,GAAgBC,GAAyD;AACnG,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAC9BH,EAAQI,YAAYL,EAASM,IAAI,MAAM,IAC3C;AAEAN,EAAAA,EAASO,GAAG,UAAU,MAAMJ,EAAa,MAAMH,EAASM,CAAC,CAAC,GAC1DN,EAASQ,KAAKP,GAAS,CAACQ,GAAGH,MAAMH,EAAa,MAAMG,CAAC,CAAC;AAEtD,iBAAeI,EAAeC,GAAa;AACzC,UAAML,IAAI,MAAMN,EAASU,eAAeC,CAAG;AAC3CR,IAAAA,EAAa,MAAMG,CAAC;AAAA,EACtB;AAEA,WAASM,EACPD,GACAE,GACAR,GACAS,IAAyD,CAAA,GACnD;AACN,WAAOd,EAASe,kBAAkBJ,GAAKE,GAAIR,GAAWS,EAAcE,MAAMF,EAAcG,SAAS;AAAA,EACnG;AAEA,SAAO,EACJ,IAAIC,MAAgChB,EAAAA,EAAYiB,MAAM,MAAMD,CAAI,IACjE;AAAA,IACEN,cAAAA;AAAAA,IACAQ,YAAYA,MAAMpB;AAAAA,IAClBU,gBAAAA;AAAAA,EAAAA,CACD;AAEL;AAEO,MAAMW,IAAk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/decodeHtmlEntities.ts","../src/utils/has-interpolation.ts","../src/utils/replace-elements.ts","../src/utils/translate-with-interpolation.ts","../src/utils/translate-jsx.ts","../src/Trans.tsx"],"sourcesContent":["import i18next, { type InitOptions, type TFunction, type i18n } from '@nerimity/i18lite';\r\nimport { createContext, createSignal, useContext, type ParentComponent } from 'solid-js';\r\n\r\nexport type TransProviderActions = {\r\n addResources(lng: string, ns: string, resources: any): i18n;\r\n changeLanguage(lng: string): Promise<void>;\r\n getI18next(): i18n;\r\n};\r\n\r\nconst TransContext = createContext<[TFunction, TransProviderActions]>();\r\n\r\nfunction createTransContext(instance: i18n, options: InitOptions): [TFunction, TransProviderActions] {\r\n const [language, setLanguage] = createSignal(null);\r\n\r\n instance.init(options, () => setLanguage(() => instance.language));\r\n\r\n async function changeLanguage(lng: string) {\r\n await instance.changeLanguage(lng);\r\n setLanguage(() => lng);\r\n }\r\n\r\n function addResources(\r\n lng: string,\r\n ns: string,\r\n resources: any,\r\n bundleOptions: { deep?: boolean; overwrite?: boolean } = {},\r\n ): i18n {\r\n return instance.addResourceBundle(lng, ns, resources, bundleOptions.deep, bundleOptions.overwrite);\r\n }\r\n\r\n const t = (...args: Parameters<TFunction>) => {\r\n // Access the signal to track it - this ensures components re-render when language changes\r\n language();\r\n return instance.t(...args);\r\n };\r\n\r\n return [\r\n t,\r\n {\r\n addResources,\r\n getI18next: () => instance,\r\n changeLanguage,\r\n },\r\n ];\r\n}\r\n\r\nexport const useTransContext = () => useContext(TransContext);\r\n\r\nexport const TransProvider: ParentComponent<{ instance?: i18n; lng?: string; options?: InitOptions }> = (props) => {\r\n return (\r\n <TransContext.Provider\r\n value={createTransContext(props.instance || i18next, { lng: props.lng, ...props.options })}\r\n children={props.children}\r\n />\r\n );\r\n};\r\n","const tempElement = document.createElement('textarea');\r\nexport function decodeHtmlEntities(encodedText: string) {\r\n tempElement.innerHTML = encodedText || '';\r\n\r\n return tempElement.value;\r\n}\r\n","import type { InterpolationOptions } from '@nerimity/i18lite';\r\n\r\nexport const hasInterpolation = (value: string, { prefix, suffix }: InterpolationOptions) =>\r\n value.includes(prefix) && value.includes(suffix);\r\n","import type { InitOptions } from '@nerimity/i18lite';\r\nimport type { IDom } from 'html-parse-string';\r\nimport { decodeHtmlEntities } from './decodeHtmlEntities';\r\nimport { hasInterpolation } from './has-interpolation';\r\n\r\nexport const replaceElements =\r\n (ast: IDom, { interpolation }: InitOptions) =>\r\n (child: Node, index: number) => {\r\n if (typeof child === 'string') {\r\n if (hasInterpolation(child, interpolation)) return decodeHtmlEntities(ast.children[index].children?.[0].content);\r\n\r\n return decodeHtmlEntities(ast.children[index].content);\r\n }\r\n\r\n child.textContent = decodeHtmlEntities(ast.children[index].children?.[0].content);\r\n\r\n return child;\r\n };\r\n","import type { InitOptions, TFunction } from '@nerimity/i18lite';\r\nimport type { TransProps } from '../Trans';\r\nimport { decodeHtmlEntities } from './decodeHtmlEntities';\r\nimport { hasInterpolation } from './has-interpolation';\r\n\r\nconst isNode = !globalThis.window;\r\n\r\nexport const translateWithInterpolation = (t: TFunction, options: InitOptions, props: TransProps) => (item) => {\r\n const type = typeof item;\r\n\r\n if (type === 'string' && hasInterpolation(item, options.interpolation)) {\r\n return decodeHtmlEntities(t(item, props.options));\r\n }\r\n\r\n if (type === 'object') {\r\n const textContent = item.textContent ?? item.t;\r\n if (textContent && hasInterpolation(textContent, options.interpolation)) {\r\n item[isNode ? 't' : 'textContent'] = t(textContent, props.options);\r\n }\r\n }\r\n\r\n return item;\r\n};\r\n","import type { TFunction, i18n } from '@nerimity/i18lite';\r\nimport type { parse, stringify } from 'html-parse-string';\r\nimport type { ParentProps } from 'solid-js';\r\nimport type { TransProps } from '../Trans';\r\nimport { replaceElements } from './replace-elements';\r\nimport { translateWithInterpolation } from './translate-with-interpolation';\r\n\r\nexport let parseHTML: typeof parse;\r\nexport let stringifyHtml: typeof stringify;\r\n(async () => {\r\n try {\r\n // @ts-ignore\r\n const module = await import('html-parse-string');\r\n parseHTML = module.parse;\r\n stringifyHtml = module.stringify;\r\n } catch {}\r\n})();\r\n\r\nexport const htmlParseStringNotFoundError = () => {\r\n console.error(\r\n 'In order to use JSX nesting, install %chtml-parse-string',\r\n 'font-weight: 700',\r\n 'https://github.com/ryansolid/html-parse-string.'\r\n );\r\n};\r\nexport const translateJSX = (\r\n { i18n: { options }, t, props }: { t: TFunction; props: ParentProps<TransProps>; i18n: i18n },\r\n children: Node[]\r\n) => {\r\n const translation = t(props.key, props.options);\r\n\r\n if (!props.children) return translation;\r\n\r\n if (translation === props.key) return children.map(translateWithInterpolation(t, options, props));\r\n\r\n if (!parseHTML) {\r\n htmlParseStringNotFoundError();\r\n return;\r\n }\r\n try {\r\n const [ast] = parseHTML(`<0>${translation}</0>`);\r\n return children.map(replaceElements(ast, options));\r\n } catch (e) {\r\n console.error(e);\r\n }\r\n};\r\n","import type { TFunction, TOptions } from '@nerimity/i18lite';\r\nimport { stringify } from 'html-parse-string';\r\nimport { children, type JSXElement, type ParentComponent, type ParentProps } from 'solid-js';\r\nimport { Dynamic } from 'solid-js/web';\r\nimport { useTransContext } from './TransProvider';\r\nimport { htmlParseStringNotFoundError, parseHTML, translateJSX } from './utils/translate-jsx';\r\n\r\nexport type TransProps = {\r\n key: string;\r\n options?: TOptions;\r\n components?: Record<string, JSXElement | ((props: any) => JSXElement)>;\r\n};\r\n\r\nexport const Trans: ParentComponent<TransProps> = (props) => {\r\n const [t, { getI18next }] = useTransContext();\r\n\r\n return (\r\n <>\r\n {props.components\r\n ? renderInterpolatedTranslation({ t, props })\r\n : typeof props.children === 'string'\r\n ? t(props.key, props.children, props.options)\r\n : translateJSX({ i18n: getI18next(), t, props }, children(() => props.children)() as Node[])}\r\n </>\r\n );\r\n};\r\n\r\nconst renderInterpolatedTranslation = ({ t, props }: { t: TFunction; props: ParentProps<TransProps> }) => {\r\n const translatedString = t(props.key, props.options);\r\n\r\n if (!parseHTML) {\r\n htmlParseStringNotFoundError();\r\n return;\r\n }\r\n\r\n const [ast] = parseHTML(`<0>${translatedString}</0>`);\r\n\r\n return ast.children.map((node) => {\r\n if (node.type === 'text') {\r\n return node.content;\r\n }\r\n\r\n const componentKey = node.name;\r\n const mappedComponent = props.components?.[componentKey];\r\n\r\n if (!mappedComponent) {\r\n return node.content;\r\n }\r\n\r\n if (typeof mappedComponent === 'function') {\r\n return <Dynamic component={mappedComponent} children={stringify(node.children)} />;\r\n }\r\n\r\n return mappedComponent;\r\n });\r\n};\r\n"],"names":["TransContext","createContext","createTransContext","instance","options","language","setLanguage","createSignal","init","changeLanguage","lng","addResources","ns","resources","bundleOptions","addResourceBundle","deep","overwrite","t","args","getI18next","useTransContext","useContext","TransProvider","props","_$createComponent","Provider","value","i18next","children","tempElement","decodeHtmlEntities","encodedText","hasInterpolation","prefix","suffix","replaceElements","ast","interpolation","child","index","isNode","translateWithInterpolation","item","type","textContent","parseHTML","stringifyHtml","module","htmlParseStringNotFoundError","translateJSX","translation","e","Trans","components","renderInterpolatedTranslation","key","i18n","translatedString","map","node","content","componentKey","name","mappedComponent","Dynamic","component","stringify"],"mappings":";;;;AASA,MAAMA,IAAeC,EAAAA;AAErB,SAASC,EAAmBC,GAAgBC,GAAyD;AACnG,QAAM,CAACC,GAAUC,CAAW,IAAIC,EAAa,IAAI;AAEjDJ,EAAAA,EAASK,KAAKJ,GAAS,MAAME,EAAY,MAAMH,EAASE,QAAQ,CAAC;AAEjE,iBAAeI,EAAeC,GAAa;AACzC,UAAMP,EAASM,eAAeC,CAAG,GACjCJ,EAAY,MAAMI,CAAG;AAAA,EACvB;AAEA,WAASC,EACPD,GACAE,GACAC,GACAC,IAAyD,CAAA,GACnD;AACN,WAAOX,EAASY,kBAAkBL,GAAKE,GAAIC,GAAWC,EAAcE,MAAMF,EAAcG,SAAS;AAAA,EACnG;AAQA,SAAO,CANGC,IAAIC,OAEZd,EAAAA,GACOF,EAASe,EAAE,GAAGC,CAAI,IAKzB;AAAA,IACER,cAAAA;AAAAA,IACAS,YAAYA,MAAMjB;AA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AAAA,IAAEO,MAAMrC,EAAAA;AAAAA,IAAcF,GAAAA;AAAAA,IAAGM,OAAAA;AAAAA,EAAAA,GAASK,EAAS,MAAML,EAAMK,QAAQ,GAAa;AAGnG,GAEM0B,IAAgCA,CAAC;AAAA,EAAErC;AAAAA,EAAGM,OAAAA;AAAwD,MAAM;AACxG,QAAMkC,IAAmBxC,EAAEM,EAAMgC,KAAKhC,EAAMpB,OAAO;AAEnD,MAAI,CAAC0C,GAAW;AACdG,IAAAA,EAAAA;AACA;AAAA,EACF;AAEA,QAAM,CAACZ,CAAG,IAAIS,EAAU,MAAMY,CAAgB,MAAM;AAEpD,SAAOrB,EAAIR,SAAS8B,IAAKC,CAAAA,MAAS;AAChC,QAAIA,EAAKhB,SAAS;AAChB,aAAOgB,EAAKC;AAGd,UAAMC,IAAeF,EAAKG,MACpBC,IAAkBxC,EAAM8B,aAAaQ,CAAY;AAEvD,WAAKE,IAID,OAAOA,KAAoB,aAC7BvC,EAAQwC,GAAO;AAAA,MAACC,WAAWF;AAAAA,MAAe,IAAEnC,WAAQ;AAAA,eAAEsC,EAAUP,EAAK/B,QAAQ;AAAA,MAAC;AAAA,IAAA,CAAA,IAGzEmC,IAPEJ,EAAKC;AAAAA,EAQhB,CAAC;AACH;"}
|
package/dist/types/Trans.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { TOptions } from '@nerimity/i18lite';
|
|
2
|
-
import { type ParentComponent } from 'solid-js';
|
|
2
|
+
import { type JSXElement, type ParentComponent } from 'solid-js';
|
|
3
3
|
export type TransProps = {
|
|
4
4
|
key: string;
|
|
5
5
|
options?: TOptions;
|
|
6
|
+
components?: Record<string, JSXElement | ((props: any) => JSXElement)>;
|
|
6
7
|
};
|
|
7
8
|
export declare const Trans: ParentComponent<TransProps>;
|
|
9
|
+
//# sourceMappingURL=Trans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Trans.d.ts","sourceRoot":"","sources":["../../src/Trans.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAY,KAAK,UAAU,EAAE,KAAK,eAAe,EAAoB,MAAM,UAAU,CAAC;AAK7F,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC;CACxE,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,eAAe,CAAC,UAAU,CAY7C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransProvider.d.ts","sourceRoot":"","sources":["../../src/TransProvider.tsx"],"names":[],"mappings":"AAAA,OAAgB,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,KAAK,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAA2C,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AAEzF,MAAM,MAAM,oBAAoB,GAAG;IACjC,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,GAAG,IAAI,CAAC;IAC5D,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,UAAU,IAAI,IAAI,CAAC;CACpB,CAAC;AAuCF,eAAO,MAAM,eAAe,yCAAiC,CAAC;AAE9D,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC;IAAE,QAAQ,CAAC,EAAE,IAAI,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,WAAW,CAAA;CAAE,CAOnG,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeHtmlEntities.d.ts","sourceRoot":"","sources":["../../../src/utils/decodeHtmlEntities.ts"],"names":[],"mappings":"AACA,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,UAIrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-interpolation.d.ts","sourceRoot":"","sources":["../../../src/utils/has-interpolation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,EAAE,oBAAoB,oBAAoB,YACtC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { InitOptions } from '@nerimity/i18lite';
|
|
2
2
|
import type { IDom } from 'html-parse-string';
|
|
3
3
|
export declare const replaceElements: (ast: IDom, { interpolation }: InitOptions) => (child: Node, index: number) => string | Node;
|
|
4
|
+
//# sourceMappingURL=replace-elements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace-elements.d.ts","sourceRoot":"","sources":["../../../src/utils/replace-elements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAI9C,eAAO,MAAM,eAAe,GACzB,KAAK,IAAI,EAAE,mBAAmB,WAAW,MACzC,OAAO,IAAI,EAAE,OAAO,MAAM,kBAU1B,CAAC"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { TFunction, i18n } from '@nerimity/i18lite';
|
|
2
|
-
import type { parse } from 'html-parse-string';
|
|
2
|
+
import type { parse, stringify } from 'html-parse-string';
|
|
3
3
|
import type { ParentProps } from 'solid-js';
|
|
4
4
|
import type { TransProps } from '../Trans';
|
|
5
5
|
export declare let parseHTML: typeof parse;
|
|
6
|
+
export declare let stringifyHtml: typeof stringify;
|
|
7
|
+
export declare const htmlParseStringNotFoundError: () => void;
|
|
6
8
|
export declare const translateJSX: ({ i18n: { options }, t, props }: {
|
|
7
9
|
t: TFunction;
|
|
8
10
|
props: ParentProps<TransProps>;
|
|
9
11
|
i18n: i18n;
|
|
10
12
|
}, children: Node[]) => string | any[];
|
|
13
|
+
//# sourceMappingURL=translate-jsx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translate-jsx.d.ts","sourceRoot":"","sources":["../../../src/utils/translate-jsx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAI3C,eAAO,IAAI,SAAS,EAAE,OAAO,KAAK,CAAC;AACnC,eAAO,IAAI,aAAa,EAAE,OAAO,SAAS,CAAC;AAU3C,eAAO,MAAM,4BAA4B,YAMxC,CAAC;AACF,eAAO,MAAM,YAAY,GACvB,iCAAiC;IAAE,CAAC,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,EAC7F,UAAU,IAAI,EAAE,mBAkBjB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { InitOptions, TFunction } from '@nerimity/i18lite';
|
|
2
2
|
import type { TransProps } from '../Trans';
|
|
3
3
|
export declare const translateWithInterpolation: (t: TFunction, options: InitOptions, props: TransProps) => (item: any) => any;
|
|
4
|
+
//# sourceMappingURL=translate-with-interpolation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translate-with-interpolation.d.ts","sourceRoot":"","sources":["../../../src/utils/translate-with-interpolation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAM3C,eAAO,MAAM,0BAA0B,GAAI,GAAG,SAAS,EAAE,SAAS,WAAW,EAAE,OAAO,UAAU,MAAM,SAAI,QAezG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "1.
|
|
3
|
-
"author": "SupertigerDev",
|
|
4
|
-
"description": "i18next for SolidJS",
|
|
5
|
-
"devDependencies": {
|
|
6
|
-
"@babel/plugin-transform-runtime": "^7.28.3",
|
|
7
|
-
"@babel/preset-typescript": "^7.27.1",
|
|
8
|
-
"@solidjs/testing-library": "^0.8.10",
|
|
9
|
-
"@types/jest": "^30.0.0",
|
|
10
|
-
"babel-preset-solid": "^1.9.9",
|
|
11
|
-
"html-parse-string": "^0.0.9",
|
|
12
|
-
"@nerimity/i18lite": "^1.0.9",
|
|
13
|
-
"i18next-http-backend": "^3.0.2",
|
|
14
|
-
"jest": "^30.2.0",
|
|
15
|
-
"jest-environment-jsdom": "^30.2.0",
|
|
16
|
-
"solid-jest": "^0.2.0",
|
|
17
|
-
"solid-js": "^1.9.9",
|
|
18
|
-
"typescript": "^5.9.3",
|
|
19
|
-
"vite": "^7.1.9",
|
|
20
|
-
"vite-plugin-solid": "^2.11.9"
|
|
21
|
-
},
|
|
22
|
-
"exports": {
|
|
23
|
-
".": {
|
|
24
|
-
"types": "./dist/types/index.d.ts",
|
|
25
|
-
"browser": {
|
|
26
|
-
"default": "./dist/browser.mjs"
|
|
27
|
-
},
|
|
28
|
-
"import": "./dist/ssr.mjs",
|
|
29
|
-
"require": "./dist/ssr.js"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"files": [
|
|
33
|
-
"dist",
|
|
34
|
-
"CHANGELOG.md"
|
|
35
|
-
],
|
|
36
|
-
"keywords": [
|
|
37
|
-
"i18n",
|
|
38
|
-
"i18next",
|
|
39
|
-
"internationalization",
|
|
40
|
-
"intl",
|
|
41
|
-
"language",
|
|
42
|
-
"localization",
|
|
43
|
-
"solid",
|
|
44
|
-
"solid-js",
|
|
45
|
-
"solidjs",
|
|
46
|
-
"translate",
|
|
47
|
-
"translations"
|
|
48
|
-
],
|
|
49
|
-
"license": "MIT",
|
|
50
|
-
"main": "./dist/ssr.js",
|
|
51
|
-
"module": "./dist/ssr.mjs",
|
|
52
|
-
"name": "@nerimity/solid-i18lite",
|
|
53
|
-
"peerDependencies": {
|
|
54
|
-
"html-parse-string": "<=1.x",
|
|
55
|
-
"@nerimity/i18lite": "<=1.x",
|
|
56
|
-
"solid-js": ">=1.8.x"
|
|
57
|
-
},
|
|
58
|
-
"peerDependenciesMeta": {
|
|
59
|
-
"html-parse-string": {
|
|
60
|
-
"optional": true
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
"repository": "github:nerimity/solid-i18lite",
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"build:
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"version": "1.8.1",
|
|
3
|
+
"author": "SupertigerDev",
|
|
4
|
+
"description": "i18next for SolidJS",
|
|
5
|
+
"devDependencies": {
|
|
6
|
+
"@babel/plugin-transform-runtime": "^7.28.3",
|
|
7
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
8
|
+
"@solidjs/testing-library": "^0.8.10",
|
|
9
|
+
"@types/jest": "^30.0.0",
|
|
10
|
+
"babel-preset-solid": "^1.9.9",
|
|
11
|
+
"html-parse-string": "^0.0.9",
|
|
12
|
+
"@nerimity/i18lite": "^1.0.9",
|
|
13
|
+
"i18next-http-backend": "^3.0.2",
|
|
14
|
+
"jest": "^30.2.0",
|
|
15
|
+
"jest-environment-jsdom": "^30.2.0",
|
|
16
|
+
"solid-jest": "^0.2.0",
|
|
17
|
+
"solid-js": "^1.9.9",
|
|
18
|
+
"typescript": "^5.9.3",
|
|
19
|
+
"vite": "^7.1.9",
|
|
20
|
+
"vite-plugin-solid": "^2.11.9"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/types/index.d.ts",
|
|
25
|
+
"browser": {
|
|
26
|
+
"default": "./dist/browser.mjs"
|
|
27
|
+
},
|
|
28
|
+
"import": "./dist/ssr.mjs",
|
|
29
|
+
"require": "./dist/ssr.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"CHANGELOG.md"
|
|
35
|
+
],
|
|
36
|
+
"keywords": [
|
|
37
|
+
"i18n",
|
|
38
|
+
"i18next",
|
|
39
|
+
"internationalization",
|
|
40
|
+
"intl",
|
|
41
|
+
"language",
|
|
42
|
+
"localization",
|
|
43
|
+
"solid",
|
|
44
|
+
"solid-js",
|
|
45
|
+
"solidjs",
|
|
46
|
+
"translate",
|
|
47
|
+
"translations"
|
|
48
|
+
],
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"main": "./dist/ssr.js",
|
|
51
|
+
"module": "./dist/ssr.mjs",
|
|
52
|
+
"name": "@nerimity/solid-i18lite",
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"html-parse-string": "<=1.x",
|
|
55
|
+
"@nerimity/i18lite": "<=1.x",
|
|
56
|
+
"solid-js": ">=1.8.x"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"html-parse-string": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"repository": "github:nerimity/solid-i18lite",
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build:browser": "vite build --config vite.browser.config.js",
|
|
66
|
+
"build:docs": "vite build --config vite.docs.config.js",
|
|
67
|
+
"build:ssr": "vite build --config vite.ssr.config.js",
|
|
68
|
+
"build:types": "tsc --project tsconfig.types.json",
|
|
69
|
+
"docs": "vite --config vite.docs.config.js",
|
|
70
|
+
"test": "jest --coverage",
|
|
71
|
+
"test:dev": "jest"
|
|
72
|
+
},
|
|
73
|
+
"sideEffects": false,
|
|
74
|
+
"type": "module",
|
|
75
|
+
"types": "./dist/types/index.d.ts"
|
|
76
|
+
}
|