@xingwangzhe/stalux 1.27.0 β 1.27.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/README.md
CHANGED
|
@@ -88,7 +88,7 @@ bun run dev
|
|
|
88
88
|
- π€ **LLM discovery files** (llms.txt / llms-full.txt)
|
|
89
89
|
- π€ **WebMCP tools** for AI agents (W3C draft, pure front-end)
|
|
90
90
|
- β‘ **View transitions** for smooth navigation
|
|
91
|
-
- π **i18n** (English / Chinese)
|
|
91
|
+
- π **i18n** (English / Simplified Chinese; missing locale keys fall back to English)
|
|
92
92
|
- π·οΈ **Tags, categories, archives** pages
|
|
93
93
|
- π¨ **Component override system** (Starlight-style)
|
|
94
94
|
- π οΈ **Easy YAML configuration** β no coding required
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@ const { t } = createTranslator((siteConfig.lang as string) || "zh-CN");
|
|
|
18
18
|
---
|
|
19
19
|
|
|
20
20
|
{(props.prev || props.next) && (
|
|
21
|
-
<nav class={style.postNavigation} aria-label="
|
|
21
|
+
<nav class={style.postNavigation} aria-label={t("post.navigation")}>
|
|
22
22
|
<div class={style.postNavigationInner}>
|
|
23
23
|
{props.prev ? (
|
|
24
24
|
<a
|
package/src/i18n/en.json
CHANGED
package/src/i18n/zh-CN.json
CHANGED
package/src/utils/i18n.ts
CHANGED
|
@@ -12,7 +12,9 @@ export interface Translator {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function createTranslator(lang: string): Translator {
|
|
15
|
-
const
|
|
15
|
+
const normalizedLang = lang.toLowerCase();
|
|
16
|
+
const language = normalizedLang.startsWith("en") ? "en" : "zh-CN";
|
|
17
|
+
const dict = dicts[language] ?? dicts["zh-CN"] ?? en;
|
|
16
18
|
|
|
17
19
|
function t(key: string, params?: Record<string, string | number>): string {
|
|
18
20
|
const keys = key.split(".");
|
|
@@ -21,12 +23,12 @@ export function createTranslator(lang: string): Translator {
|
|
|
21
23
|
if (text && typeof text === "object") {
|
|
22
24
|
text = (text as Record<string, unknown>)[k];
|
|
23
25
|
} else {
|
|
24
|
-
return key;
|
|
26
|
+
return lookup(en, key) ?? key;
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
|
-
if (typeof text !== "string")
|
|
29
|
+
if (typeof text !== "string" || !text.trim()) text = lookup(en, key) ?? key;
|
|
28
30
|
|
|
29
|
-
let result = text;
|
|
31
|
+
let result = text as string;
|
|
30
32
|
if (params) {
|
|
31
33
|
for (const [k, v] of Object.entries(params)) {
|
|
32
34
|
result = result.replace(`{${k}}`, String(v));
|
|
@@ -35,7 +37,16 @@ export function createTranslator(lang: string): Translator {
|
|
|
35
37
|
return result;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
return { t, lang };
|
|
40
|
+
return { t, lang: language };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function lookup(dictionary: Record<string, unknown>, key: string): string | undefined {
|
|
44
|
+
let value: unknown = dictionary;
|
|
45
|
+
for (const part of key.split(".")) {
|
|
46
|
+
if (!value || typeof value !== "object") return;
|
|
47
|
+
value = (value as Record<string, unknown>)[part];
|
|
48
|
+
}
|
|
49
|
+
return typeof value === "string" && value.trim() ? value : undefined;
|
|
39
50
|
}
|
|
40
51
|
|
|
41
52
|
/**
|