refactor(i18n): 迁移到 rust-i18n 语义键体系(ns.key),废弃中文原文作 key
旧实现的问题(按用户反馈):
- 中文原文作 key:文案措辞与代码耦合,一词多义撞 key("主题" Topic/Theme)
- 巨型 match 文案表:重复键靠编译警告暴露;漏翻静默回退,无任何校验
- tf 参数到处 &n.to_string() 噪音
新体系(gpui-kit 官方方案):
- locales/ui.yml 语言包(rust-i18n v2,en/zh-CN 双语并排),key 为
语义标识符(common.save / conn.connect / status.connected…),
与自然语言彻底解耦;改措辞不动代码
- crate 根 i18n! 编译期内嵌;init_i18n() 经 extend! 并入 gpui-kit
组件内置文案(按钮/空态等随语言切换)
- t/tf 薄门面查 _rust_i18n_translate(运行时 key),模型 label()
改返回语义 key;tf 参数只需 Display
- 四个强制单测:语言包 en/zh-CN 完整、占位符 {x} 两侧一致、
全源码 t()/tf() 字面量必须存在词条、模型 label 必须有真实译文
- 语言中性文案("QoS"、"/mqtt" 等)去掉 t() 包裹
- 顺带补翻 30 条漏网文案(资源监控统计行/表单校验/阿里云说明段等)
42 测试全绿;中英双语实机截图验证零裸 key。
This commit is contained in:
@@ -26,11 +26,11 @@ use crate::model::{ConnectionConfig, LastWill, ProtocolVersion, SslConfig, Trans
|
||||
use crate::mqtt::MqttEngine;
|
||||
use crate::ui::widgets::{field, field_ex, make_select, OptionDelegate};
|
||||
|
||||
fn protocol_labels() -> [&'static str; 2] { [i18n::t("MQTT 5.0"), "MQTT 3.1.1"] }
|
||||
fn protocol_labels() -> [&'static str; 2] { ["MQTT 5.0", "MQTT 3.1.1"] }
|
||||
const TRANSPORTS: [&str; 4] = ["TCP", "TLS", "WebSocket", "WSS"]; // 语言无关
|
||||
const QOS: [&str; 3] = ["QoS 0", "QoS 1", "QoS 2"]; // 语言无关
|
||||
/// 分组下拉的首项:选择它表示不归属任何分组。
|
||||
fn no_group_label() -> &'static str { i18n::t("无分组") }
|
||||
fn no_group_label() -> &'static str { i18n::t("form.no_group") }
|
||||
|
||||
pub struct ConnectionForm {
|
||||
engine: Arc<MqttEngine>,
|
||||
@@ -143,28 +143,28 @@ impl ConnectionForm {
|
||||
chrono::Local::now().timestamp()
|
||||
});
|
||||
|
||||
let name = input(&c.name, i18n::t("连接名称"), window, cx);
|
||||
let host = input(&c.host, i18n::t("broker.example.com"), window, cx);
|
||||
let port = input(&c.port.to_string(), i18n::t(i18n::t("端口")), window, cx);
|
||||
let path = input(&c.path, i18n::t("/mqtt"), window, cx);
|
||||
let client_id = input(&c.client_id, i18n::t("Client ID"), window, cx);
|
||||
let username = input(&c.username, i18n::t("用户名(可选)"), window, cx);
|
||||
let name = input(&c.name, i18n::t("form.name_ph"), window, cx);
|
||||
let host = input(&c.host, "broker.example.com", window, cx);
|
||||
let port = input(&c.port.to_string(), i18n::t(i18n::t("form.port")), window, cx);
|
||||
let path = input(&c.path, "/mqtt", window, cx);
|
||||
let client_id = input(&c.client_id, i18n::t("form.client_id"), window, cx);
|
||||
let username = input(&c.username, i18n::t("form.username_ph"), window, cx);
|
||||
let password = cx.new(|cx| {
|
||||
InputState::new(window, cx)
|
||||
.placeholder(i18n::t("密码(可选)"))
|
||||
.placeholder(i18n::t("form.password_ph"))
|
||||
.default_value(&c.password)
|
||||
.masked(true)
|
||||
});
|
||||
let keep_alive = input(&c.keep_alive.to_string(), i18n::t("60"), window, cx);
|
||||
let keep_alive = input(&c.keep_alive.to_string(), "60", window, cx);
|
||||
let conn_timeout = input(
|
||||
&c.connection_timeout_secs.to_string(),
|
||||
i18n::t("秒(默认 10)"),
|
||||
i18n::t("form.timeout_ph"),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
let max_reconnect = input(
|
||||
&c.max_reconnect_times.to_string(),
|
||||
i18n::t("0=无限重连"),
|
||||
i18n::t("form.max_reconnects_ph"),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
@@ -174,39 +174,39 @@ impl ConnectionForm {
|
||||
} else {
|
||||
String::new()
|
||||
},
|
||||
i18n::t("秒(0=会话随连接结束)"),
|
||||
i18n::t("form.session_expiry_ph"),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
let receive_max = optional_input(c.receive_maximum.map(u32::from), i18n::t("服务端接收上限"), window, cx);
|
||||
let max_packet = optional_input(c.maximum_packet_size, i18n::t("最大报文长度"), window, cx);
|
||||
let topic_alias = optional_input(c.topic_alias_maximum.map(u32::from), i18n::t("主题别名上限"), window, cx);
|
||||
let receive_max = optional_input(c.receive_maximum.map(u32::from), i18n::t("form.receive_max_ph"), window, cx);
|
||||
let max_packet = optional_input(c.maximum_packet_size, i18n::t("form.max_packet"), window, cx);
|
||||
let topic_alias = optional_input(c.topic_alias_maximum.map(u32::from), i18n::t("form.topic_alias_max"), window, cx);
|
||||
|
||||
let ssl_ca = input(&c.ssl.ca_file, i18n::t("CA 证书 PEM 路径(可选)"), window, cx);
|
||||
let ssl_client_cert = input(&c.ssl.client_cert_file, i18n::t("客户端证书 PEM 路径(可选)"), window, cx);
|
||||
let ssl_client_key = input(&c.ssl.client_key_file, i18n::t("客户端私钥 PEM 路径(可选)"), window, cx);
|
||||
let ssl_ca = input(&c.ssl.ca_file, i18n::t("ssl.ca_ph"), window, cx);
|
||||
let ssl_client_cert = input(&c.ssl.client_cert_file, i18n::t("ssl.cert_ph"), window, cx);
|
||||
let ssl_client_key = input(&c.ssl.client_key_file, i18n::t("ssl.key_ph"), window, cx);
|
||||
|
||||
let group_new = input("", i18n::t("填写后优先于左侧所选分组"), window, cx);
|
||||
let group_new = input("", i18n::t("form.new_group_hint"), window, cx);
|
||||
|
||||
let (will_topic, will_payload, will_enabled, will_retain, will_qos_idx, will_content_type, will_response_topic) =
|
||||
match &c.last_will {
|
||||
Some(w) => (
|
||||
input(&w.topic, i18n::t("遗嘱主题"), window, cx),
|
||||
input(&w.payload, i18n::t("遗嘱消息"), window, cx),
|
||||
input(&w.topic, i18n::t("form.will_topic"), window, cx),
|
||||
input(&w.payload, i18n::t("form.will_payload_ph"), window, cx),
|
||||
true,
|
||||
w.retain,
|
||||
w.qos as usize,
|
||||
input(w.content_type.as_deref().unwrap_or(""), i18n::t("内容类型(可选)"), window, cx),
|
||||
input(w.response_topic.as_deref().unwrap_or(""), i18n::t("响应主题(可选)"), window, cx),
|
||||
input(w.content_type.as_deref().unwrap_or(""), i18n::t("form.content_type_ph"), window, cx),
|
||||
input(w.response_topic.as_deref().unwrap_or(""), i18n::t("form.response_topic_ph"), window, cx),
|
||||
),
|
||||
None => (
|
||||
input("", i18n::t("遗嘱主题"), window, cx),
|
||||
input("", i18n::t("遗嘱消息"), window, cx),
|
||||
input("", i18n::t("form.will_topic"), window, cx),
|
||||
input("", i18n::t("form.will_payload_ph"), window, cx),
|
||||
false,
|
||||
false,
|
||||
0,
|
||||
input("", i18n::t("内容类型(可选)"), window, cx),
|
||||
input("", i18n::t("响应主题(可选)"), window, cx),
|
||||
input("", i18n::t("form.content_type_ph"), window, cx),
|
||||
input("", i18n::t("form.response_topic_ph"), window, cx),
|
||||
),
|
||||
};
|
||||
|
||||
@@ -402,15 +402,15 @@ impl ConnectionForm {
|
||||
fn parse_u16(s: &str, label: &'static str) -> Result<u16, String> {
|
||||
s.trim()
|
||||
.parse::<u16>()
|
||||
.map_err(|_| format!("{} {}", i18n::t(label), i18n::t("需要是 0~65535 的整数")))
|
||||
.map_err(|_| format!("{} {}", i18n::t(label), i18n::t("form.err_range")))
|
||||
}
|
||||
|
||||
/// 端口:1~65535。0 不是可连接端口,放行只会在 CONNECT 阶段报出难以理解的错误。
|
||||
fn parse_port(s: &str) -> Result<u16, String> {
|
||||
match s.trim().parse::<u16>() {
|
||||
Ok(0) => Err(i18n::t("端口需要是 1~65535 的整数").to_string()),
|
||||
Ok(0) => Err(i18n::t("form.port_invalid").to_string()),
|
||||
Ok(p) => Ok(p),
|
||||
Err(_) => Err(i18n::t("端口需要是 1~65535 的整数").to_string()),
|
||||
Err(_) => Err(i18n::t("form.port_invalid").to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,7 +419,7 @@ impl ConnectionForm {
|
||||
/// 且该值会被持久化,表现为"每次连接都失败"。
|
||||
fn parse_opt_positive_u32(s: &str, label: &'static str) -> Result<Option<u32>, String> {
|
||||
match Self::parse_opt_u32(s, label)? {
|
||||
Some(0) => Err(format!("{} {}", i18n::t(label), i18n::t("必须大于 0(0 是 MQTT 5 协议错误)"))),
|
||||
Some(0) => Err(format!("{} {}", i18n::t(label), i18n::t("form.err_positive"))),
|
||||
other => Ok(other),
|
||||
}
|
||||
}
|
||||
@@ -431,7 +431,7 @@ impl ConnectionForm {
|
||||
}
|
||||
s.parse::<u32>()
|
||||
.map(Some)
|
||||
.map_err(|_| format!("{} {}", i18n::t(label), i18n::t("需要是非负整数")))
|
||||
.map_err(|_| format!("{} {}", i18n::t(label), i18n::t("form.err_uint")))
|
||||
}
|
||||
|
||||
pub fn build(&self, cx: &App) -> Result<ConnectionConfig, String> {
|
||||
@@ -451,28 +451,28 @@ impl ConnectionForm {
|
||||
let mut name = self.val(&self.name, cx);
|
||||
if name.trim().is_empty() {
|
||||
if !for_test {
|
||||
return Err(self.fail("name", i18n::t("连接名称不能为空")));
|
||||
return Err(self.fail("name", i18n::t("form.name_required")));
|
||||
}
|
||||
name = i18n::t("测试连接").into();
|
||||
name = i18n::t("form.test").into();
|
||||
}
|
||||
// 判空已按 trim,保存也存 trim 后的值,避免首尾空白入库
|
||||
let name = name.trim().to_string();
|
||||
let host = self.val(&self.host, cx);
|
||||
if host.trim().is_empty() {
|
||||
return Err(self.fail("host", i18n::t("主机地址不能为空")));
|
||||
return Err(self.fail("host", i18n::t("form.host_required")));
|
||||
}
|
||||
let host = host.trim().to_string();
|
||||
let port = self.fail_as("port", Self::parse_port(&self.val(&self.port, cx)))?;
|
||||
let mut client_id = self.val(&self.client_id, cx);
|
||||
if client_id.trim().is_empty() {
|
||||
if !for_test {
|
||||
return Err(self.fail("client_id", i18n::t("Client ID 不能为空")));
|
||||
return Err(self.fail("client_id", i18n::t("form.client_id_required")));
|
||||
}
|
||||
client_id = format!("mqttx-test-{}", &uuid::Uuid::new_v4().simple().to_string()[..8]);
|
||||
}
|
||||
let client_id = client_id.trim().to_string();
|
||||
let keep_alive =
|
||||
self.fail_as("keep_alive", Self::parse_u16(&self.val(&self.keep_alive, cx), i18n::t("Keep Alive")))?;
|
||||
self.fail_as("keep_alive", Self::parse_u16(&self.val(&self.keep_alive, cx), i18n::t("form.keep_alive_short")))?;
|
||||
// 空串视为 0(会话随连接结束);非空必须是合法非负整数,不再静默吞掉 -1/abc
|
||||
let session_expiry = {
|
||||
let raw = self.val(&self.session_expiry, cx);
|
||||
@@ -483,23 +483,23 @@ impl ConnectionForm {
|
||||
t.parse::<u32>().map_err(|_| {
|
||||
self.fail(
|
||||
"session_expiry",
|
||||
i18n::t("会话过期间隔需要是非负整数(0=会话随连接结束)"),
|
||||
i18n::t("form.session_expiry_invalid"),
|
||||
)
|
||||
})?
|
||||
}
|
||||
};
|
||||
let receive_maximum = self.fail_as("receive_max", (|| -> Result<_, String> {
|
||||
Ok(Self::parse_opt_positive_u32(&self.val(&self.receive_max, cx), i18n::t("接收上限"))?
|
||||
.map(|v| u16::try_from(v).map_err(|_| i18n::t("接收上限不能超过 65535").to_string()))
|
||||
Ok(Self::parse_opt_positive_u32(&self.val(&self.receive_max, cx), i18n::t("form.receive_max_short"))?
|
||||
.map(|v| u16::try_from(v).map_err(|_| i18n::t("form.receive_max_invalid").to_string()))
|
||||
.transpose())
|
||||
})())??;
|
||||
let maximum_packet_size = self.fail_as(
|
||||
"max_packet",
|
||||
Self::parse_opt_positive_u32(&self.val(&self.max_packet, cx), i18n::t("最大报文长度")),
|
||||
Self::parse_opt_positive_u32(&self.val(&self.max_packet, cx), i18n::t("form.max_packet")),
|
||||
)?;
|
||||
let topic_alias_maximum = self.fail_as("topic_alias", (|| -> Result<_, String> {
|
||||
Ok(Self::parse_opt_positive_u32(&self.val(&self.topic_alias, cx), i18n::t("主题别名"))?
|
||||
.map(|v| u16::try_from(v).map_err(|_| i18n::t("主题别名上限不能超过 65535").to_string()))
|
||||
Ok(Self::parse_opt_positive_u32(&self.val(&self.topic_alias, cx), i18n::t("form.topic_alias"))?
|
||||
.map(|v| u16::try_from(v).map_err(|_| i18n::t("form.topic_alias_invalid").to_string()))
|
||||
.transpose())
|
||||
})())??;
|
||||
|
||||
@@ -512,7 +512,7 @@ impl ConnectionForm {
|
||||
.parse::<u16>()
|
||||
.ok()
|
||||
.filter(|v| *v >= 1)
|
||||
.ok_or_else(|| self.fail("conn_timeout", i18n::t("连接超时需要是 1~65535 的整数(秒)")))?
|
||||
.ok_or_else(|| self.fail("conn_timeout", i18n::t("form.conn_timeout_invalid")))?
|
||||
};
|
||||
let max_reconnect_raw = self.val(&self.max_reconnect, cx);
|
||||
let max_reconnect_times = if max_reconnect_raw.trim().is_empty() {
|
||||
@@ -521,7 +521,7 @@ impl ConnectionForm {
|
||||
max_reconnect_raw
|
||||
.trim()
|
||||
.parse::<u32>()
|
||||
.map_err(|_| self.fail("max_reconnect", i18n::t("最大重连次数需要是非负整数(0=无限)")))?
|
||||
.map_err(|_| self.fail("max_reconnect", i18n::t("form.max_reconnects_invalid")))?
|
||||
};
|
||||
|
||||
// 分组:新分组名非空时优先,否则取下拉所选(首项=无分组)
|
||||
@@ -559,7 +559,7 @@ impl ConnectionForm {
|
||||
// WS/WSS 依赖 path 建立升级请求,缺失时连接必然失败,保存前拦截
|
||||
let path = self.val(&self.path, cx).trim().to_string();
|
||||
if transport.is_websocket() && path.is_empty() {
|
||||
return Err(self.fail("path", i18n::t("WS/WSS 传输下 WS 路径不能为空")));
|
||||
return Err(self.fail("path", i18n::t("form.ws_path_required")));
|
||||
}
|
||||
|
||||
let ssl = SslConfig {
|
||||
@@ -572,7 +572,7 @@ impl ConnectionForm {
|
||||
if transport.is_tls()
|
||||
&& ssl.client_cert_file.is_empty() != ssl.client_key_file.is_empty()
|
||||
{
|
||||
return Err(self.fail("ssl_client_cert", i18n::t("客户端证书与客户端密钥必须同时填写")));
|
||||
return Err(self.fail("ssl_client_cert", i18n::t("form.cert_pair_required")));
|
||||
}
|
||||
// 证书文件不存在时握手才报错太晚,保存前给出字段级提示
|
||||
if transport.is_tls() {
|
||||
@@ -582,7 +582,7 @@ impl ConnectionForm {
|
||||
("ssl_client_key", "客户端私钥", &ssl.client_key_file),
|
||||
] {
|
||||
if !p.is_empty() && !std::path::Path::new(p).exists() {
|
||||
return Err(self.fail(key, i18n::tf("{label}路径不存在:{p}", &[("label", &i18n::t(label)), ("p", &p)])));
|
||||
return Err(self.fail(key, i18n::tf("form.path_missing", &[("label", &i18n::t(label)), ("p", &p)])));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -591,13 +591,13 @@ impl ConnectionForm {
|
||||
// 与其它字段一致:trim 后入库
|
||||
let topic = self.val(&self.will_topic, cx).trim().to_string();
|
||||
if topic.is_empty() {
|
||||
return Err(self.fail("will_topic", i18n::t("遗嘱主题不能为空")));
|
||||
return Err(self.fail("will_topic", i18n::t("will.topic_required")));
|
||||
}
|
||||
// 通配符只用于订阅过滤器;出现在 PUBLISH 主题上会被 broker 直接拒绝
|
||||
if topic.contains('+') || topic.contains('#') {
|
||||
return Err(self.fail(
|
||||
"will_topic",
|
||||
i18n::t("遗嘱主题不能包含通配符 + 或 #"),
|
||||
i18n::t("will.topic_wildcard"),
|
||||
));
|
||||
}
|
||||
let opt_str = |v: String| {
|
||||
@@ -703,7 +703,7 @@ impl ConnectionForm {
|
||||
)
|
||||
.child(
|
||||
Button::new(id)
|
||||
.label(i18n::t("浏览…"))
|
||||
.label(i18n::t("common.browse"))
|
||||
.outline()
|
||||
.small()
|
||||
.on_click(cx.listener(move |this, _, window, cx| {
|
||||
@@ -723,7 +723,7 @@ impl ConnectionForm {
|
||||
let (tx, rx) = smol::channel::bounded::<Option<std::path::PathBuf>>(1);
|
||||
std::thread::spawn(move || {
|
||||
let picked = rfd::FileDialog::new()
|
||||
.set_title(i18n::t("选择证书 / 密钥文件"))
|
||||
.set_title(i18n::t("ssl.pick_file"))
|
||||
.add_filter("证书 / 密钥 (PEM)", &["pem", "crt", "cer", "key", "der"])
|
||||
.pick_file();
|
||||
let _ = tx.send_blocking(picked);
|
||||
@@ -878,40 +878,40 @@ impl Render for ConnectionForm {
|
||||
.iter()
|
||||
.filter(|on| **on)
|
||||
.count();
|
||||
let ssl_hint = (ssl_count > 0).then(|| SharedString::from(i18n::tf("已配置 {n} 项", &[("n", &ssl_count.to_string())])));
|
||||
let ssl_hint = (ssl_count > 0).then(|| SharedString::from(i18n::tf("ssl.n_configured", &[("n", &ssl_count)])));
|
||||
let mqtt5_hint =
|
||||
(mqtt5_count > 0).then(|| SharedString::from(i18n::tf("已配置 {n} 项", &[("n", &mqtt5_count.to_string())])));
|
||||
(mqtt5_count > 0).then(|| SharedString::from(i18n::tf("ssl.n_configured", &[("n", &mqtt5_count)])));
|
||||
v_flex()
|
||||
.gap_3()
|
||||
.max_h(px(560.))
|
||||
.overflow_y_scrollbar()
|
||||
.pr_1()
|
||||
// ── 基本信息(始终展开) ──
|
||||
.child(section(i18n::t("基本信息"), border, card_bg,
|
||||
.child(section(i18n::t("form.basics"), border, card_bg,
|
||||
v_flex().gap_2().child(
|
||||
// 主机与端口是一对,放同一行;名称与协议/传输同行
|
||||
h_flex().gap_2().w_full()
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("主机"), Input::new(&self.host), true, err("host"), danger)))
|
||||
.child(div().w(px(120.)).child(field_ex(i18n::t(i18n::t("端口")), Input::new(&self.port), true, err("port"), danger)))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("form.host"), Input::new(&self.host), true, err("host"), danger)))
|
||||
.child(div().w(px(120.)).child(field_ex(i18n::t(i18n::t("form.port")), Input::new(&self.port), true, err("port"), danger)))
|
||||
)
|
||||
.child(h_flex().gap_2().w_full()
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("名称"), Input::new(&self.name), true, err("name"), danger)))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("协议"), Select::new(&self.protocol))))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("传输"), Select::new(&self.transport))))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("form.name"), Input::new(&self.name), true, err("name"), danger)))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("form.protocol"), Select::new(&self.protocol))))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("form.transport"), Select::new(&self.transport))))
|
||||
)
|
||||
.child(h_flex().gap_2().w_full()
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("分组"), Select::new(&self.group_select))))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("新建分组"), Input::new(&self.group_new))))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("form.group"), Select::new(&self.group_select))))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("form.new_group"), Input::new(&self.group_new))))
|
||||
)
|
||||
.child(h_flex().gap_2().w_full().items_end()
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("Client ID"), Input::new(&self.client_id), true, err("client_id"), danger)))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("form.client_id"), Input::new(&self.client_id), true, err("client_id"), danger)))
|
||||
// 一键换一个随机 Client ID,与 ConnectionConfig::new 的生成逻辑一致
|
||||
.child(
|
||||
Button::new("cid-regen")
|
||||
.icon(IconName::RefreshCw)
|
||||
.ghost()
|
||||
.tooltip(i18n::t("重新生成 Client ID"))
|
||||
.accessibility_label(i18n::t("重新生成 Client ID"))
|
||||
.tooltip(i18n::t("form.regen_client_id"))
|
||||
.accessibility_label(i18n::t("form.regen_client_id"))
|
||||
.on_click(cx.listener(|this, _, window, cx| {
|
||||
let cid = crate::model::generate_client_id();
|
||||
this.client_id
|
||||
@@ -921,48 +921,48 @@ impl Render for ConnectionForm {
|
||||
)
|
||||
// WS 路径仅对 WebSocket/WSS 有意义,按需显示;该传输下必填
|
||||
.when(is_ws, |w| w.child(
|
||||
div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("WS 路径"), Input::new(&self.path), true, err("path"), danger))
|
||||
div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("form.ws_path"), Input::new(&self.path), true, err("path"), danger))
|
||||
))
|
||||
)
|
||||
))
|
||||
// ── 认证与心跳 ──
|
||||
.child(self.collapsible_section(
|
||||
"sec-auth", i18n::t("认证与心跳"), None, false, self.show_auth,
|
||||
"sec-auth", i18n::t("form.auth_section"), None, false, self.show_auth,
|
||||
|f| f.show_auth = !f.show_auth, border, card_bg,
|
||||
v_flex().gap_2()
|
||||
.child(h_flex().gap_2().w_full()
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("用户名"), Input::new(&self.username))))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("密码"), Input::new(&self.password).mask_toggle())))
|
||||
.child(div().w(px(110.)).child(field_ex(i18n::t("Keep Alive (秒)"), Input::new(&self.keep_alive), true, err("keep_alive"), danger)))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("form.username"), Input::new(&self.username))))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("form.password"), Input::new(&self.password).mask_toggle())))
|
||||
.child(div().w(px(110.)).child(field_ex(i18n::t("form.keep_alive"), Input::new(&self.keep_alive), true, err("keep_alive"), danger)))
|
||||
)
|
||||
.child(h_flex().gap_2().w_full()
|
||||
.child(div().w(px(150.)).child(field_ex(i18n::t("连接超时 (秒)"), Input::new(&self.conn_timeout), false, err("conn_timeout"), danger)))
|
||||
.child(div().w(px(170.)).child(field_ex(i18n::t("最大重连次数 (0=无限)"), Input::new(&self.max_reconnect), false, err("max_reconnect"), danger)))
|
||||
.child(div().w(px(150.)).child(field_ex(i18n::t("form.conn_timeout"), Input::new(&self.conn_timeout), false, err("conn_timeout"), danger)))
|
||||
.child(div().w(px(170.)).child(field_ex(i18n::t("form.max_reconnects"), Input::new(&self.max_reconnect), false, err("max_reconnect"), danger)))
|
||||
)
|
||||
.child(self.switch_row("clean_start", i18n::t("Clean Start / Clean Session"), self.clean_start, cx))
|
||||
.child(self.switch_row("auto_reconnect", i18n::t("断线自动重连"), self.auto_reconnect, cx))
|
||||
.child(self.switch_row("auto_resubscribe", i18n::t("连接后自动恢复订阅"), self.auto_resubscribe, cx))
|
||||
.child(self.switch_row("auto_connect", i18n::t("启动时自动连接"), self.auto_connect, cx)),
|
||||
.child(self.switch_row("clean_start", i18n::t("form.clean_start"), self.clean_start, cx))
|
||||
.child(self.switch_row("auto_reconnect", i18n::t("form.auto_reconnect"), self.auto_reconnect, cx))
|
||||
.child(self.switch_row("auto_resubscribe", i18n::t("form.auto_resub"), self.auto_resubscribe, cx))
|
||||
.child(self.switch_row("auto_connect", i18n::t("form.auto_connect"), self.auto_connect, cx)),
|
||||
cx,
|
||||
))
|
||||
// ── SSL/TLS(仅 TLS/WSS 显示) ──
|
||||
.when(is_tls, |w| w.child(self.collapsible_section(
|
||||
"sec-ssl", i18n::t("SSL/TLS"), ssl_hint, true, self.show_ssl,
|
||||
"sec-ssl", i18n::t("ssl.section"), ssl_hint, true, self.show_ssl,
|
||||
|f| f.show_ssl = !f.show_ssl, border, card_bg,
|
||||
v_flex().gap_2()
|
||||
.child(self.cert_path_row(
|
||||
"ssl-ca-browse", i18n::t("CA 证书 (PEM)"), self.ssl_ca.clone(),
|
||||
"ssl-ca-browse", i18n::t("ssl.ca"), self.ssl_ca.clone(),
|
||||
err("ssl_ca"), danger, cx,
|
||||
))
|
||||
.child(self.cert_path_row(
|
||||
"ssl-cert-browse", i18n::t("客户端证书 (PEM)"), self.ssl_client_cert.clone(),
|
||||
"ssl-cert-browse", i18n::t("ssl.cert"), self.ssl_client_cert.clone(),
|
||||
err("ssl_client_cert"), danger, cx,
|
||||
))
|
||||
.child(self.cert_path_row(
|
||||
"ssl-key-browse", i18n::t("客户端密钥 (PEM)"), self.ssl_client_key.clone(),
|
||||
"ssl-key-browse", i18n::t("ssl.key"), self.ssl_client_key.clone(),
|
||||
err("ssl_client_key"), danger, cx,
|
||||
))
|
||||
.child(self.switch_row("ssl_ignore_ca", i18n::t("忽略 CA 校验(不验证服务器证书)"), self.ssl_ignore_ca, cx)),
|
||||
.child(self.switch_row("ssl_ignore_ca", i18n::t("ssl.skip_verify"), self.ssl_ignore_ca, cx)),
|
||||
cx,
|
||||
)))
|
||||
// ── MQTT 5 高级属性(仅 v5 协议显示) ──
|
||||
@@ -970,29 +970,29 @@ impl Render for ConnectionForm {
|
||||
"sec-mqtt5", "MQTT 5 属性", mqtt5_hint, true, self.show_mqtt5,
|
||||
|f| f.show_mqtt5 = !f.show_mqtt5, border, card_bg,
|
||||
h_flex().gap_2().w_full()
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("会话过期间隔(秒)"), Input::new(&self.session_expiry), false, err("session_expiry"), danger)))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("接收最大值"), Input::new(&self.receive_max), false, err("receive_max"), danger)))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("最大报文长度"), Input::new(&self.max_packet), false, err("max_packet"), danger)))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("主题别名上限"), Input::new(&self.topic_alias), false, err("topic_alias"), danger))),
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("form.session_expiry"), Input::new(&self.session_expiry), false, err("session_expiry"), danger)))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("form.receive_max"), Input::new(&self.receive_max), false, err("receive_max"), danger)))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("form.max_packet"), Input::new(&self.max_packet), false, err("max_packet"), danger)))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("form.topic_alias_max"), Input::new(&self.topic_alias), false, err("topic_alias"), danger))),
|
||||
cx,
|
||||
)))
|
||||
// ── 遗嘱 ──
|
||||
.child(self.collapsible_section(
|
||||
"sec-will", i18n::t("遗嘱消息 (Last Will)"),
|
||||
self.will_enabled.then(|| i18n::t("已启用").into()), true, self.show_will,
|
||||
"sec-will", i18n::t("form.will_section"),
|
||||
self.will_enabled.then(|| i18n::t("will.enabled_hint").into()), true, self.show_will,
|
||||
|f| f.show_will = !f.show_will, border, card_bg,
|
||||
v_flex().gap_2()
|
||||
.child(self.switch_row("will_enabled", i18n::t("启用遗嘱消息"), self.will_enabled, cx))
|
||||
.child(self.switch_row("will_enabled", i18n::t("form.will_enable"), self.will_enabled, cx))
|
||||
.when(self.will_enabled, |w| w
|
||||
.child(h_flex().gap_2()
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("遗嘱主题"), Input::new(&self.will_topic), true, err("will_topic"), danger)))
|
||||
.child(div().w(px(130.)).child(field(i18n::t("QoS"), Select::new(&self.will_qos))))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field_ex(i18n::t("form.will_topic"), Input::new(&self.will_topic), true, err("will_topic"), danger)))
|
||||
.child(div().w(px(130.)).child(field("QoS", Select::new(&self.will_qos))))
|
||||
)
|
||||
.child(field(i18n::t("遗嘱内容"), Input::new(&self.will_payload)))
|
||||
.child(field(i18n::t("form.will_payload"), Input::new(&self.will_payload)))
|
||||
// v5 遗嘱属性;3.1.1 连接会忽略这两项
|
||||
.child(h_flex().gap_2().w_full()
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("内容类型 (Content Type)"), Input::new(&self.will_content_type))))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("响应主题 (Response Topic)"), Input::new(&self.will_response_topic))))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("form.will_content_type"), Input::new(&self.will_content_type))))
|
||||
.child(div().flex_1().min_w(px(0.)).child(field(i18n::t("form.will_response_topic"), Input::new(&self.will_response_topic))))
|
||||
)
|
||||
.child(self.switch_row("will_retain", "Retain", self.will_retain, cx))
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user