2 * Copyright (C) 2013-2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import Ubuntu.Components 1.3
19 import Ubuntu.Components.ListItems 1.3
20 import Ubuntu.SystemSettings.LanguagePlugin 1.0
22 import ".." as LocalComponents
24 LocalComponents.Page {
25 objectName: "languagePage"
27 title: i18n.tr("Language")
28 forwardButtonSourceComponent: forwardButton
30 UbuntuLanguagePlugin {
34 OnScreenKeyboardPlugin {
40 var detectedLang = "";
41 // try to detect the language+country from the SIM card
42 if (root.simManager0.present && root.simManager0.preferredLanguages.length > 0) {
43 detectedLang = root.simManager0.preferredLanguages[0] + "_" + LocalePlugin.mccToCountryCode(root.simManager0.mobileCountryCode);
44 } else if (root.simManager1.present && root.simManager1.preferredLanguages.length > 0) {
45 detectedLang = root.simManager1.preferredLanguages[0] + "_" + LocalePlugin.mccToCountryCode(root.simManager1.mobileCountryCode);
46 } else if (plugin.currentLanguage != -1) {
47 detectedLang = plugin.languageCodes[plugin.currentLanguage].split(".")[0]; // remove the encoding part, after dot (en_US.utf8 -> en_US)
49 detectedLang = "en_US"; // fallback to default lang
52 // preselect the detected language
53 for (var i = 0; i < plugin.languageCodes.length; i++) {
54 var code = plugin.languageCodes[i].split(".")[0]; // remove the encoding part, after dot (en_US.utf8 -> en_US)
55 if (detectedLang === code) {
56 languagesListView.currentIndex = i;
57 languagesListView.positionViewAtIndex(i, ListView.Center);
58 i18n.language = plugin.languageCodes[i];
64 function applyOSKSettings(locale) {
65 var language = locale.split("_")[0].split(".")[0];
66 var oskLanguage = language;
68 if (language === "zh") { // special case for Chinese, select either simplified or traditional
69 if (locale.substr(0, 5) === "zh_CN" || locale.substr(0,5) === "zh_SG") {
70 oskLanguage = "zh-hans"; // Chinese Simplified
72 oskLanguage = "zh-hant"; // Chinese Traditional
76 oskPlugin.setCurrentLayout(oskLanguage);
79 // splash screen (this has to be on the first page)
82 anchors.top: parent.top
83 anchors.left: parent.left
84 anchors.right: parent.right
86 source: wideMode ? "data/Desktop_splash_screen_bkg.png" : "data/Phone_splash_screen_bkg.png"
87 fillMode: Image.PreserveAspectCrop
90 Component.onCompleted: splashAnimation.start()
95 PauseAnimation { duration: UbuntuAnimation.BriskDuration }
100 duration: UbuntuAnimation.BriskDuration
112 id: languagesListView
114 snapMode: ListView.SnapToItem
118 leftMargin: wideMode ? parent.leftMargin : 0
119 rightMargin: wideMode ? parent.rightMargin : 0
120 topMargin: wideMode ? parent.customMargin : 0
123 model: plugin.languageNames
127 objectName: "languageDelegate" + index
128 highlightColor: backgroundColor
129 divider.colorFrom: dividerColor
130 divider.colorTo: backgroundColor
131 readonly property bool isCurrent: index === ListView.view.currentIndex
139 verticalCenter: parent.verticalCenter
140 leftMargin: languagesListView.anchors.leftMargin == 0 ? staticMargin : 0
144 font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
151 verticalCenter: parent.verticalCenter;
152 rightMargin: languagesListView.anchors.rightMargin == 0 ? staticMargin : 0
154 fillMode: Image.PreserveAspectFit
155 height: units.gu(1.5)
157 source: "data/Tick@30.png"
158 visible: itemDelegate.isCurrent
162 languagesListView.currentIndex = index;
163 i18n.language = plugin.languageCodes[index];
170 LocalComponents.StackButton {
171 text: i18n.tr("Next")
172 enabled: languagesListView.currentIndex != -1
174 if (plugin.currentLanguage !== languagesListView.currentIndex) {
175 var locale = plugin.languageCodes[languagesListView.currentIndex];
176 plugin.currentLanguage = languagesListView.currentIndex;
177 applyOSKSettings(locale);
178 System.updateSessionLocale(locale);
180 i18n.language = plugin.languageCodes[plugin.currentLanguage]; // re-notify of change after above call (for qlocale change)
182 if (!root.modemManager.available || !root.modemManager.ready || root.modemManager.modems.length === 0 ||
183 (root.simManager0.present && root.simManager0.ready) || (root.simManager1.present && root.simManager1.ready) ||
184 root.seenSIMPage) { // go to next page
187 pageStack.load(Qt.resolvedUrl("sim.qml")); // show the SIM page