Skip to content

Commit

Permalink
1 Add Chinese Simplified translations
Browse files Browse the repository at this point in the history
2 MainWindow.cpp: Show and log the file path when open error
  • Loading branch information
LiaoCheng authored and LiaoCheng committed Jan 30, 2023
1 parent a30e842 commit cd2ce74
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Add by me:
bin/*
*.qm

# following are get from gitHub:

Expand Down
4 changes: 2 additions & 2 deletions AboutDlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<item>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="plainText">
<string>Email: [email protected]
<string notr="true">Email: [email protected]
https://github.com/CharlesLiaoO/EncodingConverter
Build with Qt/C++</string>
</property>
Expand All @@ -31,7 +31,7 @@ Build with Qt/C++</string>
<item>
<widget class="QToolButton" name="toolButton_AboutQt">
<property name="text">
<string>About Qt</string>
<string notr="true">About Qt</string>
</property>
</widget>
</item>
Expand Down
2 changes: 2 additions & 0 deletions EncodingConverter.pro
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ FORMS += \

RESOURCES += \
Res/res.qrc

TRANSLATIONS += Res/translations/zh_CN.ts
8 changes: 6 additions & 2 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
</size>
</property>
<property name="plainText">
<string>*.cpp;*.h;*.c;*.hpp</string>
<string notr="true">*.cpp;*.h;*.c;*.hpp</string>
</property>
</widget>
</item>
Expand Down
8 changes: 3 additions & 5 deletions Res/res.qrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<RCC>
<qresource prefix="/">
<file>translations/qtMod_zh_CN.qm</file>
<file>images/pause_Tbn.png</file>
<file>images/start_Tbn.png</file>
<file>images/stop_Tbn.png</file>
<file>images/setting.png</file>
<file>images/locale.png</file>
<file>images/setting.png</file>
<file>translations/qtMod_zh_CN.qm</file>
<file>translations/zh_CN.qm</file>
</qresource>
</RCC>
215 changes: 215 additions & 0 deletions Res/translations/zh_CN.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>AboutDlg</name>
<message>
<location filename="../../AboutDlg.ui" line="14"/>
<source>About Software</source>
<translation>关于软件</translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
<location filename="../../MainWindow.ui" line="14"/>
<source>Encoding Converter</source>
<translation>文本编码转换器</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="21"/>
<source>Encoding</source>
<translation>编码</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="27"/>
<location filename="../../MainWindow.ui" line="107"/>
<location filename="../../MainWindow.ui" line="209"/>
<source>In:</source>
<translation>输入:</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="38"/>
<source>Auto detect (Support UTF and System encoding)</source>
<translation>自动检测(支持UTF和系统编码)</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="46"/>
<location filename="../../MainWindow.ui" line="144"/>
<location filename="../../MainWindow.ui" line="216"/>
<source>Out:</source>
<translation>输出:</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="74"/>
<source>Skip when input encoding is same as output</source>
<translation>输入编码与输出相同时跳过</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="87"/>
<source>Directory or file</source>
<translation>文件夹或文件</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="93"/>
<source>Browse</source>
<translation>浏览</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="122"/>
<source>If backup, copy file X as X.ecbak in same directory</source>
<translation>如果备份,则在同级目录中复制文件X为X.ecbak</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="151"/>
<source>Recursively include sub directoy and file</source>
<translation>递归包含子文件夹和文件</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="164"/>
<source>Overwrite inputs</source>
<translation>覆盖输入</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="171"/>
<source>Backup</source>
<translation>备份</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="181"/>
<source>Suffix Name</source>
<translation>拓展名</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="203"/>
<source>New Line</source>
<translation>换行符</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="224"/>
<source>Any</source>
<translation>任意</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="258"/>
<source>Start</source>
<translation>开始</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="265"/>
<source>Stop</source>
<translation>停止</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="277"/>
<source>File: </source>
<translation>文件:</translation>
</message>
<message>
<location filename="../../MainWindow.ui" line="326"/>
<source>Message output</source>
<translation>消息输出</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="67"/>
<source>System(ANSI in Windows)</source>
<translation>系统(Windows中为ANSI)</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="113"/>
<source>Choose a directory</source>
<translation>选择一个目录</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="190"/>
<source>---- Started at %1 ----</source>
<translation>---- 开始于 %1 ----</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="206"/>
<source>Not existing or invalid path</source>
<translation>不存在或非法的路径</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="220"/>
<source>Finding files recursively...</source>
<translation>正在递归查找文件...</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="223"/>
<source>Start to convert...</source>
<translation>开始转换...</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="238"/>
<source>Error when open input file
%1</source>
<translation>错误:打开输入文件:\n%1</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="244"/>
<source>Error when open temporary output file
%1</source>
<translation>错误:打开临时输出文件:\n%1</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="262"/>
<source>%1
&apos;s input encoding is same as output, skip</source>
<translation>%1
的输入编码与输出相同,跳过</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="312"/>
<source>---- Finished at %1 ----</source>
<translation>---- 完成于 %1 ----</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="344"/>
<source>%1
&apos;s size is &gt;= %2GB, skip</source>
<translation>%1
的大小 &gt;= %2GB,跳过</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="350"/>
<source>Big file comfirmation</source>
<translation>大文件确认</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="350"/>
<source>%1
&apos;s size &gt; %2MB, still to convert?</source>
<translation>%1
&apos;的大小 &gt; %2MB,仍要转换吗?</translation>
</message>
<message>
<location filename="../../MainWindow.cpp" line="370"/>
<source>%0 (%1 lines, %2%)</source>
<translation>%0 (%1 行, %2%)</translation>
</message>
</context>
<context>
<name>SettingDlg</name>
<message>
<location filename="../../SettingDlg.ui" line="14"/>
<source>Setting</source>
<translation>设置</translation>
</message>
<message>
<location filename="../../SettingDlg.ui" line="37"/>
<source>Language: </source>
<translation>语言:</translation>
</message>
<message>
<location filename="../../SettingDlg.cpp" line="23"/>
<source>System</source>
<translation>系统</translation>
</message>
<message>
<location filename="../../SettingDlg.cpp" line="44"/>
<source>Take effect after restart</source>
<translation>重启后生效</translation>
</message>
</context>
</TS>
2 changes: 1 addition & 1 deletion SettingDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
16 changes: 9 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@
#include <NotPrjRel.h>
#include <QLocale>

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;
Expand Down

0 comments on commit cd2ce74

Please sign in to comment.