Project: Qt 5 only support simple qsTr or qsTranslate(in the same file).

This commit is contained in:
Mentalflow 2025-05-29 00:00:14 +08:00
parent 1354767d6a
commit 461dbdbf47
Signed by: Mentalflow
GPG Key ID: 5AE68D4401A2EE71
4 changed files with 60 additions and 46 deletions

View File

@ -9,10 +9,12 @@ RibbonSplashScreen {
contentArgs: { contentArgs: {
"implicitHeight": 250, "implicitHeight": 250,
"implicitWidth": 450, "implicitWidth": 450,
"titleText": QT_TRANSLATE_NOOP("RibbonSplashScreen", "Example App"), "titleText": qsTr("Example App"),
"subTitleText": QT_TRANSLATE_NOOP("RibbonSplashScreen", "A example for users to use RibbonUI.") "subTitleText": qsTr("A example for users to use RibbonUI.")
} }
onContentArgsChanged: loadItemArgs()
Timer{ Timer{
interval: 1000 interval: 1000
triggeredOnStart: true triggeredOnStart: true

View File

@ -68,8 +68,8 @@ RibbonWindow {
RibbonTour{ RibbonTour{
id: tour id: tour
RibbonTourItem{ RibbonTourItem{
title: QT_TRANSLATE_NOOP("RibbonTour", "Tab Bar") title: qsTr("Tab Bar")
text: QT_TRANSLATE_NOOP("RibbonTour", "A tab bar for window, let user choose the controllers.") text: qsTr("A tab bar for window, let user choose the controllers.")
target: tab_bar target: tab_bar
enterFunc: ()=>{ enterFunc: ()=>{
tab_bar.folded = false tab_bar.folded = false
@ -77,13 +77,13 @@ RibbonWindow {
} }
} }
RibbonTourItem{ RibbonTourItem{
title: QT_TRANSLATE_NOOP("RibbonTour", "Tab Bar Buttons") title: qsTr("Tab Bar Buttons")
text: QT_TRANSLATE_NOOP("RibbonTour", "Tool buttons at the top of tab bar.") text: qsTr("Tool buttons at the top of tab bar.")
target: tab_bar.tab_bar_tool target: tab_bar.tab_bar_tool
} }
RibbonTourItem{ RibbonTourItem{
title: QT_TRANSLATE_NOOP("RibbonTour", "Sliders") title: qsTr("Sliders")
text: QT_TRANSLATE_NOOP("RibbonTour", "Vertical/Horizental sliders with/without buttons.") text: qsTr("Vertical/Horizental sliders with/without buttons.")
target: tab_bar.slider_layout target: tab_bar.slider_layout
enterFunc: ()=>{ enterFunc: ()=>{
tab_bar.setPage(0) tab_bar.setPage(0)
@ -97,32 +97,32 @@ RibbonWindow {
} }
} }
RibbonTourItem{ RibbonTourItem{
title: QT_TRANSLATE_NOOP("RibbonTour", "Switch Buttons") title: qsTr("Switch Buttons")
text: QT_TRANSLATE_NOOP("RibbonTour", "Switch buttons with/without background color or grabber text.") text: qsTr("Switch buttons with/without background color or grabber text.")
target: tab_bar.switch_layout target: tab_bar.switch_layout
enterFunc: ()=>tab_bar.btn_with_color_and_grabberText.checked = true enterFunc: ()=>tab_bar.btn_with_color_and_grabberText.checked = true
exitFunc: ()=>tab_bar.btn_with_color_and_grabberText.checked = false exitFunc: ()=>tab_bar.btn_with_color_and_grabberText.checked = false
} }
RibbonTourItem{ RibbonTourItem{
title: QT_TRANSLATE_NOOP("RibbonTour", "CheckBoxs") title: qsTr("CheckBoxs")
text: QT_TRANSLATE_NOOP("RibbonTour", "CheckBoxs with colorful background or with/without label text.") text: qsTr("CheckBoxs with colorful background or with/without label text.")
target: tab_bar.checkbox_layout target: tab_bar.checkbox_layout
} }
RibbonTourItem{ RibbonTourItem{
title: QT_TRANSLATE_NOOP("RibbonTour", "Buttons") title: qsTr("Buttons")
text: QT_TRANSLATE_NOOP("RibbonTour", "Buttons with/without background or label text.") text: qsTr("Buttons with/without background or label text.")
target: tab_bar.button_layout target: tab_bar.button_layout
enterFunc: ()=>tab_bar.btn_without_bg_and_label.checked = true enterFunc: ()=>tab_bar.btn_without_bg_and_label.checked = true
exitFunc: ()=>tab_bar.btn_without_bg_and_label.checked = false exitFunc: ()=>tab_bar.btn_without_bg_and_label.checked = false
} }
RibbonTourItem{ RibbonTourItem{
title: QT_TRANSLATE_NOOP("RibbonTour", "Push Buttons") title: qsTr("Push Buttons")
text: QT_TRANSLATE_NOOP("RibbonTour", "Push buttons with/without sub menu.") text: qsTr("Push buttons with/without sub menu.")
target: tab_bar.pushbutton_layout target: tab_bar.pushbutton_layout
} }
RibbonTourItem{ RibbonTourItem{
title: QT_TRANSLATE_NOOP("RibbonTour", "Line Edits") title: qsTr("Line Edits")
text: QT_TRANSLATE_NOOP("RibbonTour", "Line edits with/without icon.") text: qsTr("Line edits with/without icon.")
target: tab_bar.lineedit_layout target: tab_bar.lineedit_layout
enterFunc: ()=>{ enterFunc: ()=>{
tab_bar.setPage(1) tab_bar.setPage(1)
@ -136,8 +136,8 @@ RibbonWindow {
} }
} }
RibbonTourItem{ RibbonTourItem{
title: QT_TRANSLATE_NOOP("RibbonTour", "Bottom Bar") title: qsTr("Bottom Bar")
text: QT_TRANSLATE_NOOP("RibbonTour", "A bottom bar for window.") text: qsTr("A bottom bar for window.")
target: bottom_bar target: bottom_bar
} }
target: windowItems target: windowItems
@ -375,42 +375,42 @@ RibbonWindow {
blurTarget: root.windowItems blurTarget: root.windowItems
radius: borderRadius radius: borderRadius
RibbonBackStageMenuItem{ RibbonBackStageMenuItem{
menuText: QT_TRANSLATE_NOOP("RibbonBackStageView","Home") menuText: qsTr("Home")
menuIcon: RibbonIcons.Home menuIcon: RibbonIcons.Home
type: RibbonBackStageView.MenuItemLocation.Head type: RibbonBackStageView.MenuItemLocation.Head
sourceComponent: t_content sourceComponent: t_content
sourceArgs:{'pageName':QT_TR_NOOP("Home")} sourceArgs:{'pageName':QT_TR_NOOP("Home")}
} }
RibbonBackStageMenuItem{ RibbonBackStageMenuItem{
menuText: QT_TRANSLATE_NOOP("RibbonBackStageView","File") menuText: qsTr("File")
menuIcon: RibbonIcons.Document menuIcon: RibbonIcons.Document
type: RibbonBackStageView.MenuItemLocation.Head type: RibbonBackStageView.MenuItemLocation.Head
sourceComponent: t_content sourceComponent: t_content
sourceArgs:{'pageName':QT_TR_NOOP("File")} sourceArgs:{'pageName':QT_TR_NOOP("File")}
} }
RibbonBackStageMenuItem{ RibbonBackStageMenuItem{
menuText: QT_TRANSLATE_NOOP("RibbonBackStageView","Search") menuText: qsTr("Search")
menuIcon: RibbonIcons.Search menuIcon: RibbonIcons.Search
type: RibbonBackStageView.MenuItemLocation.Body type: RibbonBackStageView.MenuItemLocation.Body
sourceComponent: t_content sourceComponent: t_content
sourceArgs:{'pageName':QT_TR_NOOP("Search")} sourceArgs:{'pageName':QT_TR_NOOP("Search")}
} }
RibbonBackStageMenuItem{ RibbonBackStageMenuItem{
menuText: QT_TRANSLATE_NOOP("RibbonBackStageView","Account") menuText: qsTr("Account")
menuIcon: RibbonIcons.PersonAccounts menuIcon: RibbonIcons.PersonAccounts
type: RibbonBackStageView.MenuItemLocation.Tail type: RibbonBackStageView.MenuItemLocation.Tail
clickOnly: true clickOnly: true
clickFunc: ()=>console.log("Menu Account clicked") clickFunc: ()=>console.log("Menu Account clicked")
} }
RibbonBackStageMenuItem{ RibbonBackStageMenuItem{
menuText: QT_TRANSLATE_NOOP("RibbonBackStageView","About") menuText: qsTr("About")
menuIcon: RibbonIcons.Info menuIcon: RibbonIcons.Info
type: RibbonBackStageView.MenuItemLocation.Tail type: RibbonBackStageView.MenuItemLocation.Tail
clickOnly: true clickOnly: true
clickFunc: ()=>root.showWindow(Qt.resolvedUrl("about.qml")) clickFunc: ()=>root.showWindow(Qt.resolvedUrl("about.qml"))
} }
RibbonBackStageMenuItem{ RibbonBackStageMenuItem{
menuText: QT_TRANSLATE_NOOP("RibbonBackStageView","Settings") menuText: qsTr("Settings")
menuIcon: RibbonIcons.Settings menuIcon: RibbonIcons.Settings
type: RibbonBackStageView.MenuItemLocation.Tail type: RibbonBackStageView.MenuItemLocation.Tail
sourceUrl: Qt.resolvedUrl("pages/SettingsMenuPage.qml") sourceUrl: Qt.resolvedUrl("pages/SettingsMenuPage.qml")

View File

@ -34,16 +34,7 @@ Window {
item.onDestroyed.connect(function(){ item.onDestroyed.connect(function(){
root.showLoadingLog.disconnect(item.dealWithLog) root.showLoadingLog.disconnect(item.dealWithLog)
}) })
if (!Object.keys(container.args).length) loadItemArgs()
return
else if(Object.keys(container.args).length){
for (let arg in container.args){
item[arg] = container.args[arg]
}
}
else{
console.error("RibbonSplashScreen: Arguments error, please check.")
}
} }
onStatusChanged: { onStatusChanged: {
if(status === Loader.Null && if(status === Loader.Null &&
@ -153,4 +144,19 @@ Window {
internal.isComponentReady = true internal.isComponentReady = true
} }
} }
function loadItemArgs(){
if(loader.item){
if (!Object.keys(container.args).length)
return
else if(Object.keys(container.args).length){
for (let arg in container.args){
loader.item[arg] = container.args[arg]
}
}
else{
console.error("RibbonSplashScreen: Arguments error, please check.")
}
}
}
} }

View File

@ -34,16 +34,7 @@ Window {
item.onDestroyed.connect(function(){ item.onDestroyed.connect(function(){
root.showLoadingLog.disconnect(item.dealWithLog) root.showLoadingLog.disconnect(item.dealWithLog)
}) })
if (!Object.keys(container.args).length) loadItemArgs()
return
else if(Object.keys(container.args).length){
for (let arg in container.args){
item[arg] = container.args[arg]
}
}
else{
console.error("RibbonSplashScreen: Arguments error, please check.")
}
} }
onStatusChanged: { onStatusChanged: {
if(status === Loader.Null && if(status === Loader.Null &&
@ -153,4 +144,19 @@ Window {
internal.isComponentReady = true internal.isComponentReady = true
} }
} }
function loadItemArgs(){
if(loader.item){
if (!Object.keys(container.args).length)
return
else if(Object.keys(container.args).length){
for (let arg in container.args){
loader.item[arg] = container.args[arg]
}
}
else{
console.error("RibbonSplashScreen: Arguments error, please check.")
}
}
}
} }