Skip to content

The only downloader you need. 下载器的集大成者。

fix(i18n): 同名文件对话框和订阅列表状态的文字能被翻译

XiaoYouChR971fe838c80a
diff --git a/app/view/components/bootstrap_list.py b/app/view/components/bootstrap_list.py
index 330192d7..06debda2 100644
--- a/app/view/components/bootstrap_list.py
+++ b/app/view/components/bootstrap_list.py
@@ -29,27 +29,23 @@ FAILURE_NOTICE_AGE = 7 * 86400
CARD_HEIGHT = 70
-def tr(text: str) -> str:
- return QCoreApplication.translate("BootstrapList", text)
-
-
def toAgoText(seconds: float) -> str:
if seconds < 60:
- return tr("刚刚")
+ return QCoreApplication.translate("BootstrapList", "刚刚")
if seconds < 3600:
- return tr("{0} 分钟前").format(int(seconds // 60))
+ return QCoreApplication.translate("BootstrapList", "{0} 分钟前").format(int(seconds // 60))
if seconds < 86400:
- return tr("{0} 小时前").format(int(seconds // 3600))
- return tr("{0} 天前").format(int(seconds // 86400))
+ return QCoreApplication.translate("BootstrapList", "{0} 小时前").format(int(seconds // 3600))
+ return QCoreApplication.translate("BootstrapList", "{0} 天前").format(int(seconds // 86400))
def toStatusText(status: SubscriptionStatus | None) -> str:
if status is None or status.count is None:
- return tr("更新失败") if status is not None and status.error else tr("未拉取")
- parts = [tr("{0} 条").format(status.count), tr("{0}更新").format(toAgoText(time.time() - status.updatedAt))]
+ return QCoreApplication.translate("BootstrapList", "更新失败") if status is not None and status.error else QCoreApplication.translate("BootstrapList", "未拉取")
+ parts = [QCoreApplication.translate("BootstrapList", "{0} 条").format(status.count), QCoreApplication.translate("BootstrapList", "{0}更新").format(toAgoText(time.time() - status.updatedAt))]
if status.error:
- parts.append(tr("更新失败"))
- return tr(",").join(parts)
+ parts.append(QCoreApplication.translate("BootstrapList", "更新失败"))
+ return QCoreApplication.translate("BootstrapList", ",").join(parts)
def isSubscriptionUrl(url: str) -> bool:
@@ -132,7 +128,7 @@ class BootstrapListCard(SettingCard):
def _onNetworkProbed(self, probed: tuple[str, dict]):
text, params = probed
- self._networkText = tr(text).format_map(params)
+ self._networkText = QCoreApplication.translate("BootstrapList", text).format_map(params)
self._refreshContent()
def _startRefresh(self):
diff --git a/app/view/dialogs/name_conflict.py b/app/view/dialogs/name_conflict.py
index 8c1febd4..3230664c 100644
--- a/app/view/dialogs/name_conflict.py
+++ b/app/view/dialogs/name_conflict.py
@@ -12,24 +12,20 @@ from app.services.name_conflict_queue import NameConflict, NameConflictQueue
from app.services.task_service import NameConflictChoice
-def tr(text: str) -> str:
- return QCoreApplication.translate("NameConflictDialog", text)
-
-
def toContentText(conflict: NameConflict) -> str:
modified = datetime.fromtimestamp(conflict.modifiedAt).strftime("%Y-%m-%d %H:%M")
if conflict.isFolder:
- existing = tr("现有文件夹:{0} 修改").format(modified)
+ existing = QCoreApplication.translate("NameConflictDialog", "现有文件夹:{0} 修改").format(modified)
else:
- existing = tr("现有文件:{0},{1} 修改").format(toReadableSize(conflict.existingSize), modified)
- newSize = toReadableSize(conflict.task.fileSize) if conflict.task.fileSize > 0 else tr("未知大小")
- return "\n".join([existing, tr("新文件:{0}").format(newSize), tr("覆盖时,旧文件会移到回收站。")])
+ existing = QCoreApplication.translate("NameConflictDialog", "现有文件:{0},{1} 修改").format(toReadableSize(conflict.existingSize), modified)
+ newSize = toReadableSize(conflict.task.fileSize) if conflict.task.fileSize > 0 else QCoreApplication.translate("NameConflictDialog", "未知大小")
+ return "\n".join([existing, QCoreApplication.translate("NameConflictDialog", "新文件:{0}").format(newSize), QCoreApplication.translate("NameConflictDialog", "覆盖时,旧文件会移到回收站。")])
class NameConflictDialog(Dialog):
def __init__(self, conflict: NameConflict, queue: NameConflictQueue):
- super().__init__(tr("下载目录中已有 {0}").format(conflict.takenPath.name), toContentText(conflict))
+ super().__init__(QCoreApplication.translate("NameConflictDialog", "下载目录中已有 {0}").format(conflict.takenPath.name), toContentText(conflict))
self._conflict = conflict
self._queue = queue
self._choice = NameConflictChoice.KEEP_BOTH
@@ -40,10 +36,10 @@ class NameConflictDialog(Dialog):
def _initWidget(self) -> None:
self.setTitleBarVisible(False)
- self.yesButton.setText(tr("保留两者"))
- self.cancelButton.setText(tr("取消"))
- self.overwriteButton = PushButton(tr("覆盖"), self.buttonGroup)
- self.restCheckBox = CheckBox(tr("对其余 {0} 个冲突执行相同操作").format(self._conflict.restCount), self)
+ self.yesButton.setText(QCoreApplication.translate("NameConflictDialog", "保留两者"))
+ self.cancelButton.setText(QCoreApplication.translate("NameConflictDialog", "取消"))
+ self.overwriteButton = PushButton(QCoreApplication.translate("NameConflictDialog", "覆盖"), self.buttonGroup)
+ self.restCheckBox = CheckBox(QCoreApplication.translate("NameConflictDialog", "对其余 {0} 个冲突执行相同操作").format(self._conflict.restCount), self)
self.restCheckBox.setVisible(self._conflict.restCount > 0)
def _initLayout(self) -> None:
diff --git a/app/view/shell/mac_status_item.py b/app/view/shell/mac_status_item.py
index 5d62ee8e..c37cd321 100644
--- a/app/view/shell/mac_status_item.py
+++ b/app/view/shell/mac_status_item.py
@@ -19,10 +19,6 @@ from app.format import toReadableSize
from app.signal_bus import signalBus
-def tr(text: str) -> str:
- return QCoreApplication.translate("SystemTrayIcon", text)
-
-
class MenuTarget(NSObject):
owner = None
@@ -79,10 +75,10 @@ class MacStatusItem:
menu.setAutoenablesItems_(False)
menu.setDelegate_(self._target)
for title, selector, key, symbol in (
- (tr("仪表盘"), "showDashboard:", "", "gauge.open.with.lines.needle.33percent"),
- (tr("全部开始"), "startAll:", "", "play.fill"),
- (tr("全部暂停"), "pauseAll:", "", "pause.fill"),
- (tr("退出程序"), "quitApp:", "q", "power"),
+ (QCoreApplication.translate("SystemTrayIcon", "仪表盘"), "showDashboard:", "", "gauge.open.with.lines.needle.33percent"),
+ (QCoreApplication.translate("SystemTrayIcon", "全部开始"), "startAll:", "", "play.fill"),
+ (QCoreApplication.translate("SystemTrayIcon", "全部暂停"), "pauseAll:", "", "pause.fill"),
+ (QCoreApplication.translate("SystemTrayIcon", "退出程序"), "quitApp:", "q", "power"),
):
item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(title, selector, key)
item.setTarget_(self._target)