2 * Copyright (C) 2018 The UBports project
3 * Copyright (C) 2013-2016 Canonical Ltd.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19import Lomiri.Components 1.3
20import Lomiri.Components.ListItems 1.3
21import Lomiri.SystemSettings.LanguagePlugin 1.0
23import ".." as LocalComponents
24import "../../Components"
27 objectName: "languagePage"
29 title: i18n.tr("Language")
30 forwardButtonSourceComponent: forwardButton
34 LomiriLanguagePlugin {
38 OnScreenKeyboardPlugin {
44 var detectedLang = "";
45 // try to detect the language+country from the SIM card
46 if (root.simManager0.present && root.simManager0.preferredLanguages.length > 0) {
47 detectedLang = root.simManager0.preferredLanguages[0] + "_" + LocalePlugin.mccToCountryCode(root.simManager0.mobileCountryCode);
48 } else if (root.simManager1.present && root.simManager1.preferredLanguages.length > 0) {
49 detectedLang = root.simManager1.preferredLanguages[0] + "_" + LocalePlugin.mccToCountryCode(root.simManager1.mobileCountryCode);
50 } else if (plugin.currentLanguage != -1) {
51 detectedLang = plugin.languageCodes[plugin.currentLanguage].split(".")[0]; // remove the encoding part, after dot (en_US.utf8 -> en_US)
53 detectedLang = "en_US"; // fallback to default lang
56 // preselect the detected language
57 for (var i = 0; i < plugin.languageCodes.length; i++) {
58 var code = plugin.languageCodes[i].split(".")[0]; // remove the encoding part, after dot (en_US.utf8 -> en_US)
59 if (detectedLang === code) {
60 languagesListView.currentIndex = i;
61 languagesListView.positionViewAtIndex(i, ListView.Center);
62 i18n.language = plugin.languageCodes[i];
68 function applyOSKSettings(locale) {
69 var language = locale.split("_")[0].split(".")[0];
70 var oskLanguage = language;
72 if (language === "zh") { // special case for Chinese, select either simplified or traditional
73 if (locale.substr(0, 5) === "zh_CN" || locale.substr(0,5) === "zh_SG") {
74 oskLanguage = "zh-hans"; // Chinese Simplified
76 oskLanguage = "zh-hant"; // Chinese Traditional
80 oskPlugin.setCurrentLayout(oskLanguage);
83 // splash screen (this has to be on the first page)
86 anchors.top: parent.top
87 anchors.left: parent.left
88 anchors.right: parent.right
90 source: wideMode ? "data/Desktop_splash_screen_bkg.png" : "data/Phone_splash_screen_bkg.png"
91 fillMode: Image.PreserveAspectCrop
94 Component.onCompleted: splashAnimation.start()
99 PauseAnimation { duration: LomiriAnimation.BriskDuration }
104 duration: LomiriAnimation.BriskDuration
116 id: languagesListView
117 objectName: "languagesListView"
119 snapMode: ListView.SnapToItem
123 leftMargin: wideMode ? parent.leftMargin : 0
124 rightMargin: wideMode ? parent.rightMargin : 0
125 topMargin: wideMode ? parent.customMargin : 0
128 model: plugin.languageNames
132 objectName: "languageDelegate_" + langLabel.text.toLowerCase().replace(/\s+/g, '_')
133 highlightColor: backgroundColor
134 divider.colorFrom: dividerColor
135 divider.colorTo: backgroundColor
136 readonly property bool isCurrent: index === ListView.view.currentIndex
144 verticalCenter: parent.verticalCenter
145 leftMargin: languagesListView.anchors.leftMargin == 0 ? staticMargin : 0
149 font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
156 verticalCenter: parent.verticalCenter;
157 rightMargin: languagesListView.anchors.rightMargin == 0 ? staticMargin : 0
159 fillMode: Image.PreserveAspectFit
160 height: units.gu(1.5)
162 source: "data/Tick@30.png"
163 visible: itemDelegate.isCurrent
167 languagesListView.currentIndex = index;
168 i18n.language = plugin.languageCodes[index];
175 LocalComponents.StackButton {
176 text: i18n.tr("Next")
177 enabled: languagesListView.currentIndex != -1
179 if (plugin.currentLanguage !== languagesListView.currentIndex) {
180 var locale = plugin.languageCodes[languagesListView.currentIndex];
181 plugin.currentLanguage = languagesListView.currentIndex;
182 applyOSKSettings(locale);
183 System.updateSessionLocale(locale);
185 i18n.language = plugin.languageCodes[plugin.currentLanguage]; // re-notify of change after above call (for qlocale change)
187 if (!root.modemManager.available || !root.modemManager.ready || root.modemManager.modems.length === 0 ||
188 (root.simManager0.present && root.simManager0.ready) || (root.simManager1.present && root.simManager1.ready) ||
189 root.seenSIMPage) { // go to next page
192 pageStack.load(Qt.resolvedUrl("sim.qml")); // show the SIM page