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
23 import "../../Components"
25 LocalComponents.Page {
26 objectName: "languagePage"
28 title: i18n.tr("Language")
29 forwardButtonSourceComponent: forwardButton
31 UbuntuLanguagePlugin {
35 OnScreenKeyboardPlugin {
41 var detectedLang = "";
42 // try to detect the language+country from the SIM card
43 if (root.simManager0.present && root.simManager0.preferredLanguages.length > 0) {
44 detectedLang = root.simManager0.preferredLanguages[0] + "_" + LocalePlugin.mccToCountryCode(root.simManager0.mobileCountryCode);
45 } else if (root.simManager1.present && root.simManager1.preferredLanguages.length > 0) {
46 detectedLang = root.simManager1.preferredLanguages[0] + "_" + LocalePlugin.mccToCountryCode(root.simManager1.mobileCountryCode);
47 } else if (plugin.currentLanguage != -1) {
48 detectedLang = plugin.languageCodes[plugin.currentLanguage].split(".")[0]; // remove the encoding part, after dot (en_US.utf8 -> en_US)
50 detectedLang = "en_US"; // fallback to default lang
53 // preselect the detected language
54 for (var i = 0; i < plugin.languageCodes.length; i++) {
55 var code = plugin.languageCodes[i].split(".")[0]; // remove the encoding part, after dot (en_US.utf8 -> en_US)
56 if (detectedLang === code) {
57 languagesListView.currentIndex = i;
58 languagesListView.positionViewAtIndex(i, ListView.Center);
59 i18n.language = plugin.languageCodes[i];
65 function applyOSKSettings(locale) {
66 var language = locale.split("_")[0].split(".")[0];
67 var oskLanguage = language;
69 if (language === "zh") { // special case for Chinese, select either simplified or traditional
70 if (locale.substr(0, 5) === "zh_CN" || locale.substr(0,5) === "zh_SG") {
71 oskLanguage = "zh-hans"; // Chinese Simplified
73 oskLanguage = "zh-hant"; // Chinese Traditional
77 oskPlugin.setCurrentLayout(oskLanguage);
80 // splash screen (this has to be on the first page)
83 anchors.top: parent.top
84 anchors.left: parent.left
85 anchors.right: parent.right
87 source: wideMode ? "data/Desktop_splash_screen_bkg.png" : "data/Phone_splash_screen_bkg.png"
88 fillMode: Image.PreserveAspectCrop
91 Component.onCompleted: splashAnimation.start()
96 PauseAnimation { duration: UbuntuAnimation.BriskDuration }
101 duration: UbuntuAnimation.BriskDuration
113 id: languagesListView
114 objectName: "languagesListView"
116 snapMode: ListView.SnapToItem
120 leftMargin: wideMode ? parent.leftMargin : 0
121 rightMargin: wideMode ? parent.rightMargin : 0
122 topMargin: wideMode ? parent.customMargin : 0
125 model: plugin.languageNames
129 objectName: "languageDelegate_" + langLabel.text.toLowerCase().replace(/\s+/g, '_')
130 highlightColor: backgroundColor
131 divider.colorFrom: dividerColor
132 divider.colorTo: backgroundColor
133 readonly property bool isCurrent: index === ListView.view.currentIndex
141 verticalCenter: parent.verticalCenter
142 leftMargin: languagesListView.anchors.leftMargin == 0 ? staticMargin : 0
146 font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
153 verticalCenter: parent.verticalCenter;
154 rightMargin: languagesListView.anchors.rightMargin == 0 ? staticMargin : 0
156 fillMode: Image.PreserveAspectFit
157 height: units.gu(1.5)
159 source: "data/Tick@30.png"
160 visible: itemDelegate.isCurrent
164 languagesListView.currentIndex = index;
165 i18n.language = plugin.languageCodes[index];
172 LocalComponents.StackButton {
173 text: i18n.tr("Next")
174 enabled: languagesListView.currentIndex != -1
176 if (plugin.currentLanguage !== languagesListView.currentIndex) {
177 var locale = plugin.languageCodes[languagesListView.currentIndex];
178 plugin.currentLanguage = languagesListView.currentIndex;
179 applyOSKSettings(locale);
180 System.updateSessionLocale(locale);
182 i18n.language = plugin.languageCodes[plugin.currentLanguage]; // re-notify of change after above call (for qlocale change)
184 if (!root.modemManager.available || !root.modemManager.ready || root.modemManager.modems.length === 0 ||
185 (root.simManager0.present && root.simManager0.ready) || (root.simManager1.present && root.simManager1.ready) ||
186 root.seenSIMPage) { // go to next page
189 pageStack.load(Qt.resolvedUrl("sim.qml")); // show the SIM page