From cd2ce746feabc9817eae0af0118aea1443c00bac Mon Sep 17 00:00:00 2001 From: LiaoCheng Date: Mon, 30 Jan 2023 14:14:34 +0800 Subject: [PATCH] 1 Add Chinese Simplified translations 2 MainWindow.cpp: Show and log the file path when open error --- .gitignore | 1 + AboutDlg.ui | 4 +- EncodingConverter.pro | 2 + MainWindow.cpp | 8 +- MainWindow.ui | 2 +- Res/res.qrc | 8 +- Res/translations/zh_CN.ts | 215 ++++++++++++++++++++++++++++++++++++++ SettingDlg.cpp | 2 +- main.cpp | 16 +-- 9 files changed, 240 insertions(+), 18 deletions(-) create mode 100644 Res/translations/zh_CN.ts diff --git a/.gitignore b/.gitignore index f594cd3..05d6dde 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Add by me: bin/* +*.qm # following are get from gitHub: diff --git a/AboutDlg.ui b/AboutDlg.ui index 35ae8f0..4154023 100644 --- a/AboutDlg.ui +++ b/AboutDlg.ui @@ -17,7 +17,7 @@ - Email: LiaoChengO@qq.com + Email: LiaoChengO@qq.com https://github.com/CharlesLiaoO/EncodingConverter Build with Qt/C++ @@ -31,7 +31,7 @@ Build with Qt/C++ - About Qt + About Qt diff --git a/EncodingConverter.pro b/EncodingConverter.pro index f1d7747..e83d209 100644 --- a/EncodingConverter.pro +++ b/EncodingConverter.pro @@ -36,3 +36,5 @@ FORMS += \ RESOURCES += \ Res/res.qrc + +TRANSLATIONS += Res/translations/zh_CN.ts diff --git a/MainWindow.cpp b/MainWindow.cpp index 7cb4c81..c6e0bd8 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -235,11 +235,15 @@ void MainWindow::on_pushButton_Start_clicked() QFile fileSrc(fiFileSrc.absoluteFilePath()); QFile fileDest(fileSrc.fileName() + sTmpSuffixName); if (!fileSrc.open(QFile::ReadOnly/* | QFile::Text*/)) { // Text mode has no effect in read mode - QMessageBox::critical(this, "", tr("Error when open input file")); + QString sOpenErr = tr("Error when open input file\n%1").arg(fileSrc.fileName()); + ui->plainTextEdit_MsgOutput->appendPlainText(sOpenErr); + QMessageBox::critical(this, "", sOpenErr); return; } if (!fileDest.open(QFile::WriteOnly)) { // Not use Text mode, because we need to specify newline char - QMessageBox::critical(this, "", tr("Error when open tmp output file")); + QString sOpenErr = tr("Error when open temporary output file\n%1").arg(fileDest.fileName()); + ui->plainTextEdit_MsgOutput->appendPlainText(sOpenErr); + QMessageBox::critical(this, "", sOpenErr); return; } diff --git a/MainWindow.ui b/MainWindow.ui index b84b81c..2c363b8 100644 --- a/MainWindow.ui +++ b/MainWindow.ui @@ -190,7 +190,7 @@ - *.cpp;*.h;*.c;*.hpp + *.cpp;*.h;*.c;*.hpp diff --git a/Res/res.qrc b/Res/res.qrc index 5e3886d..ed234a1 100644 --- a/Res/res.qrc +++ b/Res/res.qrc @@ -1,10 +1,8 @@ - translations/qtMod_zh_CN.qm - images/pause_Tbn.png - images/start_Tbn.png - images/stop_Tbn.png - images/setting.png images/locale.png + images/setting.png + translations/qtMod_zh_CN.qm + translations/zh_CN.qm diff --git a/Res/translations/zh_CN.ts b/Res/translations/zh_CN.ts new file mode 100644 index 0000000..063f5a9 --- /dev/null +++ b/Res/translations/zh_CN.ts @@ -0,0 +1,215 @@ + + + + + AboutDlg + + + About Software + 关于软件 + + + + MainWindow + + + Encoding Converter + 文本编码转换器 + + + + Encoding + 编码 + + + + + + In: + 输入: + + + + Auto detect (Support UTF and System encoding) + 自动检测(支持UTF和系统编码) + + + + + + Out: + 输出: + + + + Skip when input encoding is same as output + 输入编码与输出相同时跳过 + + + + Directory or file + 文件夹或文件 + + + + Browse + 浏览 + + + + If backup, copy file X as X.ecbak in same directory + 如果备份,则在同级目录中复制文件X为X.ecbak + + + + Recursively include sub directoy and file + 递归包含子文件夹和文件 + + + + Overwrite inputs + 覆盖输入 + + + + Backup + 备份 + + + + Suffix Name + 拓展名 + + + + New Line + 换行符 + + + + Any + 任意 + + + + Start + 开始 + + + + Stop + 停止 + + + + File: + 文件: + + + + Message output + 消息输出 + + + + System(ANSI in Windows) + 系统(Windows中为ANSI) + + + + Choose a directory + 选择一个目录 + + + + ---- Started at %1 ---- + ---- 开始于 %1 ---- + + + + Not existing or invalid path + 不存在或非法的路径 + + + + Finding files recursively... + 正在递归查找文件... + + + + Start to convert... + 开始转换... + + + + Error when open input file +%1 + 错误:打开输入文件:\n%1 + + + + Error when open temporary output file +%1 + 错误:打开临时输出文件:\n%1 + + + + %1 + 's input encoding is same as output, skip + %1 + 的输入编码与输出相同,跳过 + + + + ---- Finished at %1 ---- + ---- 完成于 %1 ---- + + + + %1 + 's size is >= %2GB, skip + %1 + 的大小 >= %2GB,跳过 + + + + Big file comfirmation + 大文件确认 + + + + %1 +'s size > %2MB, still to convert? + %1 +'的大小 > %2MB,仍要转换吗? + + + + %0 (%1 lines, %2%) + %0 (%1 行, %2%) + + + + SettingDlg + + + Setting + 设置 + + + + Language: + 语言: + + + + System + 系统 + + + + Take effect after restart + 重启后生效 + + + diff --git a/SettingDlg.cpp b/SettingDlg.cpp index 1e3bbcd..94c1800 100644 --- a/SettingDlg.cpp +++ b/SettingDlg.cpp @@ -20,7 +20,7 @@ SettingDlg::SettingDlg(QWidget *parent) : // langList<< "English"; // ui->comboBox_Lang->addItems(langList); - ui->comboBox_Lang->addItem(tr("System(系统)"), "System"); + ui->comboBox_Lang->addItem(tr("System"), "System"); ui->comboBox_Lang->addItem("Chinese(中文)", "Chinese"); ui->comboBox_Lang->addItem("English", "English"); diff --git a/main.cpp b/main.cpp index 8d4f9af..7ff1d52 100644 --- a/main.cpp +++ b/main.cpp @@ -5,31 +5,33 @@ #include #include -void LoadQtTranslation(QTranslator &tr_qt, QLocale::Language lang); +QTranslator trQt, trApp; +void LoadTranslator(QLocale::Language lang); int main(int argc, char *argv[]) { QApplication a(argc, argv); - QTranslator tr_qt; IniSetting cfg("config.ini"); QString sLanguage = cfg.value("language", "System").toString(); if (sLanguage == "System") - LoadQtTranslation(tr_qt, QLocale().language()); + LoadTranslator(QLocale().language()); else if (sLanguage == "Chinese") - LoadQtTranslation(tr_qt, QLocale::Chinese); - a.installTranslator(&tr_qt); + LoadTranslator(QLocale::Chinese); + a.installTranslator(&trQt); + a.installTranslator(&trApp); MainWindow w; w.show(); return a.exec(); } -void LoadQtTranslation(QTranslator &tr_qt, QLocale::Language lang) +void LoadTranslator(QLocale::Language lang) { switch (lang) { case QLocale::Chinese: - tr_qt.load(":/translations/qtMod_zh_CN.qm"); // modified from qt office release + trQt.load(":/translations/qtMod_zh_CN.qm"); // modified from qt office release + trApp.load(":/translations/zh_CN.qm"); break; default: break;