wang12zhe 发表于 2021-12-28 22:00:29

QML 国际化的问题


网上有很多关于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");
            }
      }

    }
}


页: [1]
查看完整版本: QML 国际化的问题