@yozora-tech/qfluent 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/assets/BDqr3vjM-bundle-graph.json +1 -0
- package/lib/assets/DLXuL6n7-bundle-graph.json +1 -0
- package/lib/index.qwik.cjs +11 -12
- package/lib/index.qwik.mjs +1 -10
- package/lib/q-manifest.json +25 -25
- package/lib/qfluent/context.qwik.cjs +170 -181
- package/lib/qfluent/context.qwik.mjs +170 -166
- package/lib/qfluent/tools.qwik.cjs +16 -11
- package/lib/qfluent/tools.qwik.mjs +17 -12
- package/lib/qfluent/translate.qwik.cjs +77 -78
- package/lib/qfluent/translate.qwik.mjs +78 -81
- package/package.json +12 -6
- package/lib/assets/DVjQdr_6-bundle-graph.json +0 -1
- package/lib/assets/l4W0yvKV-bundle-graph.json +0 -1
|
@@ -1,88 +1,85 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { FluentBundlesId, useFluentLocales } from "./context.qwik.mjs";
|
|
2
|
+
import { _captures, componentQrl, inlinedQrl, useComputedQrl, useContext, useOnDocument, useTaskQrl } from "@qwik.dev/core";
|
|
3
3
|
function wrapArgs(args) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
case "object":
|
|
17
|
-
if (args === null) {
|
|
18
|
-
return {
|
|
19
|
-
x: "null"
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return args;
|
|
23
|
-
default:
|
|
24
|
-
return {
|
|
25
|
-
x: String(args)
|
|
26
|
-
};
|
|
27
|
-
}
|
|
4
|
+
switch (typeof args) {
|
|
5
|
+
case "string":
|
|
6
|
+
case "number":
|
|
7
|
+
case "bigint":
|
|
8
|
+
case "boolean": return { x: args };
|
|
9
|
+
case "undefined": return { x: "undefined" };
|
|
10
|
+
case "object":
|
|
11
|
+
if (args === null) return { x: "null" };
|
|
12
|
+
return args;
|
|
13
|
+
default: return { x: String(args) };
|
|
14
|
+
}
|
|
28
15
|
}
|
|
29
16
|
function dummyT(s, args) {
|
|
30
|
-
|
|
17
|
+
return s + (args ? " + " + args : "");
|
|
31
18
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Return a reactive signal to a translated string.
|
|
21
|
+
*
|
|
22
|
+
* Useful for non-DOM use cases (like `document.title`, see `useLocalizedTitle`).
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* const t = useT("my-title");
|
|
26
|
+
* useTask$(({ track }) => {
|
|
27
|
+
* track(t);
|
|
28
|
+
* document.title = t.value;
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/ function useT(s, args) {
|
|
32
|
+
const locales = useFluentLocales();
|
|
33
|
+
const bundles = useContext(FluentBundlesId);
|
|
34
|
+
return useComputedQrl(/*#__PURE__*/ inlinedQrl(() => {
|
|
35
|
+
const args = _captures[0], bundles = _captures[1], locales = _captures[2], s = _captures[3];
|
|
36
|
+
const value = args?.value;
|
|
37
|
+
const placeholder = dummyT(s, value);
|
|
38
|
+
const wargs = wrapArgs(value);
|
|
39
|
+
if (!bundles.value) return placeholder;
|
|
40
|
+
for (const k of locales.value) {
|
|
41
|
+
const b = bundles.value[k];
|
|
42
|
+
if (!b) continue;
|
|
43
|
+
const m = b.getMessage(s);
|
|
44
|
+
if (!m || !m.value) continue;
|
|
45
|
+
return b.formatPattern(m.value, wargs);
|
|
46
|
+
}
|
|
47
|
+
return placeholder;
|
|
48
|
+
}, "useT_message_useComputed_S0G7htNeJXI", [
|
|
49
|
+
args,
|
|
50
|
+
bundles,
|
|
51
|
+
locales,
|
|
52
|
+
s
|
|
53
|
+
]));
|
|
62
54
|
}
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Translate a string in TSX idiom.
|
|
57
|
+
*
|
|
58
|
+
* Pass a signal for `args`.
|
|
59
|
+
*
|
|
60
|
+
* ```tsx
|
|
61
|
+
* const x = useSignal(1);
|
|
62
|
+
* return <T s="x-apples" args={x} />;
|
|
63
|
+
* ```
|
|
64
|
+
*/ var T = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((_rawProps) => {
|
|
65
|
+
return useT(_rawProps.s, _rawProps.args).value;
|
|
65
66
|
}, "T_component_g8a5BXhl0hY"));
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Make the document title (`<title>` element in `<head>`) translated, and follow locale changes.
|
|
69
|
+
*
|
|
70
|
+
* Note: Only effective after resumption on clients. Title generated during SSG is untouched.
|
|
71
|
+
*/ function useLocalizedTitle(s, args) {
|
|
72
|
+
const t = useT(s, args);
|
|
73
|
+
useOnDocument("qidle", /*#__PURE__*/ inlinedQrl(() => {
|
|
74
|
+
const t = _captures[0];
|
|
75
|
+
if (typeof document === "undefined") return;
|
|
76
|
+
document.title = t.value;
|
|
77
|
+
}, "useLocalizedTitle_useOnDocument_VXsb0xE3U2c", [t]));
|
|
78
|
+
useTaskQrl(/*#__PURE__*/ inlinedQrl(({ track }) => {
|
|
79
|
+
const t = _captures[0];
|
|
80
|
+
track(t);
|
|
81
|
+
if (typeof document === "undefined") return;
|
|
82
|
+
document.title = t.value;
|
|
83
|
+
}, "useLocalizedTitle_useTask_MxJmwSF2dkE", [t]));
|
|
83
84
|
}
|
|
84
|
-
export {
|
|
85
|
-
T,
|
|
86
|
-
useLocalizedTitle,
|
|
87
|
-
useT
|
|
88
|
-
};
|
|
85
|
+
export { T, useLocalizedTitle, useT };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora-tech/qfluent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "ProjectFluent.org translations support for Qwik framework v2.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./lib/index.qwik.mjs",
|
|
@@ -42,18 +42,24 @@
|
|
|
42
42
|
"@fluent/bundle": "^0.19.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@qwik.dev/core": "^2.0.0-
|
|
45
|
+
"@qwik.dev/core": "^2.0.0-rc.0",
|
|
46
|
+
"@qwik.dev/router": "^2.0.0-rc.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"@qwik.dev/router": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
46
52
|
},
|
|
47
53
|
"devDependencies": {
|
|
48
54
|
"@eslint/js": "^10.0.1",
|
|
49
|
-
"@qwik.dev/router": "^2.0.0-
|
|
55
|
+
"@qwik.dev/router": "^2.0.0-rc.0",
|
|
50
56
|
"@types/node": "24.10.0",
|
|
51
57
|
"eslint": "10.0.2",
|
|
52
|
-
"eslint-plugin-qwik": "^2.0.0-
|
|
53
|
-
"globals": "17.0.0",
|
|
58
|
+
"eslint-plugin-qwik": "^2.0.0-rc.0",
|
|
59
|
+
"globals": "^17.0.0",
|
|
54
60
|
"typescript": "5.9.3",
|
|
55
61
|
"typescript-eslint": "8.56.1",
|
|
56
|
-
"vite": "
|
|
62
|
+
"vite": "^8.3.2",
|
|
57
63
|
"vite-tsconfig-paths": "^4.3.2"
|
|
58
64
|
}
|
|
59
65
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
["../index.qwik.cjs",4,5,"../qfluent/context.qwik.cjs","../qfluent/tools.qwik.cjs","../qfluent/translate.qwik.cjs",3]
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
["../index.qwik.mjs",4,5,"../qfluent/context.qwik.mjs","../qfluent/tools.qwik.mjs","../qfluent/translate.qwik.mjs",3]
|