Skip to content

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

fix(i18n): 通知文本改中文 source,修复 lupdate 解析错位

XiaoYouChRd9ea0afc086b
diff --git a/app/platform/android_keepalive.py b/app/platform/android_keepalive.py
index a9f3522d..e4ff8ae8 100644
--- a/app/platform/android_keepalive.py
+++ b/app/platform/android_keepalive.py
@@ -2,8 +2,6 @@ from PySide6.QtCore import QCoreApplication
from app.platform.android_notification import notify
-tr = QCoreApplication.translate
-
REASON_DOWNLOAD = "download"
REASON_BROWSER = "browser"
@@ -61,8 +59,9 @@ class BackgroundKeepAlive:
self._startService(statusMessage)
self._running = True
elif statusMessage != self._statusMessage:
- notify(KEEPALIVE_CHANNEL, tr("KeepAlive", "Background task"), KEEPALIVE_NOTIF_ID,
- "Ghost Downloader", statusMessage, ongoing=True, lowImportance=True)
+ notify(KEEPALIVE_CHANNEL, QCoreApplication.translate("KeepAlive", "后台任务"),
+ KEEPALIVE_NOTIF_ID, "Ghost Downloader", statusMessage,
+ ongoing=True, lowImportance=True)
self._statusMessage = statusMessage
elif self._running:
self._stopService()
@@ -74,8 +73,8 @@ class BackgroundKeepAlive:
from app.format import toReadableSize
return f"{toReadableSize(self._speed)}/s"
if REASON_DOWNLOAD in self._activeReasons:
- return tr("KeepAlive", "Downloading")
- return tr("KeepAlive", "Browser extension connected")
+ return QCoreApplication.translate("KeepAlive", "下载中")
+ return QCoreApplication.translate("KeepAlive", "浏览器扩展已连接")
def _startService(self, statusMessage: str) -> None:
from jnius import autoclass
diff --git a/app/platform/android_notification.py b/app/platform/android_notification.py
index 072147cb..bea58d1c 100644
--- a/app/platform/android_notification.py
+++ b/app/platform/android_notification.py
@@ -7,8 +7,6 @@ from PySide6.QtCore import QCoreApplication
if TYPE_CHECKING:
from app.models.task import Task
-tr = QCoreApplication.translate
-
DOWNLOAD_CHANNEL = "gd3_downloads"
@@ -40,9 +38,9 @@ def notify(channelId: str, channelName: str, notificationId: int,
def notifyTaskCompleted(task: Task) -> None:
- notify(DOWNLOAD_CHANNEL, tr("Notifications", "Downloads"),
+ notify(DOWNLOAD_CHANNEL, QCoreApplication.translate("Notifications", "下载"),
hash(task.taskId) & 0x7FFFFFFF,
- tr("Notifications", "Download completed"), task.name,
+ QCoreApplication.translate("Notifications", "下载完成"), task.name,
ongoing=False, lowImportance=False)
@@ -51,10 +49,10 @@ DISK_SPACE_NOTIFICATION_ID = 0x6764_0003
def notifyDiskSpaceInsufficient(free: int, needed: int) -> None:
from app.format import toReadableSize
- notify(DOWNLOAD_CHANNEL, tr("Notifications", "Downloads"),
+ notify(DOWNLOAD_CHANNEL, QCoreApplication.translate("Notifications", "下载"),
DISK_SPACE_NOTIFICATION_ID,
- tr("Notifications", "Disk space insufficient"),
- tr("Notifications", "Remaining {0}, need {1}, task not auto-started").format(
+ QCoreApplication.translate("Notifications", "磁盘空间不足"),
+ QCoreApplication.translate("Notifications", "剩余 {0},需要 {1},任务未自动开始").format(
toReadableSize(free), toReadableSize(needed)),
ongoing=False, lowImportance=False)
@@ -67,20 +65,20 @@ def notifyBrowserTaskAdded(tasks: list[Task]) -> None:
if not tasks:
return
count = len(tasks)
- title = tr("Notifications", "Browser push") if count == 1 \
- else tr("Notifications", "Browser push ({count})").format(count=count)
+ title = QCoreApplication.translate("Notifications", "浏览器推送") if count == 1 \
+ else QCoreApplication.translate("Notifications", "浏览器推送({count})").format(count=count)
text = tasks[0].name if count == 1 else "、".join(t.name for t in tasks[:3])
if count > 3:
- text += tr("Notifications", " and {count} more").format(count=count)
- notify(DOWNLOAD_CHANNEL, tr("Notifications", "Downloads"),
+ text += QCoreApplication.translate("Notifications", "等 {count} 个").format(count=count)
+ notify(DOWNLOAD_CHANNEL, QCoreApplication.translate("Notifications", "下载"),
BROWSER_PUSH_NOTIFICATION_ID,
title, text, ongoing=False, lowImportance=False)
def notifyBrowserPaired(peerAddress: str) -> None:
- notify(DOWNLOAD_CHANNEL, tr("Notifications", "Downloads"),
+ notify(DOWNLOAD_CHANNEL, QCoreApplication.translate("Notifications", "下载"),
BROWSER_PAIR_NOTIFICATION_ID,
- tr("Notifications", "Browser extension connected"), peerAddress,
+ QCoreApplication.translate("Notifications", "浏览器扩展已连接"), peerAddress,
ongoing=False, lowImportance=True)
diff --git a/app/platform/desktop_notification.py b/app/platform/desktop_notification.py
index 2cdbc875..15ea7456 100644
--- a/app/platform/desktop_notification.py
+++ b/app/platform/desktop_notification.py
@@ -5,8 +5,6 @@ from typing import TYPE_CHECKING
from PySide6.QtCore import QCoreApplication, QFileInfo, QStandardPaths, Qt
from PySide6.QtWidgets import QFileIconProvider
-
-tr = QCoreApplication.translate
from loguru import logger
from app.platform.desktop import openFile, revealInFolder
@@ -39,8 +37,8 @@ def notifyDiskSpaceInsufficient(free: int, needed: int) -> None:
from app.format import toReadableSize
from app.services.coroutine_runner import coroutineRunner
coroutineRunner.submit(notifier.send(
- title=tr("Notifications", "Disk space insufficient"),
- message=tr("Notifications", "Remaining {0}, need {1}, task not auto-started").format(
+ title=QCoreApplication.translate("Notifications", "磁盘空间不足"),
+ message=QCoreApplication.translate("Notifications", "剩余 {0},需要 {1},任务未自动开始").format(
toReadableSize(free), toReadableSize(needed)),
))
@@ -70,11 +68,11 @@ def notifyTaskCompleted(task: Task) -> None:
from app.services.coroutine_runner import coroutineRunner
coroutineRunner.submit(notifier.send(
- title=tr("Notifications", "Download completed"),
+ title=QCoreApplication.translate("Notifications", "下载完成"),
message=task.name,
buttons=[
- Button(title=tr("Notifications", "Open file"), on_pressed=lambda: openFile(outputPath)),
- Button(title=tr("Notifications", "Open folder"), on_pressed=lambda: revealInFolder(outputPath)),
+ Button(title=QCoreApplication.translate("Notifications", "打开文件"), on_pressed=lambda: openFile(outputPath)),
+ Button(title=QCoreApplication.translate("Notifications", "打开文件夹"), on_pressed=lambda: revealInFolder(outputPath)),
],
on_clicked=lambda: openFile(outputPath),
icon=Icon(path=iconPath) if iconPath.exists() else None,