diff --git a/src/main.cpp b/src/main.cpp index 390f628f..70cb5d3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -153,19 +153,29 @@ int main(int argc, char *argv[]) qDebug() << "openSSL" << QSslSocket::sslLibraryBuildVersionString() << QSslSocket::sslLibraryVersionNumber(); - // Load missing translation for Qt. + // Load missing translation for Qt (QTextEdit/QPlainTextEdit/QTextBrowser). QTranslator qtTranslator1; if (qtTranslator1.load("widgets_" + locale, ":/translations")) { app.installTranslator(&qtTranslator1); } - // Load translation for Qt. QTranslator qtTranslator2; - if (!qtTranslator2.load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { - qtTranslator2.load("qt_" + locale, "translations"); + if (qtTranslator2.load("qdialogbuttonbox_" + locale, ":/translations")) { + app.installTranslator(&qtTranslator2); } - app.installTranslator(&qtTranslator2); + QTranslator qtTranslator3; + if (qtTranslator3.load("qwebengine_" + locale, ":/translations")) { + app.installTranslator(&qtTranslator3); + } + + // Load translation for Qt. + QTranslator qtTranslator; + if (!qtTranslator.load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { + qtTranslator.load("qt_" + locale, "translations"); + } + + app.installTranslator(&qtTranslator); // Load translation for vnote. QTranslator translator; diff --git a/src/translations/qdialogbuttonbox_zh_CN.qm b/src/translations/qdialogbuttonbox_zh_CN.qm new file mode 100644 index 00000000..43ffbeee Binary files /dev/null and b/src/translations/qdialogbuttonbox_zh_CN.qm differ diff --git a/src/translations/qdialogbuttonbox_zh_CN.ts b/src/translations/qdialogbuttonbox_zh_CN.ts new file mode 100644 index 00000000..bb248a85 --- /dev/null +++ b/src/translations/qdialogbuttonbox_zh_CN.ts @@ -0,0 +1,79 @@ + + + + + QPlatformTheme + + OK + 确定 + + + Save + 保存 + + + Save All + 全部保存 + + + Open + 打开 + + + &Yes + 是 (&Y) + + + Yes to &All + 全部选择是 (&A) + + + &No + 否 (&N) + + + N&o to All + 全部选择否 (&O) + + + Abort + 终止 + + + Retry + 重试 + + + Ignore + 忽略 + + + Close + 关闭 + + + Cancel + 取消 + + + Discard + 放弃 + + + Help + 帮助 + + + Apply + 应用 + + + Reset + 重置 + + + Restore Defaults + 恢复默认 + + + diff --git a/src/translations/qwebengine_zh_CN.qm b/src/translations/qwebengine_zh_CN.qm new file mode 100644 index 00000000..6efc3afa Binary files /dev/null and b/src/translations/qwebengine_zh_CN.qm differ diff --git a/src/translations/qwebengine_zh_CN.ts b/src/translations/qwebengine_zh_CN.ts new file mode 100644 index 00000000..3770fb5b --- /dev/null +++ b/src/translations/qwebengine_zh_CN.ts @@ -0,0 +1,159 @@ + + + + + QWebEnginePage + + Back + 后退 + + + Forward + 前进 + + + Stop + 停止 + + + Reload + 重新加载 + + + Reload and Bypass Cache + 忽略缓存重新加载 + + + Cut + 剪切 + + + Copy + 复制 + + + Paste + 粘贴 + + + Undo + 撤销 + + + Redo + 恢复 + + + Select All + 选择全部 + + + Paste and Match Style + 粘贴并匹配样式 + + + Open Link in This Window + 在当前窗口打开链接 + + + Open Link in New Window + 在新窗口打开链接 + + + Open Link in New Tab + 在新标签页打开链接 + + + Open Link in New Background Tab + 在后台新标签页打开链接 + + + Copy Link URL + 复制链接地址 + + + Save Link + 保存链接 + + + Copy Image + 复制图片 + + + Copy Image URL + 复制图片地址 + + + Save Image + 保存图片 + + + Copy Media URL + 复制媒体地址 + + + Toggle Media Controls + 切换媒体控件 + + + Toggle Looping + 切换循环 + + + Toggle Play/Pause + 切换播放/暂停 + + + Toggle Mute + 切换静音 + + + Save Media + 保存媒体 + + + Inspect Element + 查看元素 + + + Exit Full Screen Mode + 退出全屏模式 + + + Close Page + 关闭页面 + + + Unselect + 取消选择 + + + Save &Page + 保存页面 (&P) + + + Are you sure you want to leave this page? + 确认离开本页面? + + + Follow Link + 打开链接 + + + &Back + 后退 (&B) + + + &Forward + 前进 (&F) + + + &Reload + 重新加载 (&R) + + + Select folder to upload + 选择文件夹上传 + + + diff --git a/src/vnote.qrc b/src/vnote.qrc index 07e09716..825115ee 100644 --- a/src/vnote.qrc +++ b/src/vnote.qrc @@ -231,5 +231,7 @@ resources/docs/tips_external_program_en.md resources/docs/tips_external_program_zh.md translations/widgets_zh_CN.qm + translations/qdialogbuttonbox_zh_CN.qm + translations/qwebengine_zh_CN.qm diff --git a/src/vwebview.cpp b/src/vwebview.cpp index ed1a6098..b0c80ba0 100644 --- a/src/vwebview.cpp +++ b/src/vwebview.cpp @@ -40,7 +40,7 @@ void VWebView::contextMenuEvent(QContextMenuEvent *p_event) // and the URL as URLs. If the URL contains Chinese, OneNote or Word could not // recognize it. // We need to change it to only-space-encoded text. - QAction *copyImageUrlAct = getPageAction(actions, QWebEnginePage::CopyImageUrlToClipboard); + QAction *copyImageUrlAct = pageAction(QWebEnginePage::CopyImageUrlToClipboard); if (actions.contains(copyImageUrlAct)) { connect(copyImageUrlAct, &QAction::triggered, this, &VWebView::handleCopyImageUrlAction); @@ -69,8 +69,8 @@ void VWebView::contextMenuEvent(QContextMenuEvent *p_event) // the fully-encoded URL to fetch the image while Windows seems to not // recognize it. #if defined(Q_OS_WIN) - QAction *defaultCopyImageAct = getPageAction(actions, QWebEnginePage::CopyImageToClipboard); - if (defaultCopyImageAct && actions.contains(defaultCopyImageAct)) { + QAction *defaultCopyImageAct = pageAction(QWebEnginePage::CopyImageToClipboard); + if (actions.contains(defaultCopyImageAct)) { QAction *copyImageAct = new QAction(defaultCopyImageAct->text(), menu); copyImageAct->setToolTip(defaultCopyImageAct->toolTip()); connect(copyImageAct, &QAction::triggered, @@ -164,24 +164,27 @@ void VWebView::hideUnusedActions(QMenu *p_menu) QList unusedActions; - // Back. - QAction *act = getPageAction(actions, QWebEnginePage::Back); - unusedActions.append(act); + // QWebEnginePage uses different actions of Back/Forward/Reload. + // [Woboq](https://code.woboq.org/qt5/qtwebengine/src/webenginewidgets/api/qwebenginepage.cpp.html#1652) + // We tell these three actions by name. + static const QStringList actionNames({QWebEnginePage::tr("&Back"), QWebEnginePage::tr("&Forward"), QWebEnginePage::tr("&Reload")}); - // Forward. - act = getPageAction(actions, QWebEnginePage::Forward); - unusedActions.append(act); - - // Reload. - act = getPageAction(actions, QWebEnginePage::Reload); - unusedActions.append(act); + for (auto it : actions) { + if (actionNames.contains(it->text())) { + unusedActions.append(it); + } + } // ViewSource. - act = getPageAction(actions, QWebEnginePage::ViewSource); + QAction *act = pageAction(QWebEnginePage::ViewSource); unusedActions.append(act); // DownloadImageToDisk. - act = getPageAction(actions, QWebEnginePage::DownloadImageToDisk); + act = pageAction(QWebEnginePage::DownloadImageToDisk); + unusedActions.append(act); + + // DownloadLinkToDisk. + act = pageAction(QWebEnginePage::DownloadLinkToDisk); unusedActions.append(act); for (auto it : unusedActions) { @@ -226,20 +229,3 @@ void VWebView::handleCopyAction() qDebug() << "clipboard copy Html altered" << html; } } - -QAction *VWebView::getPageAction(const QList &p_actions, - QWebEnginePage::WebAction p_webAction) -{ - QAction *act = pageAction(p_webAction); - if (act && !p_actions.contains(act)) { - QString text = act->text(); - for (auto it : p_actions) { - if (it->text().endsWith(text)) { - act = it; - break; - } - } - } - - return act; -} diff --git a/src/vwebview.h b/src/vwebview.h index 269e5601..22d06a6f 100644 --- a/src/vwebview.h +++ b/src/vwebview.h @@ -33,10 +33,6 @@ private slots: private: void hideUnusedActions(QMenu *p_menu); - // pageAction() may not return exactly the action in use. - QAction *getPageAction(const QList &p_actions, - QWebEnginePage::WebAction p_webAction); - VFile *m_file; // Whether this view has hooked the Copy Image Url action.