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 // Skip language autodetection when upgrading, since user probably want
45 // to retain the current language.
46 // Preferably this page shouldn't have to be loaded in that case, but at
47 // the moment it still has to be loaded, to determine `onlyOnInstall`
52 var detectedLang = "";
53 // try to detect the language+country from the SIM card
54 if (root.simManager0.present && root.simManager0.preferredLanguages.length > 0) {
55 detectedLang = root.simManager0.preferredLanguages[0] + "_" + LocalePlugin.mccToCountryCode(root.simManager0.mobileCountryCode);
56 } else if (root.simManager1.present && root.simManager1.preferredLanguages.length > 0) {
57 detectedLang = root.simManager1.preferredLanguages[0] + "_" + LocalePlugin.mccToCountryCode(root.simManager1.mobileCountryCode);
58 } else if (plugin.currentLanguage != -1) {
59 detectedLang = plugin.languageCodes[plugin.currentLanguage].split(".")[0]; // remove the encoding part, after dot (en_US.utf8 -> en_US)
61 detectedLang = "en_US"; // fallback to default lang
64 // preselect the detected language
65 for (var i = 0; i < plugin.languageCodes.length; i++) {
66 var code = plugin.languageCodes[i].split(".")[0]; // remove the encoding part, after dot (en_US.utf8 -> en_US)
67 if (detectedLang === code) {
68 languagesListView.currentIndex = i;
69 languagesListView.positionViewAtIndex(i, ListView.Center);
70 i18n.language = plugin.languageCodes[i];
76 function applyOSKSettings(locale) {
77 var language = locale.split("_")[0].split(".")[0];
78 var oskLanguage = language;
80 if (language === "zh") { // special case for Chinese, select either simplified or traditional
81 if (locale.substr(0, 5) === "zh_CN" || locale.substr(0,5) === "zh_SG") {
82 oskLanguage = "zh-hans"; // Chinese Simplified
84 oskLanguage = "zh-hant"; // Chinese Traditional
88 oskPlugin.setCurrentLayout(oskLanguage);
91 // splash screen (this has to be on the first page)
94 anchors.top: parent.top
95 anchors.left: parent.left
96 anchors.right: parent.right
98 source: wideMode ? "data/Desktop_splash_screen_bkg.png" : "data/Phone_splash_screen_bkg.png"
99 fillMode: Image.PreserveAspectCrop
102 Component.onCompleted: splashAnimation.start()
105 SequentialAnimation {
107 PauseAnimation { duration: LomiriAnimation.BriskDuration }
112 duration: LomiriAnimation.BriskDuration
124 id: languagesListView
125 objectName: "languagesListView"
127 snapMode: ListView.SnapToItem
131 leftMargin: wideMode ? parent.leftMargin : 0
132 rightMargin: wideMode ? parent.rightMargin : 0
133 topMargin: wideMode ? parent.customMargin : 0
136 model: plugin.languageNames
140 objectName: "languageDelegate_" + langLabel.text.toLowerCase().replace(/\s+/g, '_')
141 highlightColor: backgroundColor
142 divider.colorFrom: dividerColor
143 divider.colorTo: backgroundColor
144 readonly property bool isCurrent: index === ListView.view.currentIndex
152 verticalCenter: parent.verticalCenter
153 leftMargin: languagesListView.anchors.leftMargin == 0 ? staticMargin : 0
157 font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
164 verticalCenter: parent.verticalCenter;
165 rightMargin: languagesListView.anchors.rightMargin == 0 ? staticMargin : 0
167 fillMode: Image.PreserveAspectFit
168 height: units.gu(1.5)
170 source: "data/Tick@30.png"
171 visible: itemDelegate.isCurrent
175 languagesListView.currentIndex = index;
176 i18n.language = plugin.languageCodes[index];
183 LocalComponents.StackButton {
184 text: i18n.tr("Next")
185 enabled: languagesListView.currentIndex != -1
187 if (plugin.currentLanguage !== languagesListView.currentIndex) {
188 var locale = plugin.languageCodes[languagesListView.currentIndex];
189 plugin.currentLanguage = languagesListView.currentIndex;
190 applyOSKSettings(locale);
191 System.updateSessionLocale(locale);
193 i18n.language = plugin.languageCodes[plugin.currentLanguage]; // re-notify of change after above call (for qlocale change)
195 if (!root.modemManager.available || !root.modemManager.ready || root.modemManager.modems.length === 0 ||
196 (root.simManager0.present && root.simManager0.ready) || (root.simManager1.present && root.simManager1.ready) ||
197 root.seenSIMPage) { // go to next page
200 pageStack.load(Qt.resolvedUrl("sim.qml")); // show the SIM page