Skip to content

Control a real USB-connected iPhone from Linux (no Mac, no paid developer account) and expose it to AI agents as MCP tools

feat: English log lines and notifications, docs (#33)

TheSalaty9391d88be27f
diff --git a/.env.example b/.env.example
index bc3b37f..3ed157f 100644
--- a/.env.example
+++ b/.env.example
@@ -7,6 +7,12 @@ IMAGE=iphone-control:local
# 数据目录:配对记录、Apple ID 会话和开发私钥、签好的 WDA、开发者镜像缓存、日志、锁屏密码。务必备份,不要提交
DATA_DIR=./data
+# 界面语言:工具说明和结果、命令行输出、日志、通知。zh(默认)或 en。
+# Language of tool texts, CLI output, logs and notifications: zh (default) or en.
+# MCP 和命令行各自按自己的设置发请求,守护进程按请求的语言回答;这里的设置管守护进程自己写的日志和通知,
+# 容器部署时也管 docker exec 起的 MCP 和命令行。
+IPHONE_CONTROL_LANG=
+
# 固定控制哪台设备,设了就不能切换。留空为自动选:正在控制的那台一直用到它断开;
# 运行中可以用 `iphone-control select` 或 iphone_select_device 工具切换
IPHONE_UDID=
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 98b6d75..bf5254f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,7 +8,7 @@ All notable changes to this project are documented here. The format is based on
### Added
-- English: `IPHONE_CONTROL_LANG=en` switches the MCP server instructions, tool descriptions, tool results, CLI output and help, and `status`/`doctor` to English. The default stays Simplified Chinese, so nothing changes unless you set it.
+- English: `IPHONE_CONTROL_LANG=en` switches tool descriptions, tool results, CLI output and help, `status`/`doctor`, logs and notifications to English. The default stays Simplified Chinese, so nothing changes unless you set it.
- The MCP server and the CLI send their language with each request and the daemon answers in it; requests from older clients carry none and get Chinese as before, so mixed versions during an upgrade keep working. `mcp-config` includes the setting when English is on.
- Text responses carry an optional `outcome` (`tapped_nothing`, `alert_reported`), so the MCP server no longer reads result text to stop a batch after a missed tap or to skip the extra alert check. Responses without it (older daemons) are still recognised by their Chinese prefixes.
diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md
index fa81ebd..57b2f69 100644
--- a/CHANGELOG.zh-CN.md
+++ b/CHANGELOG.zh-CN.md
@@ -8,7 +8,7 @@
### 新增
-- 英文界面:设 `IPHONE_CONTROL_LANG=en` 后,MCP 服务说明、工具说明、工具结果、命令行输出和帮助、`status`/`doctor` 改成英文。默认仍是简体中文,不设就没有任何变化。
+- 英文界面:设 `IPHONE_CONTROL_LANG=en` 后,工具说明和结果、命令行输出和帮助、`status`/`doctor`、日志、通知都改成英文。默认仍是简体中文,不设就没有任何变化。
- MCP 和命令行在每个请求里带上自己的语言,守护进程按它回答;旧版本客户端的请求不带语言,照旧用中文,升级过程中新旧版本混用也不受影响。开着英文时 `mcp-config` 会把这个设置带上。
- 文字响应带可选的 `outcome`(`tapped_nothing`、`alert_reported`),MCP 端据此在没点到时停下批量、跳过多余的弹窗检查,不再从结果文字里认;没有这个字段的响应(旧版本守护进程)照旧按中文开头认。
diff --git a/README.md b/README.md
index 4aeba9e..ce9166b 100644
--- a/README.md
+++ b/README.md
@@ -112,6 +112,8 @@ More: [step-by-step guide](https://derrors.github.io/iphone-control/en/guide/get
Action tools accept `then: "elements" | "screenshot"` to return the screen after the action. Screenshot pixels are tap coordinates, so the agent can tap what it sees. Games, maps and video players draw their own UI and have no element tree — use screenshots and coordinates there. Full parameters: [docs/tools.md](docs/tools.md).
+Tool texts, results, CLI output and logs are in Simplified Chinese by default; set `IPHONE_CONTROL_LANG=en` for English ([configuration](https://derrors.github.io/iphone-control/en/guide/configuration)).
+
## Everyday Commands
Run them as `docker exec -it iphone-control iphone-control <command>`, or directly for a source install and on macOS.
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 464722a..dd38a35 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -112,6 +112,8 @@ iphone-control mcp-config # 打印 `claude mcp add` 命令,复制运行
操作类工具可以带 `then: "elements" | "screenshot"`,顺带返回操作后的界面。截图的像素就是点击坐标,agent 看到哪里就能点哪里。游戏、地图、视频自己绘制界面,没有元素树,只能看截图按坐标操作。完整参数见 [docs/tools.md](docs/tools.md)(英文)。
+工具说明和结果、命令行输出、日志默认是简体中文;设 `IPHONE_CONTROL_LANG=en` 改成英文(见[配置](https://derrors.github.io/iphone-control/guide/configuration))。
+
## 常用命令
用 `docker exec -it iphone-control iphone-control <命令>` 运行;从源码运行和在 macOS 上直接调用。
diff --git a/apps/iphone-control/src/main.rs b/apps/iphone-control/src/main.rs
index 0a3e441..beaeeb8 100644
--- a/apps/iphone-control/src/main.rs
+++ b/apps/iphone-control/src/main.rs
@@ -207,13 +207,15 @@ fn mcp_config(container: Option<String>, socket: &Path) -> anyhow::Result<String
let in_container = Path::new("/.dockerenv").exists() || Path::new("/run/.containerenv").exists();
let container = container
.or_else(|| in_container.then(|| env_nonempty("CONTAINER_NAME").unwrap_or_else(|| "iphone-control".into())));
+ // 英文时把语言写进注册命令:直接调用时 MCP 客户端不带用户 shell 的环境;容器里一般由 .env 继承,
+ // 但只给这一次 docker exec 设了语言(.env 里没有)时,不写进去 MCP 就还是中文
+ let lang = |flag: &str| if ictl_l10n::is_en() { format!("{flag} {}=en ", ictl_l10n::ENV) } else { String::new() };
Ok(match container {
- Some(c) => format!("claude mcp add iphone -s user -- docker exec -i {c} iphone-control mcp"),
+ Some(c) => format!("claude mcp add iphone -s user -- docker exec -i {}{c} iphone-control mcp", lang("-e")),
None => {
let exe = std::env::current_exe()
.context(ictl_l10n::tr!("找不到本程序的路径", "can't find the path of this program"))?;
- // 容器里的 MCP 进程继承容器的 .env;直接调用时语言要写进 MCP 配置
- let lang = if ictl_l10n::is_en() { format!("-e {}=en ", ictl_l10n::ENV) } else { String::new() };
+ let lang = lang("-e");
format!(
"claude mcp add iphone -s user {lang}-- {} --socket {} mcp",
shell_quote(&exe.to_string_lossy()),
@@ -348,7 +350,7 @@ async fn status(socket: &Path) -> anyhow::Result<()> {
}
}
}
- if let Some(r) = &p.last_resign {
+ if let Some(r) = p.last_resign_text() {
println!("{}", ictl_l10n::trf!("上次重签 {r}", "Re-signed {r}"));
}
let unlock = match (s.auto_unlock, s.unlock_disabled) {
@@ -830,7 +832,7 @@ async fn wda_bridge(socket: &Path, port: u16) -> anyhow::Result<()> {
let device = device.clone();
tokio::spawn(async move {
if let Err(e) = bridge_conn(client, &device).await {
- tracing::warn!("桥接连接出错:{e}");
+ tracing::warn!("{}", ictl_l10n::log_trf!("桥接连接出错:{e}", "Bridge connection error: {e}"));
}
});
}
@@ -880,7 +882,20 @@ fn host_is_loopback(head: &[u8]) -> bool {
#[cfg(test)]
mod tests {
- use super::host_is_loopback;
+ use super::{host_is_loopback, mcp_config};
+ use ictl_l10n::{Lang, with_lang};
+ use std::path::Path;
+
+ /// 英文时注册命令带上语言(容器里也带:只给这次 docker exec 设了语言时,.env 里没有);中文和以前一样
+ #[test]
+ fn mcp_config_carries_english() {
+ let cmd = |l| with_lang(l, || mcp_config(Some("ic".into()), Path::new("/s")).unwrap());
+ assert_eq!(cmd(Lang::Zh), "claude mcp add iphone -s user -- docker exec -i ic iphone-control mcp");
+ assert_eq!(
+ cmd(Lang::En),
+ "claude mcp add iphone -s user -- docker exec -i -e IPHONE_CONTROL_LANG=en ic iphone-control mcp"
+ );
+ }
#[test]
fn bridge_only_accepts_loopback_host() {
diff --git a/crates/ictl-daemon/src/core.rs b/crates/ictl-daemon/src/core.rs
index e549198..3b2c41e 100644
--- a/crates/ictl-daemon/src/core.rs
+++ b/crates/ictl-daemon/src/core.rs
@@ -46,18 +46,59 @@ pub struct Persisted {
pub screen: Option<ScreenSize>,
/// `screen` 是哪台设备的;换了设备就不能拿来给 HID 换算坐标
pub screen_udid: Option<String>,
+ /// 上次重签的结果,旧格式:拼好的中文整句。照旧写,旧版本(降级、旧 CLI)还读它;新版本显示时用
+ /// [`Self::resign_result`]
pub last_resign: Option<String>,
+ /// 上次重签的结果,按看的人的语言显示([`Self::last_resign_text`])。旧版本写的 state.json 没有它
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub resign_result: Option<ResignRecord>,
/// 运行中选定要控制的设备(`iphone-control select`、`iphone_select_device`);None 是自动选。
/// 设了 `IPHONE_UDID` 时以它为准,这个不起作用
pub selected_udid: Option<String>,
}
+/// 一次重签的结果
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct ResignRecord {
+ /// 结束时间(Unix 秒)
+ pub at: u64,
+ /// 失败原因;成功时为 None
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub error: Option<String>,
+}
+
impl Persisted {
+ /// 记下这次重签的结果:新字段,加上旧版本认的中文整句
+ pub fn record_resign(&mut self, at: u64, error: Option<String>) {
+ let when = crate::eventlog::format_utc(at);
+ self.last_resign = Some(match &error {
+ None => format!("{when} 成功"),
+ Some(e) => format!("{when} 失败:{e}"),
+ });
+ self.resign_result = Some(ResignRecord { at, error });
+ }
+
+ /// 上次重签的结果,按当前语言;只有旧格式时原样给出
+ pub fn last_resign_text(&self) -> Option<String> {
+ let Some(r) = &self.resign_result else { return self.last_resign.clone() };
+ let when = crate::eventlog::format_utc(r.at);
+ Some(match &r.error {
+ None => ictl_l10n::trf!("{when} 成功", "{when} succeeded"),
+ Some(e) => ictl_l10n::trf!("{when} 失败:{e}", "{when} failed: {e}"),
+ })
+ }
+
pub fn load(path: &Path) -> Self {
let Ok(bytes) = std::fs::read(path) else { return Self::default() };
serde_json::from_slice(&bytes).unwrap_or_else(|e| {
// 损坏时按空状态启动(会显示「WDA 还没签名」),但要留痕
- tracing::warn!("state.json 解析失败,按空状态启动:{e}");
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "state.json 解析失败,按空状态启动:{e}",
+ "Parsing state.json failed, starting with an empty state: {e}"
+ )
+ );
Self::default()
})
}
@@ -67,7 +108,7 @@ impl Persisted {
let r = std::fs::write(&tmp, serde_json::to_vec_pretty(self).unwrap_or_default())
.and_then(|_| std::fs::rename(&tmp, path));
if let Err(e) = r {
- tracing::warn!("保存 state.json 失败:{e}");
+ tracing::warn!("{}", ictl_l10n::log_trf!("保存 state.json 失败:{e}", "Saving state.json failed: {e}"));
}
}
@@ -365,8 +406,8 @@ impl Daemon {
}
let r = self.cfg.ensure_passcodes_dir().and_then(|_| std::fs::rename(&legacy, &dst));
match r {
- Ok(()) => self.log.log(&format!("旧的锁屏密码只有一份,USB 上只接着 {},归到它名下", d.udid)),
- Err(e) => tracing::warn!("把旧的锁屏密码归到 {} 名下失败:{e}", d.udid),
+ Ok(()) => self.log.log(&ictl_l10n::log_trf!("旧的锁屏密码只有一份,USB 上只接着 {},归到它名下", "There is a single passcode saved by an older version and only {} is on USB; assigning it to that device", d.udid)),
+ Err(e) => tracing::warn!("{}", ictl_l10n::log_trf!("把旧的锁屏密码归到 {} 名下失败:{e}", "Assigning the old passcode to {} failed: {e}", d.udid)),
}
}
@@ -374,8 +415,9 @@ impl Daemon {
if !g.dedup.should_send(&e, Instant::now()) {
return;
}
- let (title, body) = e.title_body();
- self.log.log(&format!("通知:{title}"));
+ // 通知和事件日志按守护进程自己的语言:触发它的可能是另一种语言的请求(例如自动解锁失败)
+ let (title, body) = ictl_l10n::in_own_lang(|| e.title_body());
+ self.log.log(&ictl_l10n::log_trf!("通知:{title}", "Notification: {title}"));
let cfg = self.cfg.notify.clone();
if cfg.any() {
tokio::spawn(async move {
@@ -386,7 +428,7 @@ impl Daemon {
pub(crate) fn set_state(&self, g: &mut Inner, s: DeviceState) {
if g.state != s {
- self.log.log(&format!("状态:{}", s.describe()));
+ self.log.log(&ictl_l10n::log_trf!("状态:{}", "State: {}", ictl_l10n::in_own_lang(|| s.describe())));
g.state = s;
}
}
@@ -407,7 +449,13 @@ impl Daemon {
None => DeviceProfile::Missing,
},
Err(e) => {
- tracing::warn!("读手机上的描述文件失败,按签名记录算:{e}");
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "读手机上的描述文件失败,按签名记录算:{e}",
+ "Reading the provisioning profiles on the phone failed, going by the signing record: {e}"
+ )
+ );
DeviceProfile::Unknown(e.to_string())
}
};
@@ -585,7 +633,7 @@ impl Daemon {
pub async fn shutdown(&self) {
let mut g = self.inner.lock().await;
- self.log.log("收到停止信号,退出");
+ self.log.log(ictl_l10n::log_tr!("收到停止信号,退出", "Received stop signal, exiting"));
// 先停 HID 媒体流、runner(经 usbmuxd),再停 usbmuxd
self.drop_session(&mut g).await;
if let Some(mut c) = g.usbmuxd.take() {
@@ -629,6 +677,31 @@ fn check_request(req: &Request) -> Result<(), String> {
mod tests {
use super::*;
+ /// 重签结果存成时间和成败,按看的人的语言显示;旧字段照旧写中文整句,旧版本的 state.json 照样读
+ #[test]
+ fn resign_result_is_shown_in_the_reader_language() {
+ use ictl_l10n::{Lang, with_lang};
+ let mut p = Persisted::default();
+ p.record_resign(1_800_000_000, None);
+ assert_eq!(p.last_resign.as_deref(), Some("2027-01-15 08:00:00 成功"));
+ assert_eq!(with_lang(Lang::En, || p.last_resign_text()).as_deref(), Some("2027-01-15 08:00:00 succeeded"));
+ assert_eq!(with_lang(Lang::Zh, || p.last_resign_text()).as_deref(), Some("2027-01-15 08:00:00 成功"));
+ p.record_resign(1_800_000_000, Some("boom".into()));
+ assert_eq!(with_lang(Lang::En, || p.last_resign_text()).as_deref(), Some("2027-01-15 08:00:00 failed: boom"));
+
+ // 旧版本写的:只有中文整句,原样显示
+ let old: Persisted = serde_json::from_str(r#"{"last_resign":"2026-11-07 01:11:54 成功"}"#).unwrap();
+ assert_eq!(with_lang(Lang::En, || old.last_resign_text()).as_deref(), Some("2026-11-07 01:11:54 成功"));
+ // 新版本写的,旧版本读:多出来的字段不影响(这里用只认旧字段的结构模拟)
+ #[derive(serde::Deserialize)]
+ struct OldPersisted {
+ last_resign: Option<String>,
+ }
+ let json = serde_json::to_string(&p).unwrap();
+ let o: OldPersisted = serde_json::from_str(&json).unwrap();
+ assert_eq!(o.last_resign.as_deref(), Some("2027-01-15 08:00:00 失败:boom"));
+ }
+
fn test_daemon(tag: &str) -> (Arc<Daemon>, std::path::PathBuf) {
let dir = std::env::temp_dir().join(format!("ictl-core-{tag}-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
diff --git a/crates/ictl-daemon/src/doctor.rs b/crates/ictl-daemon/src/doctor.rs
index 79900f7..f4cebbf 100644
--- a/crates/ictl-daemon/src/doctor.rs
+++ b/crates/ictl-daemon/src/doctor.rs
@@ -177,7 +177,7 @@ impl Daemon {
fails += 1;
}
}
- if let Some(r) = &g.persisted.last_resign {
+ if let Some(r) = g.persisted.last_resign_text() {
out.push(ictl_l10n::trf!(" 上次重签:{r}", " Last re-sign: {r}"));
}
diff --git a/crates/ictl-daemon/src/eventlog.rs b/crates/ictl-daemon/src/eventlog.rs
index ec10108..7976e1c 100644
--- a/crates/ictl-daemon/src/eventlog.rs
+++ b/crates/ictl-daemon/src/eventlog.rs
@@ -30,7 +30,7 @@ impl EventLog {
pub fn log(&self, msg: &str) {
tracing::info!("{msg}");
if let Err(e) = self.append(msg) {
- tracing::warn!("写事件日志失败:{e}");
+ tracing::warn!("{}", ictl_l10n::log_trf!("写事件日志失败:{e}", "Writing the event log failed: {e}"));
}
}
diff --git a/crates/ictl-daemon/src/lib.rs b/crates/ictl-daemon/src/lib.rs
index 6f982f9..4086be0 100644
--- a/crates/ictl-daemon/src/lib.rs
+++ b/crates/ictl-daemon/src/lib.rs
@@ -61,7 +61,7 @@ pub async fn run(cfg: Config) -> anyhow::Result<()> {
async fn serve(cfg: Config, listener: tokio::net::UnixListener) -> anyhow::Result<()> {
let daemon = Daemon::new(cfg);
- daemon.log.log("守护进程启动");
+ daemon.log.log(ictl_l10n::log_tr!("守护进程启动", "Daemon started"));
let mut term = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())?;
let mut tick = tokio::time::interval(core::TICK);
@@ -78,7 +78,7 @@ async fn serve(cfg: Config, listener: tokio::net::UnixListener) -> anyhow::Resul
Ok((stream, _)) => {
conns.spawn_local(serve_conn(daemon.clone(), stream));
}
- Err(e) => tracing::warn!("控制接口 accept 失败:{e}"),
+ Err(e) => tracing::warn!("{}", ictl_l10n::log_trf!("控制接口 accept 失败:{e}", "Accepting on the control socket failed: {e}")),
},
Some(_) = conns.join_next(), if !conns.is_empty() => {}
_ = tick.tick() => {
diff --git a/crates/ictl-daemon/src/notify.rs b/crates/ictl-daemon/src/notify.rs
index e5932f8..31b7740 100644
--- a/crates/ictl-daemon/src/notify.rs
+++ b/crates/ictl-daemon/src/notify.rs
@@ -33,8 +33,10 @@ impl Event {
/// 每类事件一个样例(`iphone-control notify-test` 用),顺序与枚举一致
pub fn samples() -> Vec<Event> {
vec![
- Self::ResignFailed("(测试)苹果服务器返回错误".into()),
- Self::SessionExpired("(测试)令牌已过期".into()),
+ Self::ResignFailed(
+ ictl_l10n::tr!("(测试)苹果服务器返回错误", "(test) Apple's server returned an error").into(),
+ ),
+ Self::SessionExpired(ictl_l10n::tr!("(测试)令牌已过期", "(test) the token expired").into()),
Self::NeedsAutomationPin,
Self::WdaRecovered,
Self::UnlockDisabled,
@@ -51,27 +53,27 @@ impl Event {
pub fn title_body(&self) -> (String, String) {
match self {
Self::ResignFailed(why) => (
- "iPhone WDA 重签失败".into(),
- format!("{why}\n描述文件过期后 WDA 将无法启动(截图/点击的 HID 路线不受影响)。\n排查: iphone-control doctor"),
+ ictl_l10n::tr!("iPhone WDA 重签失败", "iPhone: re-signing WDA failed").into(),
+ ictl_l10n::trf!("{why}\n描述文件过期后 WDA 将无法启动(截图/点击的 HID 路线不受影响)。\n排查: iphone-control doctor", "{why}\nOnce the provisioning profile expires WDA can't start (the HID path for screenshots/taps is not affected).\nTroubleshoot: iphone-control doctor"),
),
Self::SessionExpired(why) => (
- "Apple ID 会话已失效".into(),
- format!("{why}\n下次重签前需要重新登录: iphone-control login"),
+ ictl_l10n::tr!("Apple ID 会话已失效", "Apple ID session expired").into(),
+ ictl_l10n::trf!("{why}\n下次重签前需要重新登录: iphone-control login", "{why}\nSign in again before the next re-sign: iphone-control login"),
),
Self::NeedsAutomationPin => (
- "iPhone 需要输入锁屏密码".into(),
- "手机重启后要启用 UI 自动化:请解锁手机,在「为 XCTest 输入 iPhone 密码」弹窗里输入锁屏密码。弹窗没出现或已关闭的话,1 分钟内会重新弹出。".into(),
+ ictl_l10n::tr!("iPhone 需要输入锁屏密码", "iPhone needs the passcode").into(),
+ ictl_l10n::tr!("手机重启后要启用 UI 自动化:请解锁手机,在「为 XCTest 输入 iPhone 密码」弹窗里输入锁屏密码。弹窗没出现或已关闭的话,1 分钟内会重新弹出。", "After a reboot, UI automation has to be enabled: unlock the phone and enter the passcode in the “Enter iPhone passcode for XCTest” prompt. If the prompt didn't appear or was dismissed, it comes back within a minute.").into(),
),
- Self::WdaRecovered => ("iPhone WDA 已恢复".into(), "已输入密码,WDA 重新就绪,可以正常操作了。".into()),
+ Self::WdaRecovered => (ictl_l10n::tr!("iPhone WDA 已恢复", "iPhone WDA is back").into(), ictl_l10n::tr!("已输入密码,WDA 重新就绪,可以正常操作了。", "Passcode entered, WDA is ready again and everything works.").into()),
Self::UnlockDisabled => (
- "iPhone 自动解锁失败,已停用".into(),
- "整串密码输完手机仍锁着(可能密码配置不对),或输入途中出错、无法确认密码是否已提交。为免累计输错,自动解锁已停用。\n请人工解锁手机、核对密码(iphone-control passcode set),再运行 iphone-control unlock-reset。".into(),
+ ictl_l10n::tr!("iPhone 自动解锁失败,已停用", "iPhone auto-unlock failed and was disabled").into(),
+ ictl_l10n::tr!("整串密码输完手机仍锁着(可能密码配置不对),或输入途中出错、无法确认密码是否已提交。为免累计输错,自动解锁已停用。\n请人工解锁手机、核对密码(iphone-control passcode set),再运行 iphone-control unlock-reset。", "The phone stayed locked after entering the whole passcode (the configured passcode may be wrong), or an error happened while entering it so it's unclear whether it was submitted. Auto-unlock is now disabled so wrong attempts don't pile up.\nUnlock the phone by hand, check the passcode (iphone-control passcode set), then run iphone-control unlock-reset.").into(),
),
Self::DeviceOffline { minutes } => (
- format!("iPhone 已离线 {minutes} 分钟"),
- "连不上手机:检查 USB 线、手机是否没电关机。重新连上后会自动恢复。".into(),
+ ictl_l10n::trf!("iPhone 已离线 {minutes} 分钟", "iPhone offline for {minutes} minutes"),
+ ictl_l10n::tr!("连不上手机:检查 USB 线、手机是否没电关机。重新连上后会自动恢复。", "Can't reach the phone: check the USB cable and whether the phone ran out of battery. It recovers automatically once reconnected.").into(),
),
- Self::DeviceOnline { minutes } => ("iPhone 已重新连上".into(), format!("离线约 {minutes} 分钟,正在自动恢复。")),
+ Self::DeviceOnline { minutes } => (ictl_l10n::tr!("iPhone 已重新连上", "iPhone reconnected").into(), ictl_l10n::trf!("离线约 {minutes} 分钟,正在自动恢复。", "Offline for about {minutes} minutes, recovering automatically.")),
}
}
}
@@ -121,7 +123,10 @@ pub async fn send(cfg: &NotifyConfig, title: &str, body: &str) -> usize {
let client = match reqwest::Client::builder().timeout(Duration::from_secs(20)).build() {
Ok(c) => c,
Err(e) => {
- tracing::warn!("通知客户端创建失败:{e}");
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!("通知客户端创建失败:{e}", "Creating the notification client failed: {e}")
+ );
return 0;
}
};
@@ -135,7 +140,10 @@ pub async fn send(cfg: &NotifyConfig, title: &str, body: &str) -> usize {
.and_then(|r| r.error_for_status());
match r {
Ok(_) => ok += 1,
- Err(e) => tracing::warn!("Telegram 发送失败:{}", e.without_url()),
+ Err(e) => tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!("Telegram 发送失败:{}", "Sending via Telegram failed: {}", e.without_url())
+ ),
}
}
if let Some(key) = &cfg.bark_key {
@@ -147,7 +155,10 @@ pub async fn send(cfg: &NotifyConfig, title: &str, body: &str) -> usize {
.and_then(|r| r.error_for_status());
match r {
Ok(_) => ok += 1,
- Err(e) => tracing::warn!("Bark 发送失败:{}", e.without_url()),
+ Err(e) => tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!("Bark 发送失败:{}", "Sending via Bark failed: {}", e.without_url())
+ ),
}
}
ok
diff --git a/crates/ictl-daemon/src/supervise.rs b/crates/ictl-daemon/src/supervise.rs
index e8064c6..a871383 100644
--- a/crates/ictl-daemon/src/supervise.rs
+++ b/crates/ictl-daemon/src/supervise.rs
@@ -72,8 +72,7 @@ impl Daemon {
g.usbmuxd_delay = (g.usbmuxd_delay * 2).clamp(Duration::from_secs(10), USBMUXD_MAX_DELAY);
g.usbmuxd_retry_at = Some(Instant::now() + g.usbmuxd_delay);
g.usbmuxd_started = None;
- self.log.log(&format!(
- "usbmuxd 启动后很快就退出了({why}),{} 秒后再试;宿主机已在运行 usbmuxd 时设 ICTL_MANAGE_USBMUXD=0",
+ self.log.log(&ictl_l10n::log_trf!("usbmuxd 启动后很快就退出了({why}),{} 秒后再试;宿主机已在运行 usbmuxd 时设 ICTL_MANAGE_USBMUXD=0", "usbmuxd exited right after starting ({why}), retrying in {} seconds; if the host already runs usbmuxd, set ICTL_MANAGE_USBMUXD=0",
g.usbmuxd_delay.as_secs()
));
}
@@ -101,10 +100,10 @@ impl Daemon {
if g.usbmuxd_retry_at.take().is_none() {
g.usbmuxd_delay = Duration::ZERO;
}
- self.log.log("usbmuxd 已(重新)启动");
+ self.log.log(ictl_l10n::log_tr!("usbmuxd 已(重新)启动", "usbmuxd (re)started"));
tokio::time::sleep(Duration::from_secs(1)).await;
}
- Err(e) => self.log.log(&format!("启动 usbmuxd 失败:{e}")),
+ Err(e) => self.log.log(&ictl_l10n::log_trf!("启动 usbmuxd 失败:{e}", "Starting usbmuxd failed: {e}")),
}
}
@@ -118,7 +117,13 @@ impl Daemon {
if g.tunnel.as_ref().is_some_and(Tunnel::hid_open) && g.hid_used.is_none_or(|t| t.elapsed() >= HID_IDLE) {
close_hid(g).await;
- tracing::info!("HID 会话空闲,已关闭(停止屏幕媒体流)");
+ tracing::info!(
+ "{}",
+ ictl_l10n::log_tr!(
+ "HID 会话空闲,已关闭(停止屏幕媒体流)",
+ "HID session idle, closed it (screen media stream stopped)"
+ )
+ );
}
self.poll_start(g).await;
@@ -130,7 +135,14 @@ impl Daemon {
Err(e) => {
// usbmuxd 抖一下就当离线会拆掉整个会话:连续几轮都失败才算
g.list_errors += 1;
- tracing::debug!("列设备失败(第 {} 次):{e}", g.list_errors);
+ tracing::debug!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "列设备失败(第 {} 次):{e}",
+ "Listing devices failed (attempt {}): {e}",
+ g.list_errors
+ )
+ );
if g.list_errors < LIST_ERRORS_OFFLINE {
self.publish(g);
return;
@@ -146,8 +158,11 @@ impl Daemon {
// 只在容器里(自己看护 usbmuxd、没有 udev)需要;用系统的 usbmuxd 服务时插拔由 udev 处理,也重启不了它
let on_usb = ictl_device::ios_usb_count(Path::new(SYSFS_USB));
if self.cfg.manage_usbmuxd && g.mux.observe(on_usb, g.connected.len()) {
- self.log
- .log(&format!("USB 上有 {on_usb} 台 iPhone/iPad,usbmuxd 只认到 {} 台,重启 usbmuxd", g.connected.len()));
+ self.log.log(&ictl_l10n::log_trf!(
+ "USB 上有 {on_usb} 台 iPhone/iPad,usbmuxd 只认到 {} 台,重启 usbmuxd",
+ "{on_usb} iPhone/iPad on USB but usbmuxd only sees {}, restarting usbmuxd",
+ g.connected.len()
+ ));
self.ensure_usbmuxd(g, true).await;
}
@@ -184,7 +199,7 @@ impl Daemon {
g.device_profile = DeviceProfile::NotChecked;
g.wda_rotation = None;
if g.device.take().is_some() {
- self.log.log("手机离线");
+ self.log.log(ictl_l10n::log_tr!("手机离线", "Phone offline"));
// 名字、型号、iOS 版本是这台的:留着的话状态、提示文字会把它当成还在控制的设备
g.info = None;
self.drop_session(g).await;
@@ -204,12 +219,18 @@ impl Daemon {
// usbmuxd 却换了编号,旧句柄的每个连接都报 bad device,永远恢复不了
if !g.device.as_ref().is_some_and(|d| d.is_connection(seen)) {
match g.device.take() {
- Some(old) if old.udid == seen.udid => self.log.log(&format!(
+ Some(old) if old.udid == seen.udid => self.log.log(&ictl_l10n::log_trf!(
"手机重新接入(usbmuxd 编号 {} → {}),重建连接",
+ "Phone reconnected (usbmuxd id {} → {}), reconnecting",
old.device_id(),
seen.device_id
)),
- Some(old) => self.log.log(&format!("改为控制 {}(原来是 {})", seen.udid, old.udid)),
+ Some(old) => self.log.log(&ictl_l10n::log_trf!(
+ "改为控制 {}(原来是 {})",
+ "Now controlling {} (was {})",
+ seen.udid,
+ old.udid
+ )),
None => {}
}
self.drop_session(g).await;
@@ -224,7 +245,7 @@ impl Daemon {
}
let model =
g.info.as_ref().map(|i| format!(" {} iOS {}", i.product_type, i.product_version)).unwrap_or_default();
- self.log.log(&format!("手机在线{model}"));
+ self.log.log(&ictl_l10n::log_trf!("手机在线{model}", "Phone online{model}"));
g.device = Some(d);
g.backoff.reset();
g.next_resign = g.next_resign.min(Instant::now() + RESIGN_CHECK_AFTER_CONNECT);
@@ -245,7 +266,12 @@ impl Daemon {
}
Ok(false) => return self.set_state(g, DeviceState::NeedsTrust),
// usbmuxd 出错:这一轮不下结论
- Err(e) => return tracing::debug!("查配对记录失败:{e}"),
+ Err(e) => {
+ return tracing::debug!(
+ "{}",
+ ictl_l10n::log_trf!("查配对记录失败:{e}", "Checking the pairing record failed: {e}")
+ );
+ }
}
if g.state != DeviceState::Ready && !device.developer_mode_enabled().await.unwrap_or(true) {
return self.set_state(g, DeviceState::DeveloperModeOff);
@@ -285,7 +311,7 @@ impl Daemon {
return;
}
if g.runner.is_some() {
- self.log.log("WDA 不可用");
+ self.log.log(ictl_l10n::log_tr!("WDA 不可用", "WDA unavailable"));
// 隧道和 HID 也一起丢:WDA 掉线常常是底层连接断了(例如 usbmuxd 重启),
// 留着旧隧道,下次查镜像就报 socket io failed 并白白退避 60 秒
self.drop_session(g).await;
@@ -304,7 +330,7 @@ impl Daemon {
if !matches!(g.state, DeviceState::NeedsAutomationPin | DeviceState::NeedsUnlock) {
self.set_state(g, DeviceState::WdaStarting { last_error: None });
}
- self.log.log("启动 WDA");
+ self.log.log(ictl_l10n::log_tr!("启动 WDA", "Starting WDA"));
let (cache, url, user_dir) = (self.cfg.ddi_cache(), self.cfg.ddi_url.clone(), self.cfg.ddi_dir.clone());
g.starting = Some(tokio::task::spawn_local(async move {
// 手机重启后开发者镜像可能掉了;已挂载时只是一次查询。错误带上「是不是挂载这一步」
@@ -344,12 +370,13 @@ impl Daemon {
return;
}
let h = g.starting.take().expect("刚检查过");
- let outcome =
- h.await.unwrap_or_else(|e| StartOutcome::Wda(WdaError::StartFailed(format!("启动任务异常:{e}"))));
+ let outcome = h.await.unwrap_or_else(|e| {
+ StartOutcome::Wda(WdaError::StartFailed(ictl_l10n::trf!("启动任务异常:{e}", "Start task failed: {e}")))
+ });
match outcome {
StartOutcome::Ready { runner, client, mounted } => {
if let Some(v) = mounted {
- self.log.log(&format!("开发者镜像已挂载 {v}"));
+ self.log.log(&ictl_l10n::log_trf!("开发者镜像已挂载 {v}", "Developer disk image mounted {v}"));
}
g.ddi_failures = 0;
g.runner = Some(runner);
@@ -366,13 +393,18 @@ impl Daemon {
if mount_failed && self.cfg.ddi_dir.is_none() {
g.ddi_failures += 1;
if g.ddi_failures >= DDI_FAILURES_INVALIDATE {
- self.log.log(&format!("开发者镜像连续 {} 次挂载失败,清掉缓存,下次重新下载", g.ddi_failures));
+ self.log.log(&ictl_l10n::log_trf!("开发者镜像连续 {} 次挂载失败,清掉缓存,下次重新下载", "Mounting the developer disk image failed {} times in a row, clearing the cache to download it again", g.ddi_failures));
ictl_device::ddi::invalidate(&self.cfg.ddi_cache());
g.ddi_failures = 0;
}
}
g.backoff.failed(Instant::now());
- self.set_state(g, DeviceState::WdaStarting { last_error: Some(format!("开发者镜像:{e}")) });
+ self.set_state(
+ g,
+ DeviceState::WdaStarting {
+ last_error: Some(ictl_l10n::trf!("开发者镜像:{e}", "Developer disk image: {e}")),
+ },
+ );
}
StartOutcome::Wda(WdaError::NeedsAutomationPin) => {
g.backoff.waiting_for_pin(Instant::now());
@@ -381,7 +413,7 @@ impl Daemon {
}
StartOutcome::Wda(e) => {
g.backoff.failed(Instant::now());
- self.log.log(&format!("WDA 启动失败:{e}"));
+ self.log.log(&ictl_l10n::log_trf!("WDA 启动失败:{e}", "WDA failed to start: {e}"));
self.set_state(g, DeviceState::WdaStarting { last_error: Some(e.to_string()) });
}
}
@@ -398,18 +430,23 @@ impl Daemon {
Ok(Ok(_)) => Ok(()),
Ok(Err(ictl_sign::SignError::NotLoggedIn)) => Err(None),
Ok(Err(e)) => Err(Some(e.to_string())),
- Err(_) => Err(Some(format!("{} 分钟内没有完成", SESSION_CHECK_TIMEOUT.as_secs() / 60))),
+ Err(_) => Err(Some(ictl_l10n::trf!(
+ "{} 分钟内没有完成",
+ "not finished within {} minutes",
+ SESSION_CHECK_TIMEOUT.as_secs() / 60
+ ))),
}
})
})
.await
- .unwrap_or_else(|e| Err(Some(format!("会话检查任务异常:{e}"))));
+ .unwrap_or_else(|e| Err(Some(ictl_l10n::trf!("会话检查任务异常:{e}", "Session check task failed: {e}"))));
let mut g = self.inner.lock().await;
match r {
Ok(()) => g.dedup.clear("session"),
Err(None) => {}
Err(Some(e)) => {
- self.log.log(&format!("Apple ID 会话检查失败:{e}"));
+ self.log
+ .log(&ictl_l10n::trf!("Apple ID 会话检查失败:{e}", "Checking the Apple ID session failed: {e}"));
self.notify(&mut g, Event::SessionExpired(e));
}
}
@@ -454,7 +491,7 @@ impl Daemon {
.filter(|n| !n.is_empty())
.unwrap_or_else(|| "iphone-control".into());
g.resigning = true;
- self.log.log("开始重签");
+ self.log.log(ictl_l10n::log_tr!("开始重签", "Re-signing started"));
(device, name)
};
let signed_udid = device.udid.clone();
@@ -463,7 +500,11 @@ impl Daemon {
(self.cfg.wda_dir(), self.cfg.wda_unsigned.clone(), self.cfg.wda_signed());
let fetch = self.cfg.wda_unsigned_is_cache() && !unsigned.is_file();
if fetch {
- self.log.log(&format!("没有未签名的 WDA 包(不在镜像里运行),先下载 {}", crate::wda_pkg::WDA_VERSION));
+ self.log.log(&ictl_l10n::log_trf!(
+ "没有未签名的 WDA 包(不在镜像里运行),先下载 {}",
+ "No unsigned WDA package (not running in the image), downloading {} first",
+ crate::wda_pkg::WDA_VERSION
+ ));
}
// plume_core 的签名 future 不是 Send(持有 &mut dyn FnMut 和非 Send 的私钥),放到阻塞线程里 block_on
let r: Result<ictl_sign::Signed, String> = tokio::task::spawn_blocking(move || {
@@ -477,16 +518,25 @@ impl Daemon {
std::fs::create_dir_all(&wda_dir).map_err(|e| e.to_string())?;
let tmp = wda_dir.join("WDA-signing.ipa");
let signed = session.sign_ipa(&unsigned, &tmp, &device.udid).await.map_err(|e| e.to_string())?;
- device.install(&tmp).await.map_err(|e| format!("安装到手机失败(手机锁屏?):{e}"))?;
+ device.install(&tmp).await.map_err(|e| {
+ ictl_l10n::trf!(
+ "安装到手机失败(手机锁屏?):{e}",
+ "Installing on the phone failed (phone locked?): {e}"
+ )
+ })?;
std::fs::rename(&tmp, &signed_path).map_err(|e| e.to_string())?;
Ok(signed)
}))
.unwrap_or_else(|_| {
- Err(format!("{} 分钟内没有完成(苹果服务器或安装卡住)", RESIGN_TIMEOUT.as_secs() / 60))
+ Err(ictl_l10n::trf!(
+ "{} 分钟内没有完成(苹果服务器或安装卡住)",
+ "not finished within {} minutes (Apple's servers or the install got stuck)",
+ RESIGN_TIMEOUT.as_secs() / 60
+ ))
})
})
.await
- .unwrap_or_else(|e| Err(format!("签名任务异常退出:{e}")));
+ .unwrap_or_else(|e| Err(ictl_l10n::trf!("签名任务异常退出:{e}", "The signing task exited abnormally: {e}")));
let mut g = self.inner.lock().await;
let g = &mut *g;
@@ -497,7 +547,7 @@ impl Daemon {
g.persisted.team_id = Some(s.team_id);
g.persisted.wda_bundle = Some(s.bundle_id);
g.persisted.profile_expires = Some(exp);
- g.persisted.last_resign = Some(format!("{} 成功", crate::eventlog::timestamp()));
+ g.persisted.record_resign(now_secs(), None);
g.persisted.save(&self.cfg.state_file());
// 新包装上后旧的 runner 会失效,下一轮巡检重新拉起。签名期间切到了别的设备就不动它的会话
if g.device.as_ref().is_some_and(|d| d.udid == signed_udid) {
@@ -506,14 +556,21 @@ impl Daemon {
g.backoff.reset();
}
g.dedup.clear("resign");
- let msg = format!("重签完成,新描述文件到期 {} UTC", crate::eventlog::format_utc(exp));
- self.log.log(&msg);
- Ok(msg)
+ let expires = crate::eventlog::format_utc(exp);
+ // 事件日志按守护进程的语言,返回给调用方的按请求的语言
+ self.log.log(&ictl_l10n::log_trf!(
+ "重签完成,新描述文件到期 {expires} UTC",
+ "Re-signing done, the new provisioning profile expires {expires} UTC"
+ ));
+ Ok(ictl_l10n::trf!(
+ "重签完成,新描述文件到期 {expires} UTC",
+ "Re-signing done, the new provisioning profile expires {expires} UTC"
+ ))
}
Err(e) => {
- g.persisted.last_resign = Some(format!("{} 失败:{e}", crate::eventlog::timestamp()));
+ g.persisted.record_resign(now_secs(), Some(e.clone()));
g.persisted.save(&self.cfg.state_file());
- self.log.log(&format!("重签失败:{e}"));
+ self.log.log(&ictl_l10n::log_trf!("重签失败:{e}", "Re-signing failed: {e}"));
Err(e)
}
};
@@ -521,3 +578,7 @@ impl Daemon {
r
}
}
+
+fn now_secs() -> u64 {
+ std::time::SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs()
+}
diff --git a/crates/ictl-daemon/src/tools.rs b/crates/ictl-daemon/src/tools.rs
index 2d06355..b78b4a7 100644
--- a/crates/ictl-daemon/src/tools.rs
+++ b/crates/ictl-daemon/src/tools.rs
@@ -698,7 +698,10 @@ impl Daemon {
match w.lock().await {
Ok(()) => true,
Err(e) => {
- tracing::info!("WDA 锁屏报错:{e}");
+ tracing::info!(
+ "{}",
+ ictl_l10n::log_trf!("WDA 锁屏报错:{e}", "WDA lock returned an error: {e}")
+ );
w.wda_reports_locked().await.unwrap_or(false)
}
}
@@ -835,7 +838,13 @@ async fn press_home(w: &mut WdaClient<DeviceTransport>) -> Result<String, WdaErr
Ok(()) => {}
Err(e @ WdaError::Unavailable(_)) => return Err(e),
Err(e) if via_hid => {
- tracing::info!("经 IOHID 按 Home 报错,改用 XCTest:{e}");
+ tracing::info!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "经 IOHID 按 Home 报错,改用 XCTest:{e}",
+ "Pressing Home via IOHID failed, using XCTest: {e}"
+ )
+ );
continue;
}
Err(e) => return Err(e),
@@ -852,7 +861,13 @@ async fn press_home(w: &mut WdaClient<DeviceTransport>) -> Result<String, WdaErr
tokio::time::sleep(Duration::from_millis(150)).await;
}
if via_hid {
- tracing::info!("经 IOHID 按 Home 后前台还是 {app},改用 XCTest 再按一次");
+ tracing::info!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "经 IOHID 按 Home 后前台还是 {app},改用 XCTest 再按一次",
+ "After pressing Home via IOHID the foreground is still {app}, pressing again via XCTest"
+ )
+ );
}
}
Ok(ictl_l10n::trf!(
@@ -865,7 +880,10 @@ async fn press_home(w: &mut WdaClient<DeviceTransport>) -> Result<String, WdaErr
/// WDA 的 `/wda/lock` 在 iOS 27 以下用 XCTest 的 `pressLockButton`,iPhone 12 mini(iOS 26.4.1)上锁不了屏
async fn lock_by_power_hid(w: &mut WdaClient<DeviceTransport>) -> bool {
if let Err(e) = w.press_power_hid().await {
- tracing::info!("经 IOHID 按电源键报错:{e}");
+ tracing::info!(
+ "{}",
+ ictl_l10n::log_trf!("经 IOHID 按电源键报错:{e}", "Pressing the power key via IOHID failed: {e}")
+ );
return false;
}
let deadline = Instant::now() + LOCK_WAIT;
@@ -874,7 +892,14 @@ async fn lock_by_power_hid(w: &mut WdaClient<DeviceTransport>) -> bool {
return true;
}
if Instant::now() >= deadline {
- tracing::info!("经 IOHID 按电源键后 {} 秒还没锁屏,改用 WDA 的锁屏", LOCK_WAIT.as_secs());
+ tracing::info!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "经 IOHID 按电源键后 {} 秒还没锁屏,改用 WDA 的锁屏",
+ "Still not locked {} s after pressing the power key via IOHID, using WDA's lock",
+ LOCK_WAIT.as_secs()
+ )
+ );
return false;
}
tokio::time::sleep(Duration::from_millis(200)).await;
@@ -964,7 +989,9 @@ async fn poll_stable(
/// 判断画面动没动用的缩略图。解码是 CPU 活,放到阻塞线程
async fn thumbnail(png: Vec<u8>) -> Result<Vec<u8>, String> {
- tokio::task::spawn_blocking(move || imaging::thumbnail(&png))
+ // 阻塞线程上没有请求的语言,带过去(解码失败的报错会返回给调用方)
+ let lang = ictl_l10n::lang();
+ tokio::task::spawn_blocking(move || ictl_l10n::with_lang(lang, || imaging::thumbnail(&png)))
.await
.map_err(|e| ictl_l10n::trf!("图像处理任务异常:{e}", "Image processing task failed: {e}"))?
}
diff --git a/crates/ictl-daemon/src/wda_pkg.rs b/crates/ictl-daemon/src/wda_pkg.rs
index b76453a..32bdb9e 100644
--- a/crates/ictl-daemon/src/wda_pkg.rs
+++ b/crates/ictl-daemon/src/wda_pkg.rs
@@ -26,7 +26,7 @@ pub async fn ensure(dest: &Path) -> Result<(), String> {
.ok_or(ictl_l10n::tr!("WDA 包路径没有上级目录", "the WDA package path has no parent directory"))?;
std::fs::create_dir_all(dir).map_err(|e| e.to_string())?;
let url = url();
- tracing::info!("下载未签名的 WDA {url}");
+ tracing::info!("{}", ictl_l10n::log_trf!("下载未签名的 WDA {url}", "Downloading the unsigned WDA {url}"));
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(600))
.build()
diff --git a/crates/ictl-device/src/ddi.rs b/crates/ictl-device/src/ddi.rs
index f602d6c..50a57a7 100644
--- a/crates/ictl-device/src/ddi.rs
+++ b/crates/ictl-device/src/ddi.rs
@@ -52,7 +52,13 @@ pub fn invalidate(dir: &Path) {
pub async fn ensure_cache(dir: &Path, base_url: &str) -> Result<PathBuf> {
let stamp = std::fs::read_to_string(dir.join(SOURCE_STAMP)).ok();
if stamp.as_deref().is_some_and(|s| s.trim() != base_url) {
- tracing::info!("开发者镜像下载地址变了,重新下载");
+ tracing::info!(
+ "{}",
+ ictl_l10n::log_tr!(
+ "开发者镜像下载地址变了,重新下载",
+ "The developer disk image download URL changed, downloading again"
+ )
+ );
invalidate(dir);
}
if cache_complete(dir) {
@@ -73,7 +79,7 @@ pub async fn ensure_cache(dir: &Path, base_url: &str) -> Result<PathBuf> {
continue;
}
let url = format!("{}/{name}", base_url.trim_end_matches('/'));
- tracing::info!("下载开发者镜像 {url}");
+ tracing::info!("{}", ictl_l10n::log_trf!("下载开发者镜像 {url}", "Downloading the developer disk image {url}"));
let resp = client
.get(&url)
.send()
diff --git a/crates/ictl-device/src/hid.rs b/crates/ictl-device/src/hid.rs
index 1e33d5f..bb5b300 100644
--- a/crates/ictl-device/src/hid.rs
+++ b/crates/ictl-device/src/hid.rs
@@ -225,7 +225,11 @@ impl Drop for HidSession {
fn drop(&mut self) {
if self.stream.is_some() {
tracing::warn!(
- "HID 会话没有 close() 就被丢掉,手机端的屏幕媒体流会一直挂着(不自动锁屏),需拔插或重开一次 HID 清掉"
+ "{}",
+ ictl_l10n::log_tr!(
+ "HID 会话没有 close() 就被丢掉,手机端的屏幕媒体流会一直挂着(不自动锁屏),需拔插或重开一次 HID 清掉",
+ "HID session dropped without close(): the phone keeps its screen media stream open (no auto-lock); replug or open HID once more to clear it"
+ )
);
}
}
diff --git a/crates/ictl-device/src/lib.rs b/crates/ictl-device/src/lib.rs
index 409254e..2a34dfc 100644
--- a/crates/ictl-device/src/lib.rs
+++ b/crates/ictl-device/src/lib.rs
@@ -329,7 +329,10 @@ impl Device {
match lockdown.get_value(Some(key), None).await {
Ok(v) => v.as_string().map(str::to_owned).unwrap_or_default(),
Err(e) => {
- tracing::warn!("读设备信息 {key} 失败:{e}");
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!("读设备信息 {key} 失败:{e}", "Reading device info {key} failed: {e}")
+ );
String::new()
}
}
diff --git a/crates/ictl-device/src/media.rs b/crates/ictl-device/src/media.rs
index 40af931..41a0b4c 100644
--- a/crates/ictl-device/src/media.rs
+++ b/crates/ictl-device/src/media.rs
@@ -124,6 +124,12 @@ async fn stop(client: &mut DisplayServiceClient<Box<dyn ReadWrite>>) {
match tokio::time::timeout(STEP, client.stop_media_stream()).await {
Ok(Ok(_)) => {}
Ok(Err(e)) => tracing::debug!("stop_media_stream: {e}"),
- Err(_) => tracing::warn!("停止屏幕媒体流超时,手机上可能还挂着屏幕共享会话"),
+ Err(_) => tracing::warn!(
+ "{}",
+ ictl_l10n::log_tr!(
+ "停止屏幕媒体流超时,手机上可能还挂着屏幕共享会话",
+ "Stopping the screen media stream timed out; a screen sharing session may still be open on the phone"
+ )
+ ),
}
}
diff --git a/crates/ictl-l10n/src/lib.rs b/crates/ictl-l10n/src/lib.rs
index f77e572..bc97a4f 100644
--- a/crates/ictl-l10n/src/lib.rs
+++ b/crates/ictl-l10n/src/lib.rs
@@ -11,7 +11,9 @@
//!
//! The client decides: the MCP server and the CLI send their language with every request, and the daemon
//! answers that request in it ([`scope`]). Requests from older clients carry no language and get Chinese.
-//! The daemon's own setting only applies to what it writes by itself (event log, notifications).
+//! The daemon's own setting applies to what it writes by itself, the event log, log lines and notifications,
+//! even while it handles a request in another language: write those with [`log_tr!`] / [`log_trf!`]
+//! (or inside [`in_own_lang`]), so the journal and the notifications stay in one language.
use std::cell::Cell;
use std::sync::atomic::{AtomicU8, Ordering};
@@ -76,6 +78,12 @@ pub fn lang() -> Lang {
if let Ok(l) = TASK_LANG.try_with(|l| *l) {
return l;
}
+ own_lang()
+}
+
+/// The process's own setting (`IPHONE_CONTROL_LANG`, decided on first use), ignoring a request's language
+/// ([`scope`]) and [`with_lang`]
+pub fn own_lang() -> Lang {
match LANG.load(Ordering::Relaxed) {
1 => Lang::Zh,
2 => Lang::En,
@@ -87,18 +95,29 @@ pub fn lang() -> Lang {
}
}
+/// Run `f` in the process's own language: for text the daemon writes by itself (event log, notifications)
+/// while it handles a request that may be in another language
+pub fn in_own_lang<T>(f: impl FnOnce() -> T) -> T {
+ with_lang(own_lang(), f)
+}
+
/// Override the language for this process
pub fn set(l: Lang) {
LANG.store(encode(l), Ordering::Relaxed);
}
/// Run `f` with the language set to `l` on this thread only (tests run in parallel and must not
-/// change each other's language)
+/// change each other's language). The previous value comes back even if `f` panics: blocking-pool threads
+/// are reused, and a leftover override would change the language of whatever runs there next
pub fn with_lang<T>(l: Lang, f: impl FnOnce() -> T) -> T {
- let prev = OVERRIDE.with(|o| o.replace(encode(l)));
- let r = f();
- OVERRIDE.with(|o| o.set(prev));
- r
+ struct Restore(u8);
+ impl Drop for Restore {
+ fn drop(&mut self) {
+ OVERRIDE.with(|o| o.set(self.0));
+ }
+ }
+ let _restore = Restore(OVERRIDE.with(|o| o.replace(encode(l))));
+ f()
}
pub fn is_en() -> bool {
@@ -131,6 +150,23 @@ macro_rules! trf {
};
}
+/// [`tr!`] for log lines and the event log: always the process's own language ([`own_lang`]), not the
+/// language of the request being handled
+#[macro_export]
+macro_rules! log_tr {
+ ($zh:literal, $en:literal $(,)?) => {
+ if $crate::own_lang() == $crate::Lang::En { $en } else { $zh }
+ };
+}
+
+/// [`trf!`] for log lines and the event log (see [`log_tr!`])
+#[macro_export]
+macro_rules! log_trf {
+ ($zh:literal, $en:literal $(, $arg:expr)* $(,)?) => {
+ if $crate::own_lang() == $crate::Lang::En { format!($en $(, $arg)*) } else { format!($zh $(, $arg)*) }
+ };
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -158,6 +194,28 @@ mod tests {
assert_eq!(inner, "en", "with_lang wins over scope");
}
+ #[test]
+ fn with_lang_restores_after_a_panic() {
+ let before = lang();
+ let other = if before == Lang::En { Lang::Zh } else { Lang::En };
+ let r = std::panic::catch_unwind(|| with_lang(other, || panic!("boom")));
+ assert!(r.is_err());
+ assert_eq!(lang(), before, "the override must not stay on the thread");
+ }
+
+ /// Log lines and the event log stay in the process's language while a request in another language is
+ /// being handled; tool results follow the request
+ #[tokio::test]
+ async fn log_texts_ignore_the_request_language() {
+ let own = own_lang();
+ let other = if own == Lang::En { Lang::Zh } else { Lang::En };
+ let (result, log) = scope(other, async { (tr!("中", "en"), log_tr!("中", "en")) }).await;
+ assert_eq!(result, if other == Lang::En { "en" } else { "中" });
+ assert_eq!(log, if own == Lang::En { "en" } else { "中" });
+ let log = scope(other, async { in_own_lang(|| tr!("中", "en")) }).await;
+ assert_eq!(log, if own == Lang::En { "en" } else { "中" });
+ }
+
#[test]
fn macros_follow_the_language() {
let n = 3;
diff --git a/crates/ictl-sign/src/lib.rs b/crates/ictl-sign/src/lib.rs
index aa81311..10900be 100644
--- a/crates/ictl-sign/src/lib.rs
+++ b/crates/ictl-sign/src/lib.rs
@@ -197,13 +197,20 @@ impl Session {
if let (Some(exe), Some(id)) = (b.executable(), b.identifier())
&& let Err(e) = prov.merge_entitlements(b.dir.join(exe), &id)
{
- tracing::warn!("合并 {} 的 entitlements 失败,只用描述文件里的:{e}", b.dir.display());
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "合并 {} 的 entitlements 失败,只用描述文件里的:{e}",
+ "Merging the entitlements of {} failed, using only those from the provisioning profile: {e}",
+ b.dir.display()
+ )
+ );
}
std::fs::write(b.dir.join("embedded.mobileprovision"), &prov.data)?;
let xml = String::from_utf8_lossy(&prov.entitlements_as_bytes()?).into_owned();
settings.set_entitlements_xml(SettingsScope::Main, xml)?;
}
- tracing::info!("签名 {}", b.dir.display());
+ tracing::info!("{}", ictl_l10n::log_trf!("签名 {}", "Signing {}", b.dir.display()));
UnifiedSigner::new(settings).sign_path_in_place(&b.dir)?;
}
if let Some(key) = &cert.key {
diff --git a/crates/ictl-unlock/src/lib.rs b/crates/ictl-unlock/src/lib.rs
index e284b9f..43dec73 100644
--- a/crates/ictl-unlock/src/lib.rs
+++ b/crates/ictl-unlock/src/lib.rs
@@ -130,7 +130,10 @@ pub async fn ensure_unlocked<T: Transport>(wda: &mut WdaClient<T>, cfg: &UnlockC
wda.set_idle_settings(IdleSettings::QUICK).await?;
let r = unlock(wda, cfg, code.as_bytes()).await;
if let Err(e) = wda.set_idle_settings(restore).await {
- tracing::warn!("恢复 WDA 等待设置失败:{e}");
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!("恢复 WDA 等待设置失败:{e}", "Restoring the WDA wait settings failed: {e}")
+ );
}
r
}
@@ -224,7 +227,13 @@ async fn unlock<T: Transport>(wda: &mut WdaClient<T>, cfg: &UnlockConfig, code:
let view = match woke {
Ok(v) => v,
Err(e @ WdaError::Remote { .. }) => {
- tracing::info!("唤醒/上滑失败,重来一轮:{e}");
+ tracing::info!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "唤醒/上滑失败,重来一轮:{e}",
+ "Wake/swipe up failed, trying another round: {e}"
+ )
+ );
continue;
}
Err(other) => return Err(other.into()),
@@ -290,7 +299,13 @@ async fn unlock<T: Transport>(wda: &mut WdaClient<T>, cfg: &UnlockConfig, code:
let verdict = enter_rest(wda, cfg, &pad, code).await;
let clear = || {
if let Err(e) = std::fs::remove_file(&cfg.disabled_flag) {
- tracing::warn!("撤掉停用标记失败,自动解锁保持停用:{e}");
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "撤掉停用标记失败,自动解锁保持停用:{e}",
+ "Removing the disabled flag failed, auto-unlock stays disabled: {e}"
+ )
+ );
}
};
match verdict {
@@ -341,7 +356,13 @@ async fn enter_rest<T: Transport>(
return Ok(Verdict::NotSubmitted(n));
}
// 归零、密码栏消失等:可能已经凑满提交了,按提交处理去确认
- tracing::warn!("第 {n} 位按后密码栏变成 {got} 位,可能已提交,确认结果");
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "第 {n} 位按后密码栏变成 {got} 位,可能已提交,确认结果",
+ "After digit {n} the passcode field shows {got} digits; it may have been submitted, checking the result"
+ )
+ );
last_pressed = false;
break;
}
diff --git a/crates/ictl-wda/src/client.rs b/crates/ictl-wda/src/client.rs
index 3bfaec7..34166ad 100644
--- a/crates/ictl-wda/src/client.rs
+++ b/crates/ictl-wda/src/client.rs
@@ -224,7 +224,13 @@ impl<T: Transport> WdaClient<T> {
Ok(match self.orientation().await {
Ok(o) => elements::View { screen: o.orient(base), orientation: Some(o) },
Err(e) => {
- tracing::debug!("读屏幕方向失败,按缓存的屏幕尺寸算:{e}");
+ tracing::debug!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "读屏幕方向失败,按缓存的屏幕尺寸算:{e}",
+ "Reading the screen orientation failed, using the cached screen size: {e}"
+ )
+ );
elements::View { screen: base, orientation: None }
}
})
@@ -278,7 +284,18 @@ impl<T: Transport> WdaClient<T> {
let (sheet, tree) = match self.cover_tree().await {
Ok(x) => x,
Err(e) => {
- tracing::debug!("核对锁屏界面失败,按{}处理:{e}", if strict { "锁着" } else { " WDA 的结果" });
+ tracing::debug!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "核对锁屏界面失败,按{}处理:{e}",
+ "Checking the lock screen failed, going by {}: {e}",
+ if strict {
+ ictl_l10n::tr!("锁着", "locked")
+ } else {
+ ictl_l10n::tr!(" WDA 的结果", "what WDA reported")
+ }
+ )
+ );
return Ok(LockCheck { locked: strict || wda_locked, uncertain: false, tree: None });
}
};
@@ -286,7 +303,13 @@ impl<T: Transport> WdaClient<T> {
(true, elements::CoverSheet::NotificationCenter) => (false, false),
(true, _) => (true, false),
(false, elements::CoverSheet::Locked) => {
- tracing::info!("WDA 报未锁屏,但屏幕上是锁屏界面(WDA 在锁屏时启动,状态未同步)");
+ tracing::info!(
+ "{}",
+ ictl_l10n::log_tr!(
+ "WDA 报未锁屏,但屏幕上是锁屏界面(WDA 在锁屏时启动,状态未同步)",
+ "WDA says unlocked, but the screen shows the lock screen (WDA started while locked and its state is stale)"
+ )
+ );
(true, false)
}
// 锁屏样式、却没有锁的标记:可能是通知中心,也可能是 Touch ID 机型熄屏、有通知时的锁屏
@@ -388,7 +411,13 @@ impl<T: Transport> WdaClient<T> {
pub async fn end_polling(&mut self) {
let b = self.idle_baseline.unwrap_or(IdleSettings::DEFAULT);
if let Err(e) = self.set_idle_settings(b).await {
- tracing::warn!("轮询后恢复 WDA 等待设置失败:{e}");
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "轮询后恢复 WDA 等待设置失败:{e}",
+ "Restoring the WDA wait settings after polling failed: {e}"
+ )
+ );
}
}
@@ -412,7 +441,13 @@ impl<T: Transport> WdaClient<T> {
self.set_idle_settings(during).await?;
let r = self.actions(steps).await;
if let Err(e) = self.set_idle_settings(baseline).await {
- tracing::warn!("手势后恢复 WDA 等待设置失败:{e}");
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "手势后恢复 WDA 等待设置失败:{e}",
+ "Restoring the WDA wait settings after the gesture failed: {e}"
+ )
+ );
}
r
}
diff --git a/crates/ictl-wda/src/elements.rs b/crates/ictl-wda/src/elements.rs
index 8a4c510..aac1e4c 100644
--- a/crates/ictl-wda/src/elements.rs
+++ b/crates/ictl-wda/src/elements.rs
@@ -124,7 +124,13 @@ impl Rotate {
Some(Orientation::LandscapeLeft) => Self::TopToLeft,
Some(Orientation::LandscapeRight) => Self::TopToRight,
o => {
- tracing::warn!("元素树是竖屏坐标而屏幕是横的,但没有状态栏、方向是 {o:?},坐标不换算");
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "元素树是竖屏坐标而屏幕是横的,但没有状态栏、方向是 {o:?},坐标不换算",
+ "The element tree uses portrait coordinates while the screen is landscape, but there is no status bar and the orientation is {o:?}; not converting coordinates"
+ )
+ );
Self::None
}
}
@@ -435,7 +441,14 @@ pub fn parse_tree(xml: &str, view: impl Into<View>) -> Tree {
Ok(Event::Eof) => break,
Err(e) => {
// 解析到一半出错:已解析的照常返回,但要留痕,否则「没找到元素」看起来像真结果
- tracing::warn!("元素树 XML 解析出错(位置 {}),只用了前面的部分:{e}", reader.buffer_position());
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "元素树 XML 解析出错(位置 {}),只用了前面的部分:{e}",
+ "Error parsing the element tree XML (at {}), only the part before it is used: {e}",
+ reader.buffer_position()
+ )
+ );
break;
}
Ok(_) => continue,
@@ -651,7 +664,13 @@ pub fn keypad(elements: &[Element]) -> Option<[(i64, i64); 10]> {
out[i] = k?;
}
if !keypad_layout_ok(&out) {
- tracing::warn!("锁屏数字键的位置不像电话键盘(坐标可能没换算对),不按:{out:?}");
+ tracing::warn!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "锁屏数字键的位置不像电话键盘(坐标可能没换算对),不按:{out:?}",
+ "The lock screen keypad doesn't look like a phone keypad (coordinates may be converted wrongly), not pressing: {out:?}"
+ )
+ );
return None;
}
Some(out)
diff --git a/crates/ictl-wda/src/http.rs b/crates/ictl-wda/src/http.rs
index dcc29c7..d293c78 100644
--- a/crates/ictl-wda/src/http.rs
+++ b/crates/ictl-wda/src/http.rs
@@ -114,8 +114,22 @@ impl Transport for DeviceTransport {
// 路径截掉查询串(/source 的排除属性很长)
let short = path.split('?').next().unwrap_or(path);
match &r {
- Ok((status, _)) => tracing::debug!("wda {method} {short} → {status}({:.2}s)", t0.elapsed().as_secs_f64()),
- Err(e) => tracing::debug!("wda {method} {short} 失败({:.2}s):{e}", t0.elapsed().as_secs_f64()),
+ Ok((status, _)) => tracing::debug!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "wda {method} {short} → {status}({:.2}s)",
+ "wda {method} {short} → {status} ({:.2}s)",
+ t0.elapsed().as_secs_f64()
+ )
+ ),
+ Err(e) => tracing::debug!(
+ "{}",
+ ictl_l10n::log_trf!(
+ "wda {method} {short} 失败({:.2}s):{e}",
+ "wda {method} {short} failed ({:.2}s): {e}",
+ t0.elapsed().as_secs_f64()
+ )
+ ),
}
r
}
diff --git a/crates/ictl-wda/src/runner.rs b/crates/ictl-wda/src/runner.rs
index d627748..87298ce 100644
--- a/crates/ictl-wda/src/runner.rs
+++ b/crates/ictl-wda/src/runner.rs
@@ -105,7 +105,7 @@ impl XCUITestListener for ErrorListener {
}
async fn did_begin_initializing_for_ui_testing(&mut self) -> std::result::Result<(), IdeviceError> {
- tracing::debug!("xctest: 开始初始化 UI 测试");
+ tracing::debug!("{}", ictl_l10n::log_tr!("xctest: 开始初始化 UI 测试", "xctest: initializing the UI test"));
Ok(())
}
@@ -120,7 +120,7 @@ impl XCUITestListener for ErrorListener {
}
async fn did_begin_executing_test_plan(&mut self) -> std::result::Result<(), IdeviceError> {
- tracing::debug!("xctest: 开始执行测试计划");
+ tracing::debug!("{}", ictl_l10n::log_tr!("xctest: 开始执行测试计划", "xctest: running the test plan"));
self.0.lock().unwrap().plan_started = true;
Ok(())
}
@@ -199,7 +199,13 @@ impl WdaRunner {
deadline = deadline.max(since + AUTOMATION_WAIT);
if !announced {
announced = true;
- tracing::info!("runner 在等手机上的「Enable UI Automation」密码");
+ tracing::info!(
+ "{}",
+ ictl_l10n::log_tr!(
+ "runner 在等手机上的「Enable UI Automation」密码",
+ "the runner is waiting for the “Enable UI Automation” passcode on the phone"
+ )
+ );
}
}
if runner.task.is_finished() {
@@ -215,8 +221,12 @@ impl WdaRunner {
if !plan_started && t0.elapsed() >= PLAN_START_FALLBACK && !fallback_logged {
fallback_logged = true;
tracing::info!(
- "{} 秒内没收到 runner 开始执行测试计划的回调,改为直接查 /status",
- PLAN_START_FALLBACK.as_secs()
+ "{}",
+ ictl_l10n::log_trf!(
+ "{} 秒内没收到 runner 开始执行测试计划的回调,改为直接查 /status",
+ "No callback that the runner started the test plan within {} seconds; querying /status directly",
+ PLAN_START_FALLBACK.as_secs()
+ )
);
}
if (plan_started || fallback_logged) && client.ready().await.unwrap_or(false) {
diff --git a/docs/decisions.md b/docs/decisions.md
index 0373224..a55e43a 100644
--- a/docs/decisions.md
+++ b/docs/decisions.md
@@ -73,7 +73,7 @@
## D12:界面文字可选英文,默认仍是中文
- **决定**:`IPHONE_CONTROL_LANG=en|zh` 选择人和 agent 看到的文字的语言(工具说明、工具结果、命令行输出、日志、通知);不设或认不出时是简体中文。每条文字在代码里原地写成中英一对(`ictl-l10n` 的 `tr!` / `trf!`),不另建翻译目录。从手机界面读到的文字(例如「滚动条」)不翻译。
-- **结果的语言由客户端决定**:MCP 和命令行在每个请求里带上自己的语言(`lang` 键),守护进程按它回答;不带 `lang` 的请求(旧版本客户端)照旧得到中文,因为它们按中文的固定开头认结果。守护进程自己的设置只管它主动写的文字(日志、通知)。容器部署里 MCP 和守护进程读同一个 `.env`,自然一致。
+- **结果的语言由客户端决定**:MCP 和命令行在每个请求里带上自己的语言(`lang` 键),守护进程按它回答;不带 `lang` 的请求(旧版本客户端)照旧得到中文,因为它们按中文的固定开头认结果。守护进程自己的设置管它主动写的文字(事件日志、日志行、通知),处理请求时写的也一样(`ictl-l10n` 的 `log_tr!` / `log_trf!`),所以日志和通知始终是同一种语言。上次重签的结果存成时间和成败,显示时再按看的人的语言拼句子。容器部署里 MCP 和守护进程读同一个 `.env`,自然一致。
- **客户端要据以行动的结果用字段表示**:文字结果带 `outcome`(`tapped_nothing`:按名字没点到;`alert_reported`:结果里已经报过系统弹窗),新版本 MCP 只看字段,不再从文字里认;没有 `outcome` 的响应来自旧版本守护进程,那时文字一定是中文,才按 `TAP_MISSED`、`ALERT_BLOCKING` 认。旧版本客户端不认识这个字段,会忽略它。
- **理由**:D10 承诺已有工具的默认返回不变,所以英文只能是可选项,不设就和以前完全一样。两种语言并排写在原处,改文字时另一种就在旁边,审查时也能逐条对照。
- **代价**:每条新文字都要写两种语言;取语言是一次原子读,开销可以忽略。
diff --git a/docs/tools.md b/docs/tools.md
index 5f90766..b193ac8 100644
--- a/docs/tools.md
+++ b/docs/tools.md
@@ -1,6 +1,6 @@
# MCP tools
-The MCP server (`iphone-control mcp`) exposes 17 tools. The tool descriptions the agent sees, and every result text, are in Simplified Chinese; this page is the English reference. The definitions live in [`crates/ictl-mcp/src/lib.rs`](../crates/ictl-mcp/src/lib.rs).
+The MCP server (`iphone-control mcp`) exposes 17 tools. The tool descriptions the agent sees, and every result text, are in Simplified Chinese by default, or in English with `IPHONE_CONTROL_LANG=en` (see [configuration](https://derrors.github.io/iphone-control/en/guide/configuration)); this page is the English reference. The definitions live in [`crates/ictl-mcp/src/lib.rs`](../crates/ictl-mcp/src/lib.rs).
Coordinates are in **points**, the same unit as the pixels of a full-screen `iphone_screenshot` (for example 430×932 on an iPhone 15 Pro Max), so an agent can read a position off a screenshot and tap it directly. Coordinates follow the current screen orientation: after a rotation the same spot has different coordinates, so take a new screenshot. Screen sizes differ per device (an iPad mini 5 is 768×1024 in portrait); don't assume 430×932.
diff --git a/website/en/guide/configuration.md b/website/en/guide/configuration.md
index 3df6f34..422f495 100644
--- a/website/en/guide/configuration.md
+++ b/website/en/guide/configuration.md
@@ -12,6 +12,7 @@ Everything is configured with environment variables, and all of them are optiona
| Variable | Default | Meaning |
|---|---|---|
| `HTTP_PROXY` / `HTTPS_PROXY` | direct | Proxy for Apple, anisette, Developer Disk Image and notification traffic |
+| `IPHONE_CONTROL_LANG` | `zh` | Language: `zh` or `en`. Applies to tool descriptions and results, CLI output, logs and notifications. The MCP server and the CLI each send their own setting and the daemon answers in it; logs and notifications follow the daemon's own setting. So for a source install also set it in the MCP client config (`iphone-control mcp-config` includes it) |
| `IPHONE_UDID` | automatic | Pin the device to control. Unset: the controlled device is kept until it disconnects, and you can switch with the `select` command or the `iphone_select_device` tool. When set, switching is refused |
| `RESIGN_MIN_DAYS` | `2` | Re-sign when fewer days than this remain |
| `RESIGN_CHECK_HOURS` | `6` | How often to check; it is also checked within a minute after the phone reconnects or you switch devices |
diff --git a/website/guide/configuration.md b/website/guide/configuration.md
index 2865459..db1882c 100644
--- a/website/guide/configuration.md
+++ b/website/guide/configuration.md
@@ -12,6 +12,7 @@
| 变量 | 默认 | 含义 |
|---|---|---|
| `HTTP_PROXY` / `HTTPS_PROXY` | 直连 | 访问苹果、anisette、开发者镜像、推送通知用的代理 |
+| `IPHONE_CONTROL_LANG` | `zh` | 界面语言:`zh` 或 `en`。工具说明和结果、命令行输出、日志、通知都按它。MCP 和命令行各自按自己的设置请求,守护进程按请求的语言回答;日志和通知按守护进程自己的设置。从源码运行时要在 MCP 配置里也设上(`iphone-control mcp-config` 会带上) |
| `IPHONE_UDID` | 自动选 | 固定控制哪台设备。不设时自动选:正在控制的那台一直用到它断开;运行中可以用 `select` 命令或 `iphone_select_device` 工具切换。设了就不能切换 |
| `RESIGN_MIN_DAYS` | `2` | 描述文件剩余不到几天时重签 |
| `RESIGN_CHECK_HOURS` | `6` | 每隔几小时检查一次;手机重新连上或切换设备后 1 分钟内也查一次 |