on xenial help sign in
Have unity8 handle language changes better
ba4a9a0Michael Terry
plugins/Unity/Launcher/desktopfilehandler.cpp+1−1
@@ -110,7 +110,7 @@ QString DesktopFileHandler::displayName() const
110 settings.beginGroup("Desktop Entry");
110 settings.beginGroup("Desktop Entry");
111
111
112 // First try to find Name[xx_YY] and Name[xx] in .desktop file
112 // First try to find Name[xx_YY] and Name[xx] in .desktop file
113− QString locale = QLocale::system().name();
113+ QString locale = QLocale().name();
114 QString shortLocale = locale.split('_').first();
114 QString shortLocale = locale.split('_').first();
115
115
116 if (locale != shortLocale && settings.contains(QString("Name[%1]").arg(locale))) {
116 if (locale != shortLocale && settings.contains(QString("Name[%1]").arg(locale))) {
plugins/Unity/Launcher/launcheritem.cpp+11−4
@@ -60,6 +60,10 @@ void LauncherItem::setName(const QString &name)
60{
60{
61 if (m_name != name) {
61 if (m_name != name) {
62 m_name = name;
62 m_name = name;
63+ QuickListEntry entry;
64+ entry.setActionId("launch_item");
65+ entry.setText(m_name);
66+ m_quickList->updateAction(entry);
63 Q_EMIT nameChanged(name);
67 Q_EMIT nameChanged(name);
64 }
68 }
65}
69}
@@ -86,12 +90,15 @@ void LauncherItem::setPinned(bool pinned)
86{
90{
87 if (m_pinned != pinned) {
91 if (m_pinned != pinned) {
88 m_pinned = pinned;
92 m_pinned = pinned;
89− QuickListEntry entry;
90− entry.setActionId("pin_item");
91− entry.setText(pinned ? gettext("Unpin shortcut") : gettext("Pin shortcut"));
92− m_quickList->updateAction(entry);
93 Q_EMIT pinnedChanged(pinned);
93 Q_EMIT pinnedChanged(pinned);
94 }
94 }
95+
96+ // Even if pinned status didn't change, we want to update text in case
97+ // the locale has changed since we last set pinned status.
98+ QuickListEntry entry;
99+ entry.setActionId("pin_item");
100+ entry.setText(pinned ? gettext("Unpin shortcut") : gettext("Pin shortcut"));
101+ m_quickList->updateAction(entry);
95}
102}
96
103
97bool LauncherItem::running() const
104bool LauncherItem::running() const
plugins/Unity/Launcher/launchermodel.cpp+1
@@ -370,6 +370,7 @@ void LauncherModel::refresh()
370 int idx = m_list.indexOf(item);
370 int idx = m_list.indexOf(item);
371 item->setName(desktopFile.displayName());
371 item->setName(desktopFile.displayName());
372 item->setIcon(desktopFile.icon());
372 item->setIcon(desktopFile.icon());
373+ item->setPinned(item->pinned()); // update pinned text if needed
373 Q_EMIT dataChanged(index(idx), index(idx), QVector<int>() << RoleName << RoleIcon);
374 Q_EMIT dataChanged(index(idx), index(idx), QVector<int>() << RoleName << RoleIcon);
374 }
375 }
375 }
376 }
plugins/Unity/Launcher/launchermodel.h+1−1
@@ -58,6 +58,7 @@ public:
58
58
59public Q_SLOTS:
59public Q_SLOTS:
60 void requestRemove(const QString &appId);
60 void requestRemove(const QString &appId);
61+ Q_INVOKABLE void refresh();
61
62
62private:
63private:
63 void storeAppList();
64 void storeAppList();
@@ -68,7 +69,6 @@ private Q_SLOTS:
68 void countChanged(const QString &appId, int count);
69 void countChanged(const QString &appId, int count);
69 void countVisibleChanged(const QString &appId, int count);
70 void countVisibleChanged(const QString &appId, int count);
70 void progressChanged(const QString &appId, int progress);
71 void progressChanged(const QString &appId, int progress);
71− void refresh();
72
72
73 void applicationAdded(const QModelIndex &parent, int row);
73 void applicationAdded(const QModelIndex &parent, int row);
74 void applicationRemoved(const QModelIndex &parent, int row);
74 void applicationRemoved(const QModelIndex &parent, int row);
plugins/Wizard/System.cpp+5
@@ -20,6 +20,7 @@
20#include <QDBusMetaType>
20#include <QDBusMetaType>
21#include <QDir>
21#include <QDir>
22#include <QFile>
22#include <QFile>
23+#include <QLocale>
23#include <QMap>
24#include <QMap>
24#include <QProcess>
25#include <QProcess>
25
26
@@ -84,6 +85,10 @@ void System::updateSessionLanguage(const QString &locale)
84 setSessionVariable("LANG", locale);
85 setSessionVariable("LANG", locale);
85 setSessionVariable("LC_ALL", locale);
86 setSessionVariable("LC_ALL", locale);
86
87
88+ // QLocale caches the default locale on startup, and Qt uses that cached
89+ // copy when formatting dates. So manually update it here.
90+ QLocale::setDefault(QLocale(locale));
91+
87 // Restart bits of the session to pick up new language.
92 // Restart bits of the session to pick up new language.
88 QProcess::startDetached("sh -c \"initctl emit indicator-services-end; \
93 QProcess::startDetached("sh -c \"initctl emit indicator-services-end; \
89 initctl stop scope-registry; \
94 initctl stop scope-registry; \
qml/Components/EdgeDemo.qml+9−1
@@ -17,6 +17,7 @@
17import AccountsService 0.1
17import AccountsService 0.1
18import LightDM 0.1 as LightDM
18import LightDM 0.1 as LightDM
19import QtQuick 2.0
19import QtQuick 2.0
20+import Ubuntu.Components 1.1
20
21
21Item {
22Item {
22 id: demo
23 id: demo
@@ -97,12 +98,19 @@ Item {
97 property bool showEdgeDemo: AccountsService.demoEdges
98 property bool showEdgeDemo: AccountsService.demoEdges
98 property bool showEdgeDemoInGreeter: AccountsService.demoEdges // TODO: AccountsService.demoEdges as lightdm user
99 property bool showEdgeDemoInGreeter: AccountsService.demoEdges // TODO: AccountsService.demoEdges as lightdm user
99
100
100− onShowEdgeDemoChanged: {
101+ function restartDemo() {
101 stopDemo()
102 stopDemo()
102 if (d.showEdgeDemo) {
103 if (d.showEdgeDemo) {
103 startDemo()
104 startDemo()
104 }
105 }
105 }
106 }
107+
108+ onShowEdgeDemoChanged: restartDemo()
109+ }
110+
111+ Connections {
112+ target: i18n
113+ onLanguageChanged: d.restartDemo()
106 }
114 }
107
115
108 function startRightEdgeDemo() {
116 function startRightEdgeDemo() {
qml/Greeter/Clock.qml+10
@@ -66,6 +66,11 @@ Item {
66 opacity: 0.5
66 opacity: 0.5
67 text: Qt.formatTime(clock.currentDate)
67 text: Qt.formatTime(clock.currentDate)
68 font.weight: Font.Light
68 font.weight: Font.Light
69+
70+ Connections {
71+ target: i18n
72+ onLanguageChanged: timeLabel.text = Qt.formatTime(clock.currentDate)
73+ }
69 }
74 }
70
75
71 Label {
76 Label {
@@ -78,6 +83,11 @@ Item {
78 opacity: 0.5
83 opacity: 0.5
79 text: Qt.formatDate(clock.currentDate, Qt.DefaultLocaleLongDate)
84 text: Qt.formatDate(clock.currentDate, Qt.DefaultLocaleLongDate)
80 font.weight: Font.Light
85 font.weight: Font.Light
86+
87+ Connections {
88+ target: i18n
89+ onLanguageChanged: dateLabel.text = Qt.formatDate(clock.currentDate, Qt.DefaultLocaleLongDate)
90+ }
81 }
91 }
82 }
92 }
83}
93}
qml/Greeter/GreeterContent.qml+5
@@ -150,6 +150,11 @@ Item {
150 onSelected: infographics.selectedUser = greeterContentLoader.model.data(uid, LightDM.UserRoles.NameRole)
150 onSelected: infographics.selectedUser = greeterContentLoader.model.data(uid, LightDM.UserRoles.NameRole)
151 }
151 }
152
152
153+ Connections {
154+ target: i18n
155+ onLanguageChanged: greeterContentLoader.infographicModel.readyForDataChange()
156+ }
157+
153 anchors {
158 anchors {
154 verticalCenter: parent.verticalCenter
159 verticalCenter: parent.verticalCenter
155 left: narrowMode ? root.left : loginLoader.right
160 left: narrowMode ? root.left : loginLoader.right
qml/Launcher/Launcher.qml+5
@@ -118,6 +118,11 @@ Item {
118 onHint: hint();
118 onHint: hint();
119 }
119 }
120
120
121+ Connections {
122+ target: i18n
123+ onLanguageChanged: LauncherModel.refresh()
124+ }
125+
121 SequentialAnimation {
126 SequentialAnimation {
122 id: fadeOutAnimation
127 id: fadeOutAnimation
123 ScriptAction {
128 ScriptAction {
qml/Shell.qml+11−15
@@ -333,6 +333,15 @@ Item {
333 minPinLength: 4
333 minPinLength: 4
334 maxPinLength: 4
334 maxPinLength: 4
335
335
336+ property string promptText
337+ infoText: promptText !== "" ? i18n.tr("Enter %1").arg(promptText) :
338+ alphaNumeric ? i18n.tr("Enter passphrase") :
339+ i18n.tr("Enter passcode")
340+ errorText: promptText !== "" ? i18n.tr("Sorry, incorrect %1").arg(promptText) :
341+ alphaNumeric ? i18n.tr("Sorry, incorrect passphrase") + "\n" +
342+ i18n.tr("Please re-enter") :
343+ i18n.tr("Sorry, incorrect passcode")
344+
336 // FIXME: We *should* show emergency dialer if there is a SIM present,
345 // FIXME: We *should* show emergency dialer if there is a SIM present,
337 // regardless of whether the side stage is enabled. But right now,
346 // regardless of whether the side stage is enabled. But right now,
338 // the assumption is that narrow screens are phones which have SIMs
347 // the assumption is that narrow screens are phones which have SIMs
@@ -386,20 +395,7 @@ Item {
386 return; // could happen if hideGreeter() comes in before we prompt
395 return; // could happen if hideGreeter() comes in before we prompt
387 }
396 }
388 if (greeter.narrowMode) {
397 if (greeter.narrowMode) {
389− if (isDefaultPrompt) {
398+ lockscreen.promptText = isDefaultPrompt ? "" : text.toLowerCase();
390− if (lockscreen.alphaNumeric) {
391− lockscreen.infoText = i18n.tr("Enter passphrase")
392− lockscreen.errorText = i18n.tr("Sorry, incorrect passphrase") + "\n" +
393− i18n.tr("Please re-enter")
394− } else {
395− lockscreen.infoText = i18n.tr("Enter passcode")
396− lockscreen.errorText = i18n.tr("Sorry, incorrect passcode")
397− }
398− } else {
399− lockscreen.infoText = i18n.tr("Enter %1").arg(text.toLowerCase())
400− lockscreen.errorText = i18n.tr("Sorry, incorrect %1").arg(text.toLowerCase())
401− }
402−
403 lockscreen.maybeShow();
399 lockscreen.maybeShow();
404 }
400 }
405 }
401 }
@@ -803,7 +799,7 @@ Item {
803 id: edgeDemo
799 id: edgeDemo
804 objectName: "edgeDemo"
800 objectName: "edgeDemo"
805 z: alphaDisclaimerLabel.z + 10
801 z: alphaDisclaimerLabel.z + 10
806− paused: Powerd.status === Powerd.Off // Saves power
802+ paused: Powerd.status === Powerd.Off || wizard.active // Saves power
807 greeter: greeter
803 greeter: greeter
808 launcher: launcher
804 launcher: launcher
809 panel: panel
805 panel: panel
qml/Wizard/Pages/10-welcome.qml+1
@@ -85,6 +85,7 @@ LocalComponents.Page {
85 onClicked: {
85 onClicked: {
86 plugin.currentLanguage = listview.currentIndex
86 plugin.currentLanguage = listview.currentIndex
87 System.updateSessionLanguage(plugin.languageCodes[listview.currentIndex]);
87 System.updateSessionLanguage(plugin.languageCodes[listview.currentIndex]);
88+ i18n.language = i18n.language; // re-notify of change after above call (for qlocale change)
88 pageStack.next()
89 pageStack.next()
89 }
90 }
90 }
91 }
qml/Wizard/Wizard.qml+2
@@ -23,6 +23,8 @@ Showable {
23 // The background wallpaper to use
23 // The background wallpaper to use
24 property string background
24 property string background
25
25
26+ readonly property alias active: loader.active
27+
26 ////
28 ////
27
29
28 id: root
30 id: root