C

Qt Quick Ultralite translation Example

/****************************************************************************** ** ** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/
import QtQuick 2.15 import QtQuickUltralite.Extras 1.2 Rectangle { id: root color: "#e8edea" width: 400 height: 400 Column { anchors.fill: parent spacing: 20 Text { text: { var lang = "English (US)" switch (Qt.uiLanguage) { case "lv_LV": lang = "Latviešu"; break case "nb_NO": lang = "Norsk"; break case "ja_JP": lang = "日本語"; break } return "current lang: " + lang } } Image { width: root.width height: root.height / 2 source: { switch (Qt.uiLanguage) { case "lv_LV": return "latvia-flag-small.png" case "nb_NO": return "norway-flag-small.png"; case "ja_JP": return "japan-flag-small.png"; default: return "usa-flag-small.png"; } } } Row { spacing: 20 Column { width: root.width / 2 Text { text: "Text {}" } Text { text: qsTr("orange", "color") } Text { text: qsTr("orange", "fruit") } Text { text: qsTr("apple") } Text { // This string is not translated in the .ts files and // will just fall back to the source string. text: qsTr("hello") } } Column { Text { text: "StaticText {}" } StaticText { text: qsTr("orange", "color") } StaticText { text: qsTr("orange", "fruit") } StaticText { text: qsTr("apple") } StaticText { text: qsTr("hello") } } } } property bool allowLangSwitch : true // Disable language switching when this is compiled with // a single language. Component.onCompleted: allowLangSwitch = (Qt.uiLanguage == "") MouseArea { anchors.fill: parent onClicked: { if (!root.allowLangSwitch) return var lang = Qt.uiLanguage switch (lang) { case "nb_NO": lang = "lv_LV"; break; case "lv_LV": lang = "ja_JP"; break; case "ja_JP": lang = ""; break; default: lang = "nb_NO"; break; } Qt.uiLanguage = lang } } }