Skip to content

Commit

Permalink
Merge branch 'feature/i18n' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
alphagocc committed Feb 11, 2018
2 parents 2aacc83 + 7538b75 commit 45ec6bd
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 7 deletions.
41 changes: 35 additions & 6 deletions FiveChess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@
#include "ui_FiveChess.h"
#include "battlegui.h"
#include "waitdialog.h"
#include "stdafx.h"
#include <QDebug>
#include <QLocale>

FiveChess::FiveChess(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::FiveChess)
QMainWindow(parent),
ui(new Ui::FiveChess)
{
ui->setupUi(this);
QObject::connect(ui->pushButtonNew,&QPushButton::clicked,this,&FiveChess::newFiveChessGame);
QObject::connect(ui->pushButtonLoad,&QPushButton::clicked,this,&FiveChess::loadFiveChessGame);
ui->setupUi(this);
QObject::connect(ui->pushButtonNew, &QPushButton::clicked, this, &FiveChess::newFiveChessGame);
QObject::connect(ui->pushButtonLoad, &QPushButton::clicked, this, &FiveChess::loadFiveChessGame);
connect(ui->actionEnglish, &QAction::triggered, this, [&] {
translateUi(QLocale::UnitedStates);
qDebug() << "!!#3" << endl;
});
connect(ui->actionChinese, &QAction::triggered, this, [&] {
translateUi(QLocale::China);
qDebug() << "!!#zh_cn" << endl;
});
}

FiveChess::~FiveChess()
{
delete ui;
Expand All @@ -23,6 +32,7 @@ void FiveChess::newFiveChessGame()
hide();
battleGui *gameGui = new battleGui();
gameGui->setData(chessBoardData);
gameGui->setTranslator(tsor);
gameGui->show();
}

Expand All @@ -44,3 +54,22 @@ void FiveChess::setData(chessBoardData_Process *data)
this->chessBoardData=data;
qDebug()<<"SetData0!"<<data<<endl;
}

void FiveChess::translateUi(int value)
{
switch (value)
{
case QLocale::China: {
tsor->load(":/lang/zh_CN.qm");
break;
}
case QLocale::UnitedStates: {
tsor->load(":/lang/en_US.qm");
break;
}
default: {
break;
}
}
ui->retranslateUi(this);
}
5 changes: 4 additions & 1 deletion FiveChess.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <QMainWindow>
#include "chessboarddata_process.h"
#include <QTranslator>

namespace Ui {
class FiveChess;
Expand All @@ -18,13 +19,15 @@ class FiveChess : public QMainWindow

private:
Ui::FiveChess *ui;

QTranslator *tsor;
public slots:
void newFiveChessGame();
void loadFiveChessGame();
public :
chessBoardData_Process *chessBoardData;
void setData(chessBoardData_Process*data);
void translateUi(int value);
void setTranslator(QTranslator *tsor) { this->tsor = tsor; }
};

#endif // FIVECHESS_H
2 changes: 2 additions & 0 deletions FiveChess.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,15 @@
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="main.cpp" />
<ClCompile Include="stdafx.cpp" />
<ClCompile Include="waitdialog.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="GeneratedFiles\ui_battlegui.h" />
<ClInclude Include="GeneratedFiles\ui_chessboardgui.h" />
<ClInclude Include="GeneratedFiles\ui_FiveChess.h" />
<ClInclude Include="GeneratedFiles\ui_waitdialog.h" />
<ClInclude Include="stdafx.h" />
<CustomBuild Include="FiveChess.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o "$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -D_UNICODE -DWIN32 -DWIN64 -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG "-I." "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtCore" "-I.\release" "-I$(QTDIR)\mkspecs\win32-msvc" "-I.\GeneratedFiles"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o "$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -D_UNICODE -DWIN32 -DWIN64 -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG "-I." "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtCore" "-I.\release" "-I$(QTDIR)\mkspecs\win32-msvc" "-I.\GeneratedFiles"</Command>
Expand Down
6 changes: 6 additions & 0 deletions FiveChess.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<ClCompile Include="GeneratedFiles\qrc_fivechessresources.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="FiveChess.h">
Expand Down Expand Up @@ -153,6 +156,9 @@
<ClInclude Include="GeneratedFiles\ui_waitdialog.h">
<Filter>Generated Files</Filter>
</ClInclude>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="Resources\black.png">
Expand Down
1 change: 1 addition & 0 deletions battlegui.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "battlegui.h"
#include "ui_battlegui.h"
#include "stdafx.h"
#include <QDebug>

battleGui::battleGui(QWidget *parent) :
Expand Down
3 changes: 3 additions & 0 deletions battlegui.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QWidget>
#include "chessboarddata_process.h"
#include <QTimer>
#include <QTranslator>

namespace Ui {
class battleGui;
Expand All @@ -22,9 +23,11 @@ class battleGui : public QWidget
bool close();
QTimer *timer;
int time;
QTranslator * tsor;
public :
chessBoardData_Process *chessBoardData;
void setData(chessBoardData_Process*data);
void setTranslator(QTranslator *tsor) { this->tsor = tsor; }
};

#endif // BATTLEGUI_H
1 change: 1 addition & 0 deletions chessboardgui.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "chessboardgui.h"
#include "ui_chessboardgui.h"
#include "stdafx.h"
#include <QPainter>
#include <QMouseEvent>
#include <QPaintEvent>
Expand Down
Binary file added en_US.qm
Binary file not shown.
108 changes: 108 additions & 0 deletions en_US.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context>
<name>FiveChess</name>
<message>
<location filename="FiveChess.ui" line="38"/>
<source>New Game</source>
<translation></translation>
</message>
<message>
<location filename="FiveChess.ui" line="51"/>
<source>Load Game</source>
<translation></translation>
</message>
<message>
<location filename="FiveChess.ui" line="83"/>
<source>Language</source>
<translation></translation>
</message>
<message>
<location filename="FiveChess.ui" line="90"/>
<source>About</source>
<translation></translation>
</message>
<message>
<location filename="FiveChess.ui" line="99"/>
<source>English</source>
<translation></translation>
</message>
<message>
<location filename="FiveChess.ui" line="104"/>
<source>Chinese</source>
<translation></translation>
</message>
<message>
<location filename="FiveChess.ui" line="14"/>
<location filename="FiveChess.ui" line="63"/>
<source>FiveChess</source>
<translation></translation>
</message>
</context>
<context>
<name>battleGui</name>
<message>
<location filename="battlegui.ui" line="20"/>
<source>Battle</source>
<translation></translation>
</message>
<message>
<location filename="battlegui.ui" line="65"/>
<source>Exit</source>
<translation></translation>
</message>
<message>
<location filename="battlegui.ui" line="72"/>
<source>Save</source>
<translation></translation>
</message>
<message>
<location filename="battlegui.ui" line="79"/>
<source>Time:</source>
<translation></translation>
</message>
<message>
<location filename="battlegui.cpp" line="21"/>
<source>Time:%1 Second</source>
<translation></translation>
</message>
</context>
<context>
<name>chessBoardData_Process</name>
<message>
<location filename="chessboarddata_process.cpp" line="61"/>
<source>Save Chess Board File</source>
<translation></translation>
</message>
<message>
<location filename="chessboarddata_process.cpp" line="63"/>
<location filename="chessboarddata_process.cpp" line="96"/>
<source>ChessBoardFile(*.chessbrd)</source>
<translation></translation>
</message>
<message>
<location filename="chessboarddata_process.cpp" line="94"/>
<source>Open Chess Board File</source>
<translation></translation>
</message>
</context>
<context>
<name>waitDialog</name>
<message>
<location filename="waitdialog.ui" line="14"/>
<source>Dialog</source>
<translation></translation>
</message>
<message>
<location filename="waitdialog.ui" line="20"/>
<source>组件开发中,敬请期待。</source>
<translation></translation>
</message>
<message>
<location filename="waitdialog.ui" line="27"/>
<source>Github:alphagocc</source>
<translation></translation>
</message>
</context>
</TS>
4 changes: 4 additions & 0 deletions fivechessresources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
<qresource prefix="/ico">
<file>Resources/ICO.ico</file>
</qresource>
<qresource prefix="/lang">
<file>en_US.qm</file>
<file>zh_CN.qm</file>
</qresource>
</RCC>
6 changes: 6 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
#include "chessboarddata_process.h"
#include <QApplication>
#include "chessboardgui.h"
#include <QTranslator>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTranslator tsor;
tsor.load(":/lang/zh_CN.qm");
a.installTranslator(&tsor);

FiveChess w;
chessBoardData_Process data=chessBoardData_Process();
w.setTranslator(&tsor);
w.setData(&data);
w.show();

Expand Down
1 change: 1 addition & 0 deletions stdafx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <stdafx.h>
1 change: 1 addition & 0 deletions stdafx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <QWidget>
Binary file added zh_CN.qm
Binary file not shown.
Loading

0 comments on commit 45ec6bd

Please sign in to comment.