on xenial help sign in
Have unity8 handle language changes better
commitba4a9a02a4b63b0ac23321fbaa24b1bbc756499f authorMichael Terry <michael.terry@canonical.com> dateWed 19 Nov 2014, 12:43 (12 years ago) parente7b1494
12 files changed+62−22
plugins/Unity/Launcher/desktopfilehandler.cpp+1−1 plugins/Unity/Launcher/launcheritem.cpp+11−4 plugins/Unity/Launcher/launchermodel.cpp+1 plugins/Unity/Launcher/launchermodel.h+1−1 plugins/Wizard/System.cpp+5 qml/Components/EdgeDemo.qml+9−1 qml/Greeter/Clock.qml+10 qml/Greeter/GreeterContent.qml+5 qml/Launcher/Launcher.qml+5 qml/Shell.qml+11−15 qml/Wizard/Pages/10-welcome.qml+1 qml/Wizard/Wizard.qml+2
plugins/Unity/Launcher/desktopfilehandler.cpp+1−1
@@ -110,7 +110,7 @@ QString DesktopFileHandler::displayName() const
110110 settings.beginGroup("Desktop Entry");
111111
112112 // First try to find Name[xx_YY] and Name[xx] in .desktop file
113− QString locale = QLocale::system().name();
113+ QString locale = QLocale().name();
114114 QString shortLocale = locale.split('_').first();
115115
116116 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)
6060{
6161 if (m_name != name) {
6262 m_name = name;
63+ QuickListEntry entry;
64+ entry.setActionId("launch_item");
65+ entry.setText(m_name);
66+ m_quickList->updateAction(entry);
6367 Q_EMIT nameChanged(name);
6468 }
6569}
@@ -86,12 +90,15 @@ void LauncherItem::setPinned(bool pinned)
8690{
8791 if (m_pinned != pinned) {
8892 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);
9393 Q_EMIT pinnedChanged(pinned);
9494 }
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);
95102}
96103
97104bool LauncherItem::running() const
plugins/Unity/Launcher/launchermodel.cpp+1
@@ -370,6 +370,7 @@ void LauncherModel::refresh()
370370 int idx = m_list.indexOf(item);
371371 item->setName(desktopFile.displayName());
372372 item->setIcon(desktopFile.icon());
373+ item->setPinned(item->pinned()); // update pinned text if needed
373374 Q_EMIT dataChanged(index(idx), index(idx), QVector<int>() << RoleName << RoleIcon);
374375 }
375376 }
plugins/Unity/Launcher/launchermodel.h+1−1
@@ -58,6 +58,7 @@ public:
5858
5959public Q_SLOTS:
6060 void requestRemove(const QString &appId);
61+ Q_INVOKABLE void refresh();
6162
6263private:
6364 void storeAppList();
@@ -68,7 +69,6 @@ private Q_SLOTS:
6869 void countChanged(const QString &appId, int count);
6970 void countVisibleChanged(const QString &appId, int count);
7071 void progressChanged(const QString &appId, int progress);
71− void refresh();
7272
7373 void applicationAdded(const QModelIndex &parent, int row);
7474 void applicationRemoved(const QModelIndex &parent, int row);
plugins/Wizard/System.cpp+5
@@ -20,6 +20,7 @@
2020#include <QDBusMetaType>
2121#include <QDir>
2222#include <QFile>
23+#include <QLocale>
2324#include <QMap>
2425#include <QProcess>
2526
@@ -84,6 +85,10 @@ void System::updateSessionLanguage(const QString &locale)
8485 setSessionVariable("LANG", locale);
8586 setSessionVariable("LC_ALL", locale);
8687
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+
8792 // Restart bits of the session to pick up new language.
8893 QProcess::startDetached("sh -c \"initctl emit indicator-services-end; \
8994 initctl stop scope-registry; \
qml/Components/EdgeDemo.qml+9−1
@@ -17,6 +17,7 @@
1717import AccountsService 0.1
1818import LightDM 0.1 as LightDM
1919import QtQuick 2.0
20+import Ubuntu.Components 1.1
2021
2122Item {
2223 id: demo
@@ -97,12 +98,19 @@ Item {
9798 property bool showEdgeDemo: AccountsService.demoEdges
9899 property bool showEdgeDemoInGreeter: AccountsService.demoEdges // TODO: AccountsService.demoEdges as lightdm user
99100
100− onShowEdgeDemoChanged: {
101+ function restartDemo() {
101102 stopDemo()
102103 if (d.showEdgeDemo) {
103104 startDemo()
104105 }
105106 }
107+
108+ onShowEdgeDemoChanged: restartDemo()
109+ }
110+
111+ Connections {
112+ target: i18n
113+ onLanguageChanged: d.restartDemo()
106114 }
107115
108116 function startRightEdgeDemo() {
qml/Greeter/Clock.qml+10
@@ -66,6 +66,11 @@ Item {
6666 opacity: 0.5
6767 text: Qt.formatTime(clock.currentDate)
6868 font.weight: Font.Light
69+
70+ Connections {
71+ target: i18n
72+ onLanguageChanged: timeLabel.text = Qt.formatTime(clock.currentDate)
73+ }
6974 }
7075
7176 Label {
@@ -78,6 +83,11 @@ Item {
7883 opacity: 0.5
7984 text: Qt.formatDate(clock.currentDate, Qt.DefaultLocaleLongDate)
8085 font.weight: Font.Light
86+
87+ Connections {
88+ target: i18n
89+ onLanguageChanged: dateLabel.text = Qt.formatDate(clock.currentDate, Qt.DefaultLocaleLongDate)
90+ }
8191 }
8292 }
8393}
qml/Greeter/GreeterContent.qml+5
@@ -150,6 +150,11 @@ Item {
150150 onSelected: infographics.selectedUser = greeterContentLoader.model.data(uid, LightDM.UserRoles.NameRole)
151151 }
152152
153+ Connections {
154+ target: i18n
155+ onLanguageChanged: greeterContentLoader.infographicModel.readyForDataChange()
156+ }
157+
153158 anchors {
154159 verticalCenter: parent.verticalCenter
155160 left: narrowMode ? root.left : loginLoader.right
qml/Launcher/Launcher.qml+5
@@ -118,6 +118,11 @@ Item {
118118 onHint: hint();
119119 }
120120
121+ Connections {
122+ target: i18n
123+ onLanguageChanged: LauncherModel.refresh()
124+ }
125+
121126 SequentialAnimation {
122127 id: fadeOutAnimation
123128 ScriptAction {
qml/Shell.qml+11−15
@@ -333,6 +333,15 @@ Item {
333333 minPinLength: 4
334334 maxPinLength: 4
335335
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+
336345 // FIXME: We *should* show emergency dialer if there is a SIM present,
337346 // regardless of whether the side stage is enabled. But right now,
338347 // the assumption is that narrow screens are phones which have SIMs
@@ -386,20 +395,7 @@ Item {
386395 return; // could happen if hideGreeter() comes in before we prompt
387396 }
388397 if (greeter.narrowMode) {
389− if (isDefaultPrompt) {
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−
398+ lockscreen.promptText = isDefaultPrompt ? "" : text.toLowerCase();
403399 lockscreen.maybeShow();
404400 }
405401 }
@@ -803,7 +799,7 @@ Item {
803799 id: edgeDemo
804800 objectName: "edgeDemo"
805801 z: alphaDisclaimerLabel.z + 10
806− paused: Powerd.status === Powerd.Off // Saves power
802+ paused: Powerd.status === Powerd.Off || wizard.active // Saves power
807803 greeter: greeter
808804 launcher: launcher
809805 panel: panel
qml/Wizard/Pages/10-welcome.qml+1
@@ -85,6 +85,7 @@ LocalComponents.Page {
8585 onClicked: {
8686 plugin.currentLanguage = listview.currentIndex
8787 System.updateSessionLanguage(plugin.languageCodes[listview.currentIndex]);
88+ i18n.language = i18n.language; // re-notify of change after above call (for qlocale change)
8889 pageStack.next()
8990 }
9091 }
qml/Wizard/Wizard.qml+2
@@ -23,6 +23,8 @@ Showable {
2323 // The background wallpaper to use
2424 property string background
2525
26+ readonly property alias active: loader.active
27+
2628 ////
2729
2830 id: root