From ba95a7a990695a94eccf320483334d9ece49a37d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E7=B3=96=E9=9B=AA=E7=8B=B8?= Date: Sun, 7 Apr 2024 16:48:45 +0300 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E5=A4=9A=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E5=88=87=E6=8D=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/bll_polychat.h | 9 +++ App/dal_polychat.h | 5 ++ App/db_localdata.h | 7 ++ App/language_EN.qm | Bin 10341 -> 10473 bytes App/language_EN.ts | 65 ++++++++++-------- App/language_zh_CN.qm | Bin 8296 -> 8416 bytes App/language_zh_CN.ts | 65 ++++++++++-------- App/loginwidget.ui | 122 ++++++++++++++++++++++++++++------ App/uil_chatboxwidget.cpp | 3 +- App/uil_loginwidget.cpp | 34 ++++++++++ App/uil_loginwidget.h | 3 + Tester/tst_PolyChatTester.cpp | 2 +- 12 files changed, 239 insertions(+), 76 deletions(-) diff --git a/App/bll_polychat.h b/App/bll_polychat.h index 2d40283..f8c794d 100644 --- a/App/bll_polychat.h +++ b/App/bll_polychat.h @@ -91,6 +91,15 @@ static void initAndShowChatList(QWidget* parent) ::chatList->show(); } +static void loadTranslator() +{ + ::translator_EN = new QTranslator; + ::translator_EN->load(":/language/language_EN.qm"); + + ::translator_zn_CN = new QTranslator; + ::translator_zn_CN->load(":/language/language_zh_CN.qm"); +} + } #endif // BLL_POLYCHAT_H diff --git a/App/dal_polychat.h b/App/dal_polychat.h index dfb9e0b..a115c24 100644 --- a/App/dal_polychat.h +++ b/App/dal_polychat.h @@ -71,6 +71,11 @@ static void initAndShowChatList(QWidget* parent) BLL::initAndShowChatList(parent); } +static void loadTranslator() +{ + BLL::loadTranslator(); +} + } #endif // DAL_POLYCHAT_H diff --git a/App/db_localdata.h b/App/db_localdata.h index 83533ce..0de155f 100644 --- a/App/db_localdata.h +++ b/App/db_localdata.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "uil_chatlist.h" #include "chat.h" @@ -36,5 +37,11 @@ extern QString localUserGroupNumber; extern QHostAddress localIpAddress ; extern ChatList* chatList ; +/** + * 语言配置 + */ +static QTranslator* translator_EN; +static QTranslator* translator_zn_CN; + #endif // DB_LOCALDATA_H diff --git a/App/language_EN.qm b/App/language_EN.qm index f9adf490083203edfa404073a46456413e3eadf9..2098a0bbaaef2660d1fbac052ef839cd8eb377bc 100644 GIT binary patch delta 1130 zcmXYwe@v8h9LL|sJB>j?P}kn$|K3~=_@E7W`{J}s^@qhp}8?PK&2HaZS9W$N@_~y_+Nl6Lz}Xg$E?%Z@Q!O- zENEBfgn`uGwTYLnFz{0C*GC&c^7d@a}>YxTw;TBb?ZIlbNp}=gBSP0@*8^*rg>eks=*d3d!JY3Y}Kzn-?ZG zQgGUGl5I@gEc`iXppcWIsg((s&WZLXSSh(&>^QrVEq{%Saglym-Ef7(t0kua&#&Td zTiGi|f$p&bfAfEhuJXI1G?aDGJ$Zm}R(E;>11lSJ=SvvS-LKL&s2jO3%-)~T*BV~u zAUgC7$>VI@&-%vd{eX9|zU4Z6mBq}DoBr*1lL>5B znLTDMSoJFRgXY3=D{xP~`J}>@c`D7Z!FNY#7?(m*?2UXxDn7y?v`J9Gn_7LqPz!eAn|jDrg`Z|KH7H!`X5^_M%8lvl7Tv>Z3|SeIu7~joy*`%2+MO x*E*zRG-F7UYMVLyUN4`dQWU9+);86~ZBDN&%^dF7rG%reY^-aFByG+L>wl-ECLaI* delta 1045 zcmXAodu&rx9LK+1&%JGLd)v{itd{lRIu-^>jDSOlVL(T=(Twt1WkNJUfy&qvgbj$) zj7I_toGef#Z^AMj2_q|zFiGS!jRqMEl}Av}Y<~>r3mIgPfL}ei$^D#j?(g~io!dLD zC(_`1JsrRZz)?fK0;EkR#{;f$lHNvgA|T!&O8`wHX90TtXVIyNmjQ)_hABXphOXz5 zzA}g%xpb<7=oElC3i0C>I#x-h^ZS2$=Y2`{VM%`sO7R#bX@at|1F(*i^gM*JI|SHD zq5O0c$PP*-a$4ay{2c>zz;Pr1Wd4rHlUf1e8I+D#!{V-@bl!V_+KJK{cH!!h^u361 z6VJ_gDBE!ku-w9oxzB)%IheV26ENtcWTpoTx;~=adNh1xXZ#Pbr~U{FxQK%v$B}?I zfxkRM8F-W7rJghFaIax)ML*yT8h-0<2ZsETwqfHNfPYWgw(fr@^Owf79GW?j#-h!) zxfn3c%qwET24iym_vAg}H_QG6+}+0RZH%iLL_uyh8)+1?|Go~Gu80N69x72QKEa{{ zJCBK-C1)9^P|{T)>1`9owmzT($VcQba)6A8W1kwyT2djOiB!Q8cC=bDSSNZbS#ZX1 zav2K>ia&bIETmk~>ezr5Q=Aj1lSm|vtPmmnfZmJ=c;m}xDD`Ct8eal$nz4l z{8}>|PN`MfU!~MdYTIHa^gmWF6*EzGkz_Eec6MCm%;%V5=H6Wupw_mAd`E|{-GoJ^2s?i;v7MPPpNpq(Rl*RtwFC+V{^ zZ#c++0ZWTYx^uNiG6m#Z(@y(~DDhbBQJ;q$PuHH;*K(wTB)xI#n6meQ^t;x=84e(D z&U!q+QF(v0B|?3ig&wv|KEzAs++utCwuJ^!+lnMRw(hf??_$M6nr)9;Ml$gsJv5sV zn)d5;p_PE=Eq!Aoiwf?N)axakqx9DHLQ4I${=?6_r20jB`S_EJcgH?2e<|%R+Yi+6 zSIpS#vbPkllJxD4)k-fA{5B5c4o`(dQb~={qIy;~iV;I4pK1gU;kyzmF{$yqa9ge6 Y>V@&DXng*{SZZC?bweuk!fTFy0d;i^SO5S3 diff --git a/App/language_EN.ts b/App/language_EN.ts index 4fce81e..3f84018 100644 --- a/App/language_EN.ts +++ b/App/language_EN.ts @@ -156,7 +156,7 @@ - + Send file Send file @@ -252,66 +252,67 @@ IP address + Chat %1 on port %2 [Chat] %1 on port %2 - Chat %1 on port %2 + Chat %1 on port %2 - + Clean all message Clean all message - + Are you sure you want to clear all messages? Are you sure you want to clear all messages? - - - + + + Warning Warning - + Can not save! Message box is empty Can not save! Message box is empty - + Save file Save file - + Save cancel Save cancel - + Cancel sending file Cancel sending file - + Error Error - + File size cannot exceed 1Gb File size cannot exceed 1GB - + File reception request File reception request - + [%1] from group [%2] wants to send you a file, do you want to receive it? --------------------- @@ -326,13 +327,13 @@ Name: %3 Size: %4Kb - + %1 online %1 online! %1 online - + %1 left on %2 %1 left on %2 @@ -418,47 +419,57 @@ Size: %4Kb LoginWidget - Form - Hello PolyChat + Hello PolyChat + + + + 🌏 English + - + + 🇨🇳 Chinese + + + + PolyChat - + Group: Group: - + Name: Name: - + 🚀 - + Login Login - + Return Return - + + PolyChat Login PolyChat Login - + Name or Group number can not be empty Name or Group number can not be empty diff --git a/App/language_zh_CN.qm b/App/language_zh_CN.qm index 7588d5ded198e20910d1bed6bfe4dc9f353515b4..436671970ffc4ffb052f2f929535da4a87dbe1b5 100644 GIT binary patch delta 1116 zcmXAne@v8h9LL{x&-2_p_v5*TJMOqUzWr{%A>FzMi ziW6)!^%8~UnbBCHAz9hHYU8pEO5NHt7MYY=P6x6`iqnFoTR-0P{PFDd{eGX%kN4-t zFJ;%49=xwu0}ur4W8^}>@FQ6YIEQq4=iZkALN8ej$erYqfNkEPHBZDo1Ej@#xDBlA z0$fcxeQgjAFQC%}h{GaaUIOvTo3yLbsl2MwU7*wdBBZK9z@kDra-M9{>FI{lT>)61 zg7h3P_TuftO#vGD zCJYOSO_#}(@J)0Ya6coAcLpfDP%K(74v3@T+S}g)rj)ojag&{B7k8tPf`j6b>a#Hh zS~z!L2PSm-jN+*ScNk!boTa0iyh}bVp6U?DO{7HrDkh8WQRpq5xju1n3k9q1lTixF z6n~$T87CrH+gN}+Cb^cfQ`TuIe)a(OB$JHsknx-T;MpmSR-FNSz0yQ0XXRXBTJp}H z{NHM-`|boC2Tb9&@)_tc)0r2T*#DF1Ton^$4d~37Fb$u-$k~5ru9vqnL9cmR@&k@; z&>U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kH}hF&=yXY6NNaDo&6&?JFSM+oZlifc^bGIR&*sX~2I^IqL(lo&-5?o% z&-^I-z0eU$Qhz3e3oQQ?#*uZF?!lYv2rQr8H**BF)?d!Ilcm-ZTaHmM#oDBi?gh5O zNEGm;+b#{yV~c~ff$l^m?y-HTSm7gHrDM+x$Nx>ES$M1NFJTL{Tz#{D12E(teOsZI zNykarQzf03^>fX+wEtFr@RXO-UgRv!`JH-g&iSJ%xqpuH=sLcNMxV#olual4T%$_u zVv^ToKvHJZFLsIOaBI6QEeZKph;n|GBN>JKEyo5-!D7tCYEG4A_!WWWmCN>K4Dm#J M+*PJ%i^pgG3Wlc%Z2$lO diff --git a/App/language_zh_CN.ts b/App/language_zh_CN.ts index 9507b9a..70a8c3d 100644 --- a/App/language_zh_CN.ts +++ b/App/language_zh_CN.ts @@ -155,7 +155,7 @@ - + Send file 发送文件 @@ -251,66 +251,67 @@ IP 地址 + Chat %1 on port %2 [Chat] %1 on port %2 - 群聊 %1 在端口 %2 + 群聊 %1 在端口 %2 - + Clean all message 清空聊天框 - + Are you sure you want to clear all messages? 您确定要清空聊天框吗? - - - + + + Warning 警告 - + Can not save! Message box is empty 无法保存! 信息框为空 - + Save file 保存文件 - + Save cancel 取消保存 - + Cancel sending file 取消文件发送 - + Error 错误 - + File size cannot exceed 1Gb 文件大小不能超过 1GB - + File reception request 文件接收请求 - + [%1] from group [%2] wants to send you a file, do you want to receive it? --------------------- @@ -325,13 +326,13 @@ Size: %4Kb 大小: %4Kb - + %1 online %1 online! %1 上线 - + %1 left on %2 %1 在 %2 退出 @@ -417,47 +418,57 @@ Size: %4Kb LoginWidget - Form - Hello PolyChat + Hello PolyChat + + + + 🌏 English + - + + 🇨🇳 Chinese + + + + PolyChat - + Group: 班级号: - + Name: 姓名: - + 🚀 - + Login 登录 - + Return 返回 - + + PolyChat Login 登录 PolyChat - + Name or Group number can not be empty 名称或班级号不能为空 diff --git a/App/loginwidget.ui b/App/loginwidget.ui index b59f71b..8bda108 100644 --- a/App/loginwidget.ui +++ b/App/loginwidget.ui @@ -23,9 +23,93 @@ - Form + PolyChat Login + + + -1 + + + Qt::LeftToRight + + 12 + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 10 + + + + + + + + + 0 + 0 + + + + + 120 + 0 + + + + Qt::LeftToRight + + + 10 + + + QComboBox::InsertAtCurrent + + + + 🌏 English + + + + + 🇨🇳 Chinese + + + + + + + @@ -37,7 +121,7 @@ Times New Roman - 42 + 48 false true false @@ -60,23 +144,6 @@ - - - - - - - Group: - - - - - - - Name: - - - @@ -90,6 +157,13 @@ + + + + Group: + + + @@ -103,6 +177,16 @@ + + + + + + + Name: + + + diff --git a/App/uil_chatboxwidget.cpp b/App/uil_chatboxwidget.cpp index 338cb5b..42b9640 100644 --- a/App/uil_chatboxwidget.cpp +++ b/App/uil_chatboxwidget.cpp @@ -23,8 +23,7 @@ ChatBoxWidget::ChatBoxWidget(QWidget* parent, QString name, qint16 port) ui->setupUi(this); this->setAttribute(Qt::WA_DeleteOnClose); this->setWindowIcon(QIcon(":/icon/icons/user-group.png")); - this->setWindowTitle(QString("Chat %1 on port %2").arg(name, port)); -// this->setWindowTitle(tr("Chat %1 on port %2").arg(name, port)); + this->setWindowTitle(QString(tr("Chat %1 on port %2")).arg(name).arg(port)); // 注意:这里 .arg() 必须链式调用 不可以 .arg(name, port) 否则无法正常渲染。这是因为 如果想 .arg(name, port) 单次调用的话,必须保证参数类型一样,而这里是一个 QString 一个 qint16 类型,而链式调用就不存在这个问题 /* 对所有窗口的同样地址广播 8888 (告诉 ChatList 本窗口存在) */ diff --git a/App/uil_loginwidget.cpp b/App/uil_loginwidget.cpp index b9b9845..7c604b8 100644 --- a/App/uil_loginwidget.cpp +++ b/App/uil_loginwidget.cpp @@ -16,6 +16,7 @@ LoginWidget::LoginWidget(QWidget *parent) : this->setWindowTitle(tr("PolyChat Login")); this->setWindowIcon(QIcon(":/icon/icons/nekosilverfox.png")); + ui->leUserName->setFocus(); // this->setAttribute(Qt::WA_DeleteOnClose); @@ -28,6 +29,27 @@ LoginWidget::LoginWidget(QWidget *parent) : Qt::SmoothTransformation))); // 使用平滑的缩放方式 this->setPalette(background); + /* 加载语言配置 */ + DAL::loadTranslator(); + /* 切换语言 */ + connect(ui->cbLanguage, &QComboBox::currentIndexChanged, + this, [&](){ + switch (ui->cbLanguage->currentIndex()) + { + case 0: + qApp->installTranslator(::translator_EN); + break; + case 1: + qApp->installTranslator(::translator_zn_CN); + break; + default: + break; + } + + }); + emit ui->cbLanguage->currentIndexChanged(0); // 先发送一下信号让启动默认语言变为英语 + + /* User checked button `login` */ connect(ui->btnLogin, &QPushButton::clicked, this, &LoginWidget::userLogin); @@ -45,6 +67,18 @@ LoginWidget::LoginWidget(QWidget *parent) : }); } +void LoginWidget::changeEvent(QEvent* event) +{ + if (event->type() == QEvent::LanguageChange) + { + ui->retranslateUi(this); + } + else + { + QWidget::changeEvent(event); // 否则,一切应该像平时一样进行 + } +} + /** [SLOT] User Login * @brief LoginWidget::userLogin diff --git a/App/uil_loginwidget.h b/App/uil_loginwidget.h index d9513c3..df0a545 100644 --- a/App/uil_loginwidget.h +++ b/App/uil_loginwidget.h @@ -16,6 +16,9 @@ class LoginWidget : public QWidget explicit LoginWidget(QWidget *parent = nullptr); ~LoginWidget(); +protected: + virtual void changeEvent(QEvent *event); + public slots: void userLogin(); diff --git a/Tester/tst_PolyChatTester.cpp b/Tester/tst_PolyChatTester.cpp index 9023ec9..15816e8 100644 --- a/Tester/tst_PolyChatTester.cpp +++ b/Tester/tst_PolyChatTester.cpp @@ -946,7 +946,7 @@ void PolyChatTester::ut_tcpserver_textBrowser() void PolyChatTester::ut_chatbox_title() { ChatBoxWidget chatBox(nullptr, "3530409/90102", 2333); - QCOMPARE(chatBox.windowTitle(), QString("Chat %1 on port %2").arg("3530409/90102", 2333)); + QCOMPARE(chatBox.windowTitle(), QString("Chat %1 on port %2").arg("3530409/90102").arg(2333)); } /** 保证 btnBold 是可选按钮(Checkable-QToolButton),且文字显示被禁用