from __future__ import annotations MESSAGES: dict[str, dict[str, str]] = { "zh": { "app.title": "干扰数据处理", "tab.overview": "概览", "tab.runs": "运行记录", "tab.settings": "设置", "header.scheduleOn": "定时运行中", "header.scheduleOff": "定时已暂停", "header.theme": "切换日夜间", "header.language": "English", "header.languageShort": "EN", "card.schedule": "定时任务", "card.current": "当前状态", "card.lastRun": "最近结果", "card.latestData": "最新入库", "schedule.every": "每 {n} 分钟", "schedule.cron": "Cron {expr}", "schedule.paused": "已暂停", "schedule.next": "下次运行 {time}", "schedule.setup": "请先完成设置", "current.idle": "空闲", "current.running": "运行中", "current.elapsed": "#{id} · {trigger} · 已运行 {elapsed}", "current.lastFinished": "上次结束于 {time}", "empty.dash": "—", "empty.never": "暂无记录", "latest.rows": "{rows} 行 · {time} 写入", "today.summary": "今日运行 {total} 次 · 入库 {processed} · 无新数据 {idle} · 异常 {problem}", "action.run": "立即运行", "action.dryRun": "试运行", "action.dryRunHint": "处理最新一组文件并保存在本地,不写数据库和历史目录", "action.pause": "暂停定时", "action.resume": "启用定时", "action.cancel": "停止运行", "action.refresh": "刷新", "action.save": "保存设置", "action.test": "测试连接", "action.copy": "复制日志", "action.close": "关闭", "action.viewAll": "查看全部", "log.title": "运行日志", "log.empty": "暂无日志输出", "log.copied": "已复制", "recent.title": "最近运行", "recent.empty": "还没有运行记录", "status.running": "运行中", "status.processed": "已入库", "status.history_repaired": "已补传历史", "status.skipped": "无新数据", "status.waiting": "等待数据", "status.failed": "失败", "status.timeout": "超时", "status.cancelled": "已停止", "status.interrupted": "已中断", "status.dryRunDone": "试运行完成", "trigger.schedule": "定时", "trigger.manual": "手动", "trigger.dryRun": "试运行", "detail.missing": "缺少 {count} 类:{sources}", "detail.noFiles": "未找到源文件", "detail.upToDate": "数据库已是 {time}", "detail.timeout": "超过 {n} 分钟未完成", "detail.dryRunOutput": "结果保存在本地", "runs.filter.all": "全部", "runs.filter.processed": "已入库", "runs.filter.idle": "无新数据", "runs.filter.problem": "异常", "runs.col.id": "编号", "runs.col.started": "开始时间", "runs.col.trigger": "触发", "runs.col.status": "状态", "runs.col.target": "数据时间", "runs.col.rows": "汇总行数", "runs.col.duration": "耗时", "runs.col.detail": "说明", "runs.total": "共 {n} 条", "runs.empty": "没有符合条件的记录", "dialog.title": "运行 #{id}", "dialog.started": "开始", "dialog.finished": "结束", "dialog.duration": "耗时", "dialog.target": "数据时间", "dialog.rows": "汇总行数", "section.schedule": "定时运行", "section.metrix": "Metrix 接口", "section.source": "文件来源", "section.history": "历史归档", "section.database": "数据库", "section.retention": "保留策略", "field.schedule_enabled": "启用定时", "field.schedule_mode": "运行方式", "field.interval_minutes": "间隔(分钟)", "field.cron_expression": "Cron 表达式", "field.cron_hint": "分 时 日 月 周,例如 */15 * * * *", "field.timeout_minutes": "单次超时(分钟)", "field.metrix_url": "接口地址", "field.metrix_token": "API 令牌", "field.storage_mode": "访问方式", "field.metrix_storage_id": "存储连接 ID", "field.remote_host": "主机", "field.remote_port": "端口", "field.remote_username": "用户名", "field.remote_password": "密码", "field.ftp_encoding": "文件名编码", "field.ftp_passive": "被动模式", "field.source_root": "源数据目录", "field.lookback_days": "回看天数", "field.cell_data_directories": "小区信息目录", "field.cell_data_hint": "每行一个目录", "field.history_enabled": "上传历史 CSV", "field.history_root": "历史目录", "field.database_mode": "写入方式", "field.metrix_database_id": "数据库连接 ID", "field.mysql_host": "主机", "field.mysql_port": "端口", "field.mysql_username": "用户名", "field.mysql_password": "密码", "field.database_name": "库名", "field.table_name": "表名", "field.keep_outputs": "本地结果保留份数", "field.keep_runs": "运行记录保留条数", "option.interval": "固定间隔", "option.cron": "Cron 表达式", "option.storageMetrix": "Metrix 存储", "option.databaseMetrix": "Metrix 数据库连接", "option.mysql": "MySQL 直连", "secret.saved": "已保存,留空则不修改", "secret.empty": "未设置", "check.storage": "文件来源", "check.database": "数据库", "check.storageOk": "找到 {count} 个日期目录,最新 {latest}", "check.databaseOk": "连接正常,最新数据 {latest}", "check.running": "正在测试连接…", "msg.saved": "设置已保存", "msg.started": "已开始运行", "msg.busy": "已有任务在运行", "msg.cancelled": "已发送停止指令", "msg.scheduleOn": "定时已启用", "msg.scheduleOff": "定时已暂停", "error.required": "请填写“{field}”", "error.range": "“{field}”应在 {min} 到 {max} 之间", "error.invalidChoice": "“{field}”取值无效", "error.invalidCron": "Cron 表达式无效", "error.invalidUrl": "接口地址需以 http:// 或 https:// 开头", "error.absolutePath": "“{field}”需要以 / 开头", "error.invalidIdentifier": "“{field}”只能包含字母、数字和下划线", "forbidden.title": "无权访问", "forbidden.body": "只有应用管理员可以打开管理界面。", }, "en": { "app.title": "Interference ETL", "tab.overview": "Overview", "tab.runs": "Runs", "tab.settings": "Settings", "header.scheduleOn": "Schedule on", "header.scheduleOff": "Schedule paused", "header.theme": "Toggle theme", "header.language": "中文", "header.languageShort": "中", "card.schedule": "Schedule", "card.current": "Current", "card.lastRun": "Last result", "card.latestData": "Latest data", "schedule.every": "Every {n} min", "schedule.cron": "Cron {expr}", "schedule.paused": "Paused", "schedule.next": "Next run {time}", "schedule.setup": "Settings required", "current.idle": "Idle", "current.running": "Running", "current.elapsed": "#{id} · {trigger} · {elapsed} elapsed", "current.lastFinished": "Last finished {time}", "empty.dash": "—", "empty.never": "No runs yet", "latest.rows": "{rows} rows · written {time}", "today.summary": "Today: {total} runs · {processed} processed · {idle} no new data · {problem} problems", "action.run": "Run now", "action.dryRun": "Dry run", "action.dryRunHint": "Process the latest file group locally without writing the database or history", "action.pause": "Pause schedule", "action.resume": "Enable schedule", "action.cancel": "Stop run", "action.refresh": "Refresh", "action.save": "Save settings", "action.test": "Test connections", "action.copy": "Copy log", "action.close": "Close", "action.viewAll": "View all", "log.title": "Run log", "log.empty": "No log output", "log.copied": "Copied", "recent.title": "Recent runs", "recent.empty": "No runs yet", "status.running": "Running", "status.processed": "Processed", "status.history_repaired": "History repaired", "status.skipped": "No new data", "status.waiting": "Waiting for data", "status.failed": "Failed", "status.timeout": "Timed out", "status.cancelled": "Stopped", "status.interrupted": "Interrupted", "status.dryRunDone": "Dry run done", "trigger.schedule": "Scheduled", "trigger.manual": "Manual", "trigger.dryRun": "Dry run", "detail.missing": "Missing {count}: {sources}", "detail.noFiles": "No source files found", "detail.upToDate": "Database already at {time}", "detail.timeout": "Not finished within {n} min", "detail.dryRunOutput": "Result kept locally", "runs.filter.all": "All", "runs.filter.processed": "Processed", "runs.filter.idle": "No new data", "runs.filter.problem": "Problems", "runs.col.id": "ID", "runs.col.started": "Started", "runs.col.trigger": "Trigger", "runs.col.status": "Status", "runs.col.target": "Data time", "runs.col.rows": "Rows", "runs.col.duration": "Duration", "runs.col.detail": "Detail", "runs.total": "{n} runs", "runs.empty": "No matching runs", "dialog.title": "Run #{id}", "dialog.started": "Started", "dialog.finished": "Finished", "dialog.duration": "Duration", "dialog.target": "Data time", "dialog.rows": "Rows", "section.schedule": "Schedule", "section.metrix": "Metrix API", "section.source": "File source", "section.history": "History archive", "section.database": "Database", "section.retention": "Retention", "field.schedule_enabled": "Enabled", "field.schedule_mode": "Mode", "field.interval_minutes": "Interval (minutes)", "field.cron_expression": "Cron expression", "field.cron_hint": "minute hour day month weekday, e.g. */15 * * * *", "field.timeout_minutes": "Timeout (minutes)", "field.metrix_url": "Base URL", "field.metrix_token": "API token", "field.storage_mode": "Access", "field.metrix_storage_id": "Storage ID", "field.remote_host": "Host", "field.remote_port": "Port", "field.remote_username": "Username", "field.remote_password": "Password", "field.ftp_encoding": "Filename encoding", "field.ftp_passive": "Passive mode", "field.source_root": "Source directory", "field.lookback_days": "Lookback days", "field.cell_data_directories": "Cell data directories", "field.cell_data_hint": "One directory per line", "field.history_enabled": "Upload history CSV", "field.history_root": "History directory", "field.database_mode": "Access", "field.metrix_database_id": "Connection ID", "field.mysql_host": "Host", "field.mysql_port": "Port", "field.mysql_username": "Username", "field.mysql_password": "Password", "field.database_name": "Database", "field.table_name": "Table", "field.keep_outputs": "Local results kept", "field.keep_runs": "Runs kept", "option.interval": "Interval", "option.cron": "Cron", "option.storageMetrix": "Metrix storage", "option.databaseMetrix": "Metrix connection", "option.mysql": "Direct MySQL", "secret.saved": "Saved; leave blank to keep", "secret.empty": "Not set", "check.storage": "File source", "check.database": "Database", "check.storageOk": "{count} date folders, latest {latest}", "check.databaseOk": "Connected, latest data {latest}", "check.running": "Testing connections…", "msg.saved": "Settings saved", "msg.started": "Run started", "msg.busy": "A run is already in progress", "msg.cancelled": "Stop requested", "msg.scheduleOn": "Schedule enabled", "msg.scheduleOff": "Schedule paused", "error.required": "{field} is required", "error.range": "{field} must be between {min} and {max}", "error.invalidChoice": "Invalid {field}", "error.invalidCron": "Invalid cron expression", "error.invalidUrl": "Base URL must start with http:// or https://", "error.absolutePath": "{field} must start with /", "error.invalidIdentifier": "{field} may only contain letters, digits and underscores", "forbidden.title": "Access denied", "forbidden.body": "Only app administrators can open this page.", }, } class Translator: def __init__(self, lang: str) -> None: self.lang = lang if lang in MESSAGES else "zh" def __call__(self, key: str, **params: object) -> str: text = MESSAGES[self.lang].get(key) or MESSAGES["zh"].get(key) or key return text.format(**params) if params else text