diff --git a/example/example.qrc b/example/example.qrc
index daa59ed7..c012e353 100644
--- a/example/example.qrc
+++ b/example/example.qrc
@@ -189,5 +189,6 @@
qml/page/T_Clip.qml
qml/page/T_3D.qml
res/obj/test.obj
+ qml/global/Lang.qml
diff --git a/example/qml-Qt6/global/ItemsFooter.qml b/example/qml-Qt6/global/ItemsFooter.qml
index 80c2fb7c..4a2fdf01 100644
--- a/example/qml-Qt6/global/ItemsFooter.qml
+++ b/example/qml-Qt6/global/ItemsFooter.qml
@@ -2,6 +2,7 @@ pragma Singleton
import QtQuick
import FluentUI
+import "qrc:///example/qml/global"
FluObject{
@@ -12,7 +13,7 @@ FluObject{
FluPaneItemSeparator{}
FluPaneItem{
- title:lang.about
+ title:Lang.about
icon:FluentIcons.Contact
onDropped: { FluApp.navigate("/about") }
onTapListener:function(){
@@ -21,7 +22,7 @@ FluObject{
}
FluPaneItem{
- title:lang.settings
+ title:Lang.settings
icon:FluentIcons.Settings
url:"qrc:/example/qml/page/T_Settings.qml"
onDropped:{ FluApp.navigate("/pageWindow",{title:title,url:url}) }
diff --git a/example/qml-Qt6/global/ItemsOriginal.qml b/example/qml-Qt6/global/ItemsOriginal.qml
index 5110514e..b9e3d3bc 100644
--- a/example/qml-Qt6/global/ItemsOriginal.qml
+++ b/example/qml-Qt6/global/ItemsOriginal.qml
@@ -2,6 +2,7 @@ pragma Singleton
import QtQuick
import FluentUI
+import "qrc:///example/qml/global"
FluObject{
@@ -16,7 +17,7 @@ FluObject{
FluPaneItem{
id:item_home
count: 9
- title:lang.home
+ title:Lang.home
infoBadge:FluBadge{
count: item_home.count
}
@@ -47,7 +48,7 @@ FluObject{
FluPaneItemExpander{
id:item_expander_basic_input
- title:lang.basic_input
+ title:Lang.basic_input
icon:FluentIcons.CheckboxComposite
editDelegate: FluTextBox{
text:item_expander_basic_input.title
@@ -137,7 +138,7 @@ FluObject{
}
FluPaneItemExpander{
- title:lang.form
+ title:Lang.form
icon:FluentIcons.GridView
FluPaneItem{
title:"TextBox"
@@ -172,7 +173,7 @@ FluObject{
}
FluPaneItemExpander{
- title:lang.surface
+ title:Lang.surface
icon:FluentIcons.SurfaceHub
FluPaneItem{
title:"InfoBar"
@@ -246,7 +247,7 @@ FluObject{
}
FluPaneItemExpander{
- title:lang.popus
+ title:Lang.popus
icon:FluentIcons.ButtonMenu
FluPaneItem{
title:"Dialog"
@@ -284,7 +285,7 @@ FluObject{
}
FluPaneItemExpander{
- title:lang.navigation
+ title:Lang.navigation
icon:FluentIcons.AllApps
FluPaneItem{
title:"Pivot"
@@ -353,7 +354,7 @@ FluObject{
}
FluPaneItemExpander{
- title:lang.theming
+ title:Lang.theming
icon:FluentIcons.Brightness
FluPaneItem{
title:"Acrylic"
@@ -393,7 +394,7 @@ FluObject{
}
FluPaneItemExpander{
- title:lang.other
+ title:Lang.other
icon:FluentIcons.Shop
FluPaneItem{
title:"QRCode"
diff --git a/example/qml-Qt6/global/Lang.qml b/example/qml-Qt6/global/Lang.qml
new file mode 100644
index 00000000..219aaa8d
--- /dev/null
+++ b/example/qml-Qt6/global/Lang.qml
@@ -0,0 +1,77 @@
+pragma Singleton
+
+import QtQuick
+
+QtObject {
+
+ property string home
+ property string basic_input
+ property string form
+ property string surface
+ property string popus
+ property string navigation
+ property string theming
+ property string media
+ property string dark_mode
+ property string sys_dark_mode
+ property string search
+ property string about
+ property string settings
+ property string locale
+ property string navigation_view_display_mode
+ property string other
+
+ function zh(){
+ home="首页"
+ basic_input="基本输入"
+ form="表单"
+ surface="表面"
+ popus="弹窗"
+ navigation="导航"
+ theming="主题"
+ media="媒体"
+ dark_mode="夜间模式"
+ sys_dark_mode="跟随系统"
+ search="查找"
+ about="关于"
+ settings="设置"
+ locale="语言环境"
+ navigation_view_display_mode="导航视图显示模式"
+ other="其他"
+ }
+
+ function en(){
+ home="Home"
+ basic_input="Basic Input"
+ form="Form"
+ surface="Surfaces"
+ popus="Popus"
+ navigation="Navigation"
+ theming="Theming"
+ media="Media"
+ dark_mode="Dark Mode"
+ sys_dark_mode="Sync with system"
+ search="Search"
+ about="About"
+ settings="Settings"
+ locale="Locale"
+ navigation_view_display_mode="NavigationView Display Mode"
+ other="Other"
+ }
+
+ property string __locale
+ property var __localeList: ["Zh","En"]
+
+ on__LocaleChanged: {
+ if(__locale === "Zh"){
+ zh()
+ }else{
+ en()
+ }
+ }
+
+ Component.onCompleted: {
+ __locale = "En"
+ }
+
+}
diff --git a/example/qml-Qt6/global/qmldir b/example/qml-Qt6/global/qmldir
index eb6bfeaf..cc5287d7 100644
--- a/example/qml-Qt6/global/qmldir
+++ b/example/qml-Qt6/global/qmldir
@@ -1,2 +1,3 @@
singleton ItemsOriginal 1.0 ItemsOriginal.qml
singleton ItemsFooter 1.0 ItemsFooter.qml
+singleton Lang 1.0 Lang.qml
diff --git a/example/qml-Qt6/page/T_Settings.qml b/example/qml-Qt6/page/T_Settings.qml
index aecef5c2..1dd35fc4 100644
--- a/example/qml-Qt6/page/T_Settings.qml
+++ b/example/qml-Qt6/page/T_Settings.qml
@@ -101,7 +101,7 @@ FluScrollablePage{
left: parent.left
}
FluText{
- text:lang.dark_mode
+ text:Lang.dark_mode
font: FluTextStyle.BodyStrong
Layout.bottomMargin: 4
}
@@ -131,7 +131,7 @@ FluScrollablePage{
left: parent.left
}
FluText{
- text:lang.navigation_view_display_mode
+ text:Lang.navigation_view_display_mode
font: FluTextStyle.BodyStrong
Layout.bottomMargin: 4
}
@@ -162,7 +162,7 @@ FluScrollablePage{
}
FluText{
- text:lang.locale
+ text:Lang.locale
font: FluTextStyle.BodyStrong
Layout.bottomMargin: 4
}
@@ -170,12 +170,12 @@ FluScrollablePage{
Flow{
spacing: 5
Repeater{
- model: ["Zh","En"]
+ model: Lang.__localeList
delegate: FluRadioButton{
- checked: AppInfo.lang.objectName === modelData
+ checked: Lang.__locale === modelData
text:modelData
clickListener:function(){
- AppInfo.changeLang(modelData)
+ Lang.__locale = modelData
}
}
}
diff --git a/example/qml-Qt6/window/MainWindow.qml b/example/qml-Qt6/window/MainWindow.qml
index c5df0ed7..bf56c5d5 100644
--- a/example/qml-Qt6/window/MainWindow.qml
+++ b/example/qml-Qt6/window/MainWindow.qml
@@ -38,8 +38,8 @@ FluWindow {
checkUpdate(false)
}
}
-
Component.onCompleted: {
+ console.debug(Lang.about)
FluTools.setQuitOnLastWindowClosed(false)
tour.open()
checkUpdate(true)
@@ -119,7 +119,7 @@ FluWindow {
left: parent.left
right: parent.right
}
- darkText: lang.dark_mode
+ darkText: Lang.dark_mode
showDark: true
z:7
darkClickListener:(button)=>handleDarkChanged(button)
@@ -169,7 +169,7 @@ FluWindow {
left: parent.left
right: parent.right
}
- darkText: lang.dark_mode
+ darkText: Lang.dark_mode
showDark: true
darkClickListener:(button)=>handleDarkChanged(button)
z:7
@@ -202,7 +202,7 @@ FluWindow {
autoSuggestBox:FluAutoSuggestBox{
iconSource: FluentIcons.Search
items: ItemsOriginal.getSearchData()
- placeholderText: lang.search
+ placeholderText: Lang.search
onItemClicked:
(data)=>{
ItemsOriginal.startPageByItem(data)
diff --git a/example/qml/global/ItemsFooter.qml b/example/qml/global/ItemsFooter.qml
index 5ea2f91b..0e6b3cf8 100644
--- a/example/qml/global/ItemsFooter.qml
+++ b/example/qml/global/ItemsFooter.qml
@@ -2,6 +2,7 @@ pragma Singleton
import QtQuick 2.15
import FluentUI 1.0
+import "qrc:///example/qml/global"
FluObject{
@@ -12,7 +13,7 @@ FluObject{
FluPaneItemSeparator{}
FluPaneItem{
- title:lang.about
+ title:Lang.about
icon:FluentIcons.Contact
onDropped: { FluApp.navigate("/about") }
onTapListener:function(){
@@ -21,7 +22,7 @@ FluObject{
}
FluPaneItem{
- title:lang.settings
+ title:Lang.settings
icon:FluentIcons.Settings
url:"qrc:/example/qml/page/T_Settings.qml"
onDropped:{ FluApp.navigate("/pageWindow",{title:title,url:url}) }
diff --git a/example/qml/global/ItemsOriginal.qml b/example/qml/global/ItemsOriginal.qml
index da02f419..36ae30e2 100644
--- a/example/qml/global/ItemsOriginal.qml
+++ b/example/qml/global/ItemsOriginal.qml
@@ -2,6 +2,7 @@ pragma Singleton
import QtQuick 2.15
import FluentUI 1.0
+import "qrc:///example/qml/global"
FluObject{
@@ -16,7 +17,7 @@ FluObject{
FluPaneItem{
id:item_home
count: 9
- title:lang.home
+ title:Lang.home
infoBadge:FluBadge{
count: item_home.count
}
@@ -47,7 +48,7 @@ FluObject{
FluPaneItemExpander{
id:item_expander_basic_input
- title:lang.basic_input
+ title:Lang.basic_input
icon:FluentIcons.CheckboxComposite
editDelegate: FluTextBox{
text:item_expander_basic_input.title
@@ -137,7 +138,7 @@ FluObject{
}
FluPaneItemExpander{
- title:lang.form
+ title:Lang.form
icon:FluentIcons.GridView
FluPaneItem{
title:"TextBox"
@@ -172,7 +173,7 @@ FluObject{
}
FluPaneItemExpander{
- title:lang.surface
+ title:Lang.surface
icon:FluentIcons.SurfaceHub
FluPaneItem{
title:"InfoBar"
@@ -246,7 +247,7 @@ FluObject{
}
FluPaneItemExpander{
- title:lang.popus
+ title:Lang.popus
icon:FluentIcons.ButtonMenu
FluPaneItem{
title:"Dialog"
@@ -284,7 +285,7 @@ FluObject{
}
FluPaneItemExpander{
- title:lang.navigation
+ title:Lang.navigation
icon:FluentIcons.AllApps
FluPaneItem{
title:"Pivot"
@@ -353,7 +354,7 @@ FluObject{
}
FluPaneItemExpander{
- title:lang.theming
+ title:Lang.theming
icon:FluentIcons.Brightness
FluPaneItem{
title:"Acrylic"
@@ -393,7 +394,7 @@ FluObject{
}
FluPaneItemExpander{
- title:lang.other
+ title:Lang.other
icon:FluentIcons.Shop
FluPaneItem{
title:"QRCode"
diff --git a/example/qml/global/Lang.qml b/example/qml/global/Lang.qml
new file mode 100644
index 00000000..08e90461
--- /dev/null
+++ b/example/qml/global/Lang.qml
@@ -0,0 +1,77 @@
+pragma Singleton
+
+import QtQuick 2.15
+
+QtObject {
+
+ property string home
+ property string basic_input
+ property string form
+ property string surface
+ property string popus
+ property string navigation
+ property string theming
+ property string media
+ property string dark_mode
+ property string sys_dark_mode
+ property string search
+ property string about
+ property string settings
+ property string locale
+ property string navigation_view_display_mode
+ property string other
+
+ function zh(){
+ home="首页"
+ basic_input="基本输入"
+ form="表单"
+ surface="表面"
+ popus="弹窗"
+ navigation="导航"
+ theming="主题"
+ media="媒体"
+ dark_mode="夜间模式"
+ sys_dark_mode="跟随系统"
+ search="查找"
+ about="关于"
+ settings="设置"
+ locale="语言环境"
+ navigation_view_display_mode="导航视图显示模式"
+ other="其他"
+ }
+
+ function en(){
+ home="Home"
+ basic_input="Basic Input"
+ form="Form"
+ surface="Surfaces"
+ popus="Popus"
+ navigation="Navigation"
+ theming="Theming"
+ media="Media"
+ dark_mode="Dark Mode"
+ sys_dark_mode="Sync with system"
+ search="Search"
+ about="About"
+ settings="Settings"
+ locale="Locale"
+ navigation_view_display_mode="NavigationView Display Mode"
+ other="Other"
+ }
+
+ property string __locale
+ property var __localeList: ["Zh","En"]
+
+ on__LocaleChanged: {
+ if(__locale === "Zh"){
+ zh()
+ }else{
+ en()
+ }
+ }
+
+ Component.onCompleted: {
+ __locale = "En"
+ }
+
+}
diff --git a/example/qml/global/qmldir b/example/qml/global/qmldir
index eb6bfeaf..cc5287d7 100644
--- a/example/qml/global/qmldir
+++ b/example/qml/global/qmldir
@@ -1,2 +1,3 @@
singleton ItemsOriginal 1.0 ItemsOriginal.qml
singleton ItemsFooter 1.0 ItemsFooter.qml
+singleton Lang 1.0 Lang.qml
diff --git a/example/qml/page/T_Settings.qml b/example/qml/page/T_Settings.qml
index 6d28ff9c..3c28ad86 100644
--- a/example/qml/page/T_Settings.qml
+++ b/example/qml/page/T_Settings.qml
@@ -104,7 +104,7 @@ FluScrollablePage{
left: parent.left
}
FluText{
- text:lang.dark_mode
+ text:Lang.dark_mode
font: FluTextStyle.BodyStrong
Layout.bottomMargin: 4
}
@@ -134,7 +134,7 @@ FluScrollablePage{
left: parent.left
}
FluText{
- text:lang.navigation_view_display_mode
+ text:Lang.navigation_view_display_mode
font: FluTextStyle.BodyStrong
Layout.bottomMargin: 4
}
@@ -165,7 +165,7 @@ FluScrollablePage{
}
FluText{
- text:lang.locale
+ text:Lang.locale
font: FluTextStyle.BodyStrong
Layout.bottomMargin: 4
}
@@ -173,12 +173,12 @@ FluScrollablePage{
Flow{
spacing: 5
Repeater{
- model: ["Zh","En"]
+ model: Lang.__localeList
delegate: FluRadioButton{
- checked: AppInfo.lang.objectName === modelData
+ checked: Lang.__locale === modelData
text:modelData
clickListener:function(){
- AppInfo.changeLang(modelData)
+ Lang.__locale = modelData
}
}
}
diff --git a/example/qml/window/MainWindow.qml b/example/qml/window/MainWindow.qml
index a6b2f407..46685b7d 100644
--- a/example/qml/window/MainWindow.qml
+++ b/example/qml/window/MainWindow.qml
@@ -121,7 +121,7 @@ FluWindow {
left: parent.left
right: parent.right
}
- darkText: lang.dark_mode
+ darkText: Lang.dark_mode
showDark: true
z:7
darkClickListener:(button)=>handleDarkChanged(button)
@@ -171,7 +171,7 @@ FluWindow {
left: parent.left
right: parent.right
}
- darkText: lang.dark_mode
+ darkText: Lang.dark_mode
showDark: true
darkClickListener:(button)=>handleDarkChanged(button)
z:7
@@ -204,7 +204,7 @@ FluWindow {
autoSuggestBox:FluAutoSuggestBox{
iconSource: FluentIcons.Search
items: ItemsOriginal.getSearchData()
- placeholderText: lang.search
+ placeholderText: Lang.search
onItemClicked:
(data)=>{
ItemsOriginal.startPageByItem(data)
diff --git a/example/src/AppInfo.cpp b/example/src/AppInfo.cpp
index d833609f..f6a270fb 100644
--- a/example/src/AppInfo.cpp
+++ b/example/src/AppInfo.cpp
@@ -3,35 +3,14 @@
#include
#include
#include
-#include "lang/En.h"
-#include "lang/Zh.h"
#include "Version.h"
AppInfo::AppInfo(QObject *parent)
: QObject{parent}
{
version(APPLICATION_VERSION);
- lang(new En());
}
void AppInfo::init(QQmlApplicationEngine *engine){
- QQmlContext * context = engine->rootContext();
- Lang* lang = this->lang();
- context->setContextProperty("lang",lang);
- QObject::connect(this,&AppInfo::langChanged,this,[=]{
- context->setContextProperty("lang",this->lang());
- });
-}
-
-void AppInfo::changeLang(const QString& locale){
- if(_lang){
- _lang->deleteLater();
- }
- if(locale=="Zh"){
- lang(new Zh());
- }else if(locale=="En"){
- lang(new En());
- }else {
- lang(new En());
- }
+ engine->rootContext();
}
diff --git a/example/src/AppInfo.h b/example/src/AppInfo.h
index 647fee8e..c4a5024f 100644
--- a/example/src/AppInfo.h
+++ b/example/src/AppInfo.h
@@ -3,7 +3,6 @@
#include
#include
-#include "lang/Lang.h"
#include "stdafx.h"
#include "singleton.h"
@@ -11,13 +10,11 @@ class AppInfo : public QObject
{
Q_OBJECT
Q_PROPERTY_AUTO(QString,version)
- Q_PROPERTY_AUTO(Lang*,lang)
private:
explicit AppInfo(QObject *parent = nullptr);
public:
SINGLETONG(AppInfo)
void init(QQmlApplicationEngine *engine);
- Q_INVOKABLE void changeLang(const QString& locale);
};
#endif // APPINFO_H
diff --git a/example/src/lang/En.cpp b/example/src/lang/En.cpp
deleted file mode 100644
index a24f08cb..00000000
--- a/example/src/lang/En.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "En.h"
-
-En::En(QObject *parent)
- : Lang{parent}
-{
- setObjectName("En");
- home("Home");
- basic_input("Basic Input");
- form("Form");
- surface("Surfaces");
- popus("Popus");
- navigation("Navigation");
- theming("Theming");
- media("Media");
- dark_mode("Dark Mode");
- sys_dark_mode("Sync with system");
- search("Search");
- about("About");
- settings("Settings");
- locale("Locale");
- navigation_view_display_mode("NavigationView Display Mode");
- other("Other");
-}
diff --git a/example/src/lang/En.h b/example/src/lang/En.h
deleted file mode 100644
index 9f79cd91..00000000
--- a/example/src/lang/En.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef EN_H
-#define EN_H
-
-#include
-#include "Lang.h"
-
-class En : public Lang
-{
- Q_OBJECT
-public:
- explicit En(QObject *parent = nullptr);
-
-signals:
-
-};
-
-#endif // EN_H
diff --git a/example/src/lang/Lang.cpp b/example/src/lang/Lang.cpp
deleted file mode 100644
index 396fb305..00000000
--- a/example/src/lang/Lang.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "Lang.h"
-
-Lang::Lang(QObject *parent)
- : QObject{parent}
-{
-
-}
diff --git a/example/src/lang/Lang.h b/example/src/lang/Lang.h
deleted file mode 100644
index ae44d45e..00000000
--- a/example/src/lang/Lang.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef LANG_H
-#define LANG_H
-
-#include
-#include "../stdafx.h"
-
-class Lang : public QObject
-{
- Q_OBJECT
- Q_PROPERTY_AUTO(QString,home);
- Q_PROPERTY_AUTO(QString,basic_input);
- Q_PROPERTY_AUTO(QString,form);
- Q_PROPERTY_AUTO(QString,surface);
- Q_PROPERTY_AUTO(QString,popus);
- Q_PROPERTY_AUTO(QString,navigation);
- Q_PROPERTY_AUTO(QString,theming);
- Q_PROPERTY_AUTO(QString,media);
- Q_PROPERTY_AUTO(QString,dark_mode);
- Q_PROPERTY_AUTO(QString,sys_dark_mode);
- Q_PROPERTY_AUTO(QString,search);
- Q_PROPERTY_AUTO(QString,about);
- Q_PROPERTY_AUTO(QString,settings);
- Q_PROPERTY_AUTO(QString,navigation_view_display_mode);
- Q_PROPERTY_AUTO(QString,locale);
- Q_PROPERTY_AUTO(QString,other);
-public:
- explicit Lang(QObject *parent = nullptr);
-
-};
-
-#endif // LANG_H
diff --git a/example/src/lang/Zh.cpp b/example/src/lang/Zh.cpp
deleted file mode 100644
index 276d4a8e..00000000
--- a/example/src/lang/Zh.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "Zh.h"
-
-Zh::Zh(QObject *parent)
- : Lang{parent}
-{
- setObjectName("Zh");
- home("首页");
- basic_input("基本输入");
- form("表单");
- surface("表面");
- popus("弹窗");
- navigation("导航");
- theming("主题");
- media("媒体");
- dark_mode("夜间模式");
- sys_dark_mode("跟随系统");
- search("查找");
- about("关于");
- settings("设置");
- locale("语言环境");
- navigation_view_display_mode("导航视图显示模式");
- other("其他");
-}
diff --git a/example/src/lang/Zh.h b/example/src/lang/Zh.h
deleted file mode 100644
index 0074bc98..00000000
--- a/example/src/lang/Zh.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef ZH_H
-#define ZH_H
-
-#include
-#include "Lang.h"
-
-class Zh : public Lang
-{
- Q_OBJECT
-public:
- explicit Zh(QObject *parent = nullptr);
-
-signals:
-
-};
-
-#endif // ZH_H