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