mirror of
https://github.com/jaredtao/TaoQuick.git
synced 2025-01-19 20:22:56 +08:00
Trans use qsTr.
This commit is contained in:
parent
fef2528b86
commit
3cc40c44aa
@ -30,7 +30,7 @@ Popup {
|
|||||||
}
|
}
|
||||||
TTextBtn {
|
TTextBtn {
|
||||||
id: closeBtn
|
id: closeBtn
|
||||||
text: trans.trans("Close") + trans.transString
|
text: qsTr("Close")
|
||||||
width: 80
|
width: 80
|
||||||
height: 38
|
height: 38
|
||||||
radius: 8
|
radius: 8
|
||||||
|
@ -50,7 +50,7 @@ Rectangle {
|
|||||||
ToolTip {
|
ToolTip {
|
||||||
id: tip
|
id: tip
|
||||||
delay: 800
|
delay: 800
|
||||||
text: trans.trans(String("Component Name: %1, Count: %2")).arg(trans.trans(name)).arg(count) + trans.transString
|
text: qsTr(String("Component Name: %1, Count: %2")).arg(qsTr(name)).arg(count)
|
||||||
visible: area.containsMouse
|
visible: area.containsMouse
|
||||||
}
|
}
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
@ -23,7 +23,7 @@ TImageBtn {
|
|||||||
delegate: TTextBtn {
|
delegate: TTextBtn {
|
||||||
width: langListView.width
|
width: langListView.width
|
||||||
height: 36
|
height: 36
|
||||||
text: trans.trans(modelData) + trans.transString
|
text: qsTr(modelData)
|
||||||
color: trans.currentLang === modelData ? gConfig.themeColor :( containsMouse ? "lightgray" : pop.barColor)
|
color: trans.currentLang === modelData ? gConfig.themeColor :( containsMouse ? "lightgray" : pop.barColor)
|
||||||
textColor: gConfig.textColor
|
textColor: gConfig.textColor
|
||||||
radius: 4
|
radius: 4
|
||||||
|
@ -42,7 +42,7 @@ TImageBtn {
|
|||||||
centerIn: parent
|
centerIn: parent
|
||||||
}
|
}
|
||||||
color: "white"
|
color: "white"
|
||||||
text: trans.trans(model.name) + trans.transString
|
text: qsTr(model.name)
|
||||||
}
|
}
|
||||||
Rectangle {
|
Rectangle {
|
||||||
x: parent.width - width
|
x: parent.width - width
|
||||||
|
@ -15,7 +15,7 @@ Background {
|
|||||||
topMargin: 60
|
topMargin: 60
|
||||||
}
|
}
|
||||||
property string title: defaultTitle
|
property string title: defaultTitle
|
||||||
text: trans.trans(title) + trans.transString
|
text: qsTr(title)
|
||||||
}
|
}
|
||||||
GridView {
|
GridView {
|
||||||
id: gridView
|
id: gridView
|
||||||
@ -34,7 +34,7 @@ Background {
|
|||||||
height: 100
|
height: 100
|
||||||
CompCard {
|
CompCard {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
name: trans.trans(modelData.name) + trans.transString
|
name: qsTr(modelData.name)
|
||||||
count: modelData.count
|
count: modelData.count
|
||||||
icon: modelData.icon
|
icon: modelData.icon
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
@ -29,7 +29,7 @@ ListView {
|
|||||||
id: btn
|
id: btn
|
||||||
width: root.width
|
width: root.width
|
||||||
height: rowHeight
|
height: rowHeight
|
||||||
text: trans.trans(model.name) + trans.transString
|
text: qsTr(model.name)
|
||||||
textItem.leftPadding: 6
|
textItem.leftPadding: 6
|
||||||
textHorizontalAlignment: Text.AlignLeft
|
textHorizontalAlignment: Text.AlignLeft
|
||||||
textColor: text === currentTitle ? gConfig.titleBackground : gConfig.textColor
|
textColor: text === currentTitle ? gConfig.titleBackground : gConfig.textColor
|
||||||
@ -68,7 +68,7 @@ ListView {
|
|||||||
delegate: TGradientBtn {
|
delegate: TGradientBtn {
|
||||||
width: root.width
|
width: root.width
|
||||||
height: rowHeight
|
height: rowHeight
|
||||||
text: trans.trans(model.name) + trans.transString
|
text: qsTr(model.name)
|
||||||
textColor: text === currentTitle ? gConfig.titleBackground : gConfig.textColor
|
textColor: text === currentTitle ? gConfig.titleBackground : gConfig.textColor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
currentTitle = model.name
|
currentTitle = model.name
|
||||||
|
@ -45,7 +45,7 @@ Rectangle {
|
|||||||
|
|
||||||
}
|
}
|
||||||
function notify(msg) {
|
function notify(msg) {
|
||||||
t.text = msg + trans.transString
|
t.text = msg
|
||||||
ani.start()
|
ani.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
const static auto cEnglisthStr = QStringLiteral("English");
|
const static auto cEnglisthStr = QStringLiteral("English");
|
||||||
const static auto cChineseStr = QStringLiteral("简体中文");
|
const static auto cChineseStr = QStringLiteral("简体中文");
|
||||||
Trans::Trans(QObject* parent)
|
Trans::Trans(QObject* parent)
|
||||||
: QObject(parent)
|
: QTranslator(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void Trans::init() {}
|
void Trans::init() {}
|
||||||
@ -17,11 +17,22 @@ void Trans::uninit() {}
|
|||||||
void Trans::beforeUiReady(QQmlContext* ctx)
|
void Trans::beforeUiReady(QQmlContext* ctx)
|
||||||
{
|
{
|
||||||
ctx->setContextProperty("trans", this);
|
ctx->setContextProperty("trans", this);
|
||||||
|
loadFolder(qApp->applicationDirPath() + "/Trans");
|
||||||
|
qApp->installTranslator(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Trans::afterUiReady()
|
void Trans::afterUiReady()
|
||||||
{
|
{
|
||||||
loadFolder(qApp->applicationDirPath() + "/Trans");
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Trans::translate(const char *context, const char *sourceText, const char *disambiguation, int n) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(context)
|
||||||
|
Q_UNUSED(disambiguation)
|
||||||
|
Q_UNUSED(n)
|
||||||
|
|
||||||
|
return trans(sourceText);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Trans::loadFolder(const QString& folder)
|
void Trans::loadFolder(const QString& folder)
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "TaoObject.h"
|
#include "TaoObject.h"
|
||||||
class Trans : public QObject, public TaoObject
|
#include <QTranslator>
|
||||||
|
class Trans : public QTranslator, public TaoObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString currentLang READ currentLang WRITE setCurrentLang NOTIFY currentLangChanged)
|
Q_PROPERTY(QString currentLang READ currentLang WRITE setCurrentLang NOTIFY currentLangChanged)
|
||||||
@ -25,6 +26,8 @@ public:
|
|||||||
void beforeUiReady(QQmlContext* ctx) override;
|
void beforeUiReady(QQmlContext* ctx) override;
|
||||||
|
|
||||||
void afterUiReady() override;
|
void afterUiReady() override;
|
||||||
|
|
||||||
|
QString translate(const char *context, const char *sourceText, const char *disambiguation = nullptr, int n = -1) const override;
|
||||||
public:
|
public:
|
||||||
const QString ¤tLang() const;
|
const QString ¤tLang() const;
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ int main(int argc, char** argv)
|
|||||||
TaoFramework::instance()->beforeUiReady(view.rootContext());
|
TaoFramework::instance()->beforeUiReady(view.rootContext());
|
||||||
|
|
||||||
view.engine()->addImportPath(qmlPath);
|
view.engine()->addImportPath(qmlPath);
|
||||||
|
QObject::connect(TaoFramework::instance()->getObject<Trans>(), &Trans::currentLangChanged, view.engine(), &QQmlEngine::retranslate);
|
||||||
view.rootContext()->setContextProperty("qmlPath", qmlPath);
|
view.rootContext()->setContextProperty("qmlPath", qmlPath);
|
||||||
view.rootContext()->setContextProperty("imgPath", imgPath);
|
view.rootContext()->setContextProperty("imgPath", imgPath);
|
||||||
view.rootContext()->setContextProperty("contentsPath", contentsPath);
|
view.rootContext()->setContextProperty("contentsPath", contentsPath);
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
CONFIG += file_copies
|
CONFIG += file_copies
|
||||||
|
|
||||||
|
#一部分头文件加入编译预处理,提高编译速度
|
||||||
|
msvc | gcc | xcode {
|
||||||
|
CONFIG += precompile_header
|
||||||
|
PRECOMPILED_HEADER = $$PWD/Src/stdafx.h
|
||||||
|
}
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/Src/TaoObject.h \
|
$$PWD/Src/TaoObject.h \
|
||||||
$$PWD/Src/TaoFramework.h \
|
$$PWD/Src/TaoFramework.h \
|
||||||
|
@ -31,11 +31,6 @@ CONFIG(debug,debug|release) {
|
|||||||
# QMAKE_CFLAGS += -source-charset:utf-8
|
# QMAKE_CFLAGS += -source-charset:utf-8
|
||||||
# QMAKE_CXXFLAGS += -source-charset:utf-8
|
# QMAKE_CXXFLAGS += -source-charset:utf-8
|
||||||
#}
|
#}
|
||||||
#一部分头文件加入编译预处理,提高编译速度
|
|
||||||
msvc | gcc | xcode {
|
|
||||||
CONFIG += precompile_header
|
|
||||||
PRECOMPILED_HEADER = $$PWD/Src/stdafx.h
|
|
||||||
}
|
|
||||||
|
|
||||||
include($${TaoQuick_3RDPARTY_TREE}/3rdparty.pri)
|
include($${TaoQuick_3RDPARTY_TREE}/3rdparty.pri)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user