fix(webui): localize the component gallery
This commit is contained in:
1 parent
282839cc65
commit
ae5cb64e9e
54 files changed
+11120
-719
No files matched your search
@@ -15,6 +15,7 @@ import {
|
||||
|
||||
import { channelFeatures } from "./channel-fixtures";
|
||||
import { StatePicker, type ComponentExample } from "./example";
|
||||
import { useGalleryTranslation } from "./i18n";
|
||||
|
||||
const scan: ChannelConnectPayload = {
|
||||
session_id: "gallery-weixin",
|
||||
@@ -26,6 +27,7 @@ type ConnectState = "starting" | "scan" | "verify" | "verify-error" | "connected
|
||||
| "expired" | "failed" | "cancelled" | "error";
|
||||
|
||||
function WeixinConnectPreview() {
|
||||
const { t } = useGalleryTranslation();
|
||||
const [mode, setMode] = useState<ConnectState>("scan");
|
||||
const [notice, setNotice] = useState("");
|
||||
const connect: ChannelConnectPayload | WeixinVerificationPayload | null = mode === "starting" ? null
|
||||
@@ -35,12 +37,12 @@ function WeixinConnectPreview() {
|
||||
} : { ...scan, status: mode === "connected" ? "succeeded" : mode };
|
||||
|
||||
return <>
|
||||
<StatePicker label="微信连接状态" value={mode}
|
||||
<StatePicker label={t("previews.weixinConnect.state")} value={mode}
|
||||
options={["starting", "scan", "verify", "verify-error", "connected", "expired", "failed", "cancelled", "error"]}
|
||||
onChange={setMode} />
|
||||
<WeixinConnectFlowView connect={connect} busy={mode === "starting"} autoStart minimalPending
|
||||
error={mode === "error" ? "Connection interrupted. Try again." : null}
|
||||
onStart={() => { setMode("scan"); setNotice("已显示新的预览二维码。"); }}
|
||||
error={mode === "error" ? t("previews.weixinConnect.error") : null}
|
||||
onStart={() => { setMode("scan"); setNotice("previews.weixinConnect.refreshed"); }}
|
||||
onCancel={() => setMode("cancelled")}
|
||||
onPoll={async (params) => {
|
||||
if (params?.verify_code === "123456") {
|
||||
@@ -50,7 +52,7 @@ function WeixinConnectPreview() {
|
||||
setMode("verify-error");
|
||||
return { ...scan, challenge: "verify_code", verification_failed: true };
|
||||
}} />
|
||||
<p role="status" className="mt-4 text-xs text-muted-foreground">{notice || "验证码预览输入 123456 可完成连接;其他输入会保留草稿并显示错误。"}</p>
|
||||
<p role="status" className="mt-4 text-xs text-muted-foreground">{t(notice || "previews.weixinConnect.hint")}</p>
|
||||
</>;
|
||||
}
|
||||
|
||||
@@ -58,6 +60,7 @@ type PanelState = "unconfigured" | "running" | "auth-expired" | "saving" | "save
|
||||
|
||||
function WeixinPanelPreview() {
|
||||
const { t, i18n } = useTranslation();
|
||||
const { t: g } = useGalleryTranslation();
|
||||
const channelTx = channelTranslator(t, "weixin");
|
||||
const [mode, setMode] = useState<PanelState>("running");
|
||||
const [edited, setEdited] = useState(false);
|
||||
@@ -80,14 +83,14 @@ function WeixinPanelPreview() {
|
||||
const runtimeError = mode === "auth-expired" ? channelTx("custom.expired", WEIXIN_AUTH_EXPIRED_MESSAGE) : undefined;
|
||||
|
||||
return <>
|
||||
<StatePicker label="微信面板状态" value={mode}
|
||||
<StatePicker label={g("previews.weixinPanel.state")} value={mode}
|
||||
options={["unconfigured", "running", "auth-expired", "saving", "saved", "save-error"]}
|
||||
onChange={(next) => { setMode(next); setEdited(false); }} />
|
||||
<WeixinPanelView feature={feature} actionKey={null} showBrandLogos={false}
|
||||
primaryFields={primaryFields} advancedFields={advancedFields} fieldValues={values}
|
||||
configuredFields={new Set()} secretVisibilityKey="gallery-weixin" runtimeError={runtimeError}
|
||||
saving={mode === "saving" && !edited} saveState={mode === "saved" || edited ? "saved" : "idle"}
|
||||
saveError={mode === "save-error" && !edited ? "Unable to save settings. Your draft is preserved." : null}
|
||||
saveError={mode === "save-error" && !edited ? g("previews.linearPanel.saveError") : null}
|
||||
connectFlow={mode === "unconfigured" || mode === "auth-expired" ? <WeixinConnectFlowView
|
||||
connect={connect} busy={false} error={null} autoStart minimalPending
|
||||
suppressSucceeded={mode === "auth-expired"}
|
||||
@@ -99,12 +102,12 @@ function WeixinPanelPreview() {
|
||||
}
|
||||
|
||||
export const weixinChannelExamples: ComponentExample[] = [
|
||||
{ title: "WeixinPanelView · 微信设置", files: ["nanobot/channels/weixin/webui/WeixinPanelView.tsx"],
|
||||
Preview: WeixinPanelPreview, description: "查看微信设置、高级参数、保存反馈和登录过期恢复。",
|
||||
options: "字段来自频道的真实设置契约。视图管理展开和密钥可见状态;运行时入口负责自动保存、草稿合并和登录恢复。",
|
||||
{ title: "previews.weixinPanel.title", files: ["nanobot/channels/weixin/webui/WeixinPanelView.tsx"],
|
||||
Preview: WeixinPanelPreview, description: "previews.weixinPanel.description",
|
||||
options: "previews.weixinPanel.options",
|
||||
code: '<WeixinPanelView feature={feature} primaryFields={primary} advancedFields={advanced} fieldValues={values} saving={saving} saveState={saveState} saveError={error} connectFlow={connectFlow} onFieldChange={change} />' },
|
||||
{ title: "WeixinConnectFlowView · 微信扫码与验证", files: ["nanobot/channels/weixin/webui/WeixinConnectFlowView.tsx"],
|
||||
Preview: WeixinConnectPreview, description: "比较扫码、验证码、成功、过期、取消和连接错误。",
|
||||
options: "视图接收连接快照与操作回调,并保留验证码草稿。二维码生成在浏览器中进行;授权启动、轮询暂停、刷新和取消由真实入口负责。",
|
||||
{ title: "previews.weixinConnect.title", files: ["nanobot/channels/weixin/webui/WeixinConnectFlowView.tsx"],
|
||||
Preview: WeixinConnectPreview, description: "previews.weixinConnect.description",
|
||||
options: "previews.weixinConnect.options",
|
||||
code: '<WeixinConnectFlowView connect={connect} busy={busy} error={error} autoStart minimalPending onStart={start} onCancel={cancel} onPoll={verify} />' },
|
||||
];
|
||||
Reference in new issue
Block a user