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 2.0 Rectangle { id: root color: "#e8edea" Column { anchors.fill: parent spacing: 14 Text { topPadding: 8 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 case "ar_SA": lang = " العربية"; break case "th_TH": lang = "ไทย"; break } return " Current language: " + lang } } Row { spacing: 30 Item {} // dummy for spacing Image { width: root.width * 0.25 height: root.height * 0.25 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"; case "ar_SA": return "saudi-arabia-flag-small.png"; case "th_TH": return "thai-flag-small.png"; default: return "usa-flag-small.png"; } } } } Row { spacing: 30 width: parent.width // dummy item for spacing at the beginning Item {} Column { Text { id: staticTextItemsTitle text: "StaticText items" } StaticText { width: staticTextItemsTitle.width text: qsTr("orange", "color") } StaticText { width: staticTextItemsTitle.width text: qsTr("orange", "fruit") } StaticText { width: staticTextItemsTitle.width text: qsTr("apple") } StaticText { width: staticTextItemsTitle.width text: qsTr("hello") } } Column { Text { id: textItemsTitle text: "Text items" } Text { width: textItemsTitle.width text: qsTr("orange", "color") } Text { width: textItemsTitle.width text: qsTr("orange", "fruit") } Text { width: textItemsTitle.width text: qsTr("apple") } Text { width: textItemsTitle.width // This string is not translated in the .ts files and // will just fall back to the source string. 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 = "ar_SA"; break; case "ar_SA": lang = "th_TH"; break; case "th_TH": lang = ""; break; default: lang = "nb_NO"; break; } Qt.uiLanguage = lang } } }