找回密码
 立即注册
收起左侧

QML 国际化的问题

0
回复
2910
查看
[复制链接]
累计签到:1 天
连续签到:1 天
来源: 2021-12-28 22:00:29 显示全部楼层 |阅读模式
1Qter豆

网上有很多关于QT 国际化处理的例子,我也按照流程实现了简单的动态翻译,

但发现个问题:
当我增加一个Button,在单击Button,修改Text显示的内容后,Text内容的翻译就无效了,有知道该怎么做才能在单击Button后也能正常翻译吗?难道QT只能对静态的字符进行翻译吗?


import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
   property string name: QT_TRID_NOOP("HELLO")
    Rectangle{
        id:page1
        anchors.fill: parent
        Text{
            id:label1
            anchors.centerIn: parent
            text: qsTr("第1页")
        }

        Button{
            text: "更新"
            onClicked:label1.text = qsTr("按下按键")
        }

        Button{
            text: "中文"
            anchors.bottom: parent.bottom
            anchors.left: parent.left
            onClicked: translator.loadLanguage("Chinese");
        }
        Button{
            text: "English"
            anchors.bottom: parent.bottom
            anchors.right: parent.right
            onClicked: {
                translator.loadLanguage("English");
            }
        }

    }
}


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了