Merge lp:~agateau/unity-2d/gettext2 into lp:unity-2d/3.0

Proposed by Aurélien Gâteau
Status: Merged
Approved by: Florian Boucault
Approved revision: 464
Merged at revision: 463
Proposed branch: lp:~agateau/unity-2d/gettext2
Merge into: lp:unity-2d/3.0
Diff against target: 1113 lines (+344/-324)
23 files modified
launcher/UnityApplications/launcherapplication.cpp (+5/-2)
launcher/UnityApplications/launcherdevice.cpp (+3/-1)
launcher/UnityApplications/trash.cpp (+6/-3)
launcher/UnityApplications/workspaces.cpp (+4/-1)
launcher/app/launcher.cpp (+4/-6)
libunity-2d-private/src/CMakeLists.txt (+2/-1)
libunity-2d-private/src/gettexttranslator.cpp (+0/-85)
libunity-2d-private/src/gettexttranslator.h (+0/-61)
libunity-2d-private/src/unity2dtr.cpp (+78/-0)
libunity-2d-private/src/unity2dtr.h (+70/-0)
libunity-2d-private/tests/CMakeLists.txt (+4/-4)
libunity-2d-private/tests/fr.po (+5/-0)
libunity-2d-private/tests/gettexttest.cpp (+0/-74)
libunity-2d-private/tests/unity2dtrtest.cpp (+55/-0)
panel/app/main.cpp (+2/-4)
places/GroupHeader.qml (+1/-1)
places/Home.qml (+8/-8)
places/SearchEntry.qml (+2/-2)
places/SearchRefine.qml (+2/-2)
places/app/places.cpp (+3/-4)
po/fr.po (+69/-50)
po/unity-2d.pot (+16/-13)
po/update-unity-2d-pot (+5/-2)
To merge this branch: bzr merge lp:~agateau/unity-2d/gettext2
Reviewer Review Type Date Requested Status
Florian Boucault Pending
Review via email: mp+53668@code.launchpad.net

Commit message

[translations] Replace GettextTranslator with Unity2dTr, for proper handling of plural forms

Description of the change

This branch replaces GettextTranslator with Unity2dTr, a thin wrapper around gettext functions. The wrapper is useful to handle char* to QString conversions and to make it simpler to use plural forms.

I decided to name the translation functions u2dTr() to keep them short, but this can be adjusted.

On the QML side, an helper object named "u2d" is installed in the root context of places and launcher. Code using qsTr() is replaced with u2d.tr().

It would have been nicer to expose the function as u2dTr, but I couldn't find a way to expose standalone functions and the operator() trick failed as well.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/UnityApplications/launcherapplication.cpp'
2--- launcher/UnityApplications/launcherapplication.cpp 2011-03-11 01:14:28 +0000
3+++ launcher/UnityApplications/launcherapplication.cpp 2011-03-16 17:45:58 +0000
4@@ -35,6 +35,9 @@
5
6 #include <X11/X.h>
7
8+// libunity-2d
9+#include <unity2dtr.h>
10+
11 #include <QDebug>
12 #include <QAction>
13 #include <QDBusInterface>
14@@ -745,14 +748,14 @@
15 QAction* keep = new QAction(m_menu);
16 keep->setCheckable(is_running);
17 keep->setChecked(sticky());
18- keep->setText(is_running ? tr("Keep In Launcher") : tr("Remove From Launcher"));
19+ keep->setText(is_running ? u2dTr("Keep In Launcher") : u2dTr("Remove From Launcher"));
20 actions.append(keep);
21 QObject::connect(keep, SIGNAL(triggered()), this, SLOT(onKeepTriggered()));
22 }
23
24 if (is_running) {
25 QAction* quit = new QAction(m_menu);
26- quit->setText(tr("Quit"));
27+ quit->setText(u2dTr("Quit"));
28 actions.append(quit);
29 QObject::connect(quit, SIGNAL(triggered()), this, SLOT(onQuitTriggered()));
30 }
31
32=== modified file 'launcher/UnityApplications/launcherdevice.cpp'
33--- launcher/UnityApplications/launcherdevice.cpp 2011-03-10 12:31:36 +0000
34+++ launcher/UnityApplications/launcherdevice.cpp 2011-03-16 17:45:58 +0000
35@@ -30,6 +30,8 @@
36 #include <gtk/gtk.h>
37 }
38
39+// libunity-2d
40+#include <unity2dtr.h>
41
42 LauncherDevice::LauncherDevice() :
43 m_volume(NULL)
44@@ -223,7 +225,7 @@
45 LauncherDevice::createMenuActions()
46 {
47 QAction* eject = new QAction(m_menu);
48- eject->setText(tr("Eject"));
49+ eject->setText(u2dTr("Eject"));
50 m_menu->addAction(eject);
51 QObject::connect(eject, SIGNAL(triggered()), this, SLOT(onEjectTriggered()));
52 }
53
54=== modified file 'launcher/UnityApplications/trash.cpp'
55--- launcher/UnityApplications/trash.cpp 2011-03-09 13:23:04 +0000
56+++ launcher/UnityApplications/trash.cpp 2011-03-16 17:45:58 +0000
57@@ -22,6 +22,9 @@
58
59 #include "config.h"
60
61+// libunity-2d
62+#include <unity2dtr.h>
63+
64 #include <QDebug>
65 #include <QAction>
66
67@@ -68,7 +71,7 @@
68 QString
69 Trash::name() const
70 {
71- return tr("Trash");
72+ return u2dTr("Trash");
73 }
74
75 QString
76@@ -188,14 +191,14 @@
77 if (c == 0) return;
78
79 QAction* contents = new QAction(m_menu);
80- contents->setText(tr("%n item(s) in trash", 0, c));
81+ contents->setText(u2dTr("%n item in trash", "%n items in trash", c));
82 contents->setEnabled(false);
83 m_menu->addAction(contents);
84
85 m_menu->addSeparator();
86
87 QAction* empty = new QAction(m_menu);
88- empty->setText(tr("Empty Trash"));
89+ empty->setText(u2dTr("Empty Trash"));
90 m_menu->addAction(empty);
91 QObject::connect(empty, SIGNAL(triggered()), this, SLOT(onEmptyTriggered()));
92 }
93
94=== modified file 'launcher/UnityApplications/workspaces.cpp'
95--- launcher/UnityApplications/workspaces.cpp 2011-02-10 01:00:41 +0000
96+++ launcher/UnityApplications/workspaces.cpp 2011-03-16 17:45:58 +0000
97@@ -24,6 +24,9 @@
98 #include <QDBusInterface>
99 #include <QDBusReply>
100
101+// libunity-2d
102+#include <unity2dtr.h>
103+
104 Workspaces::Workspaces()
105 {
106 }
107@@ -63,7 +66,7 @@
108 QString
109 Workspaces::name() const
110 {
111- return tr("Workspaces");
112+ return u2dTr("Workspaces");
113 }
114
115 QString
116
117=== modified file 'launcher/app/launcher.cpp'
118--- launcher/app/launcher.cpp 2011-03-14 15:25:50 +0000
119+++ launcher/app/launcher.cpp 2011-03-16 17:45:58 +0000
120@@ -20,9 +20,9 @@
121 #include <gtk/gtk.h>
122
123 // unity-2d
124-#include <gettexttranslator.h>
125 #include <gnomesessionclient.h>
126 #include <unity2dapplication.h>
127+#include <unity2dtr.h>
128 #include <propertybinder.h>
129
130 // libqtgconf
131@@ -36,8 +36,6 @@
132 #include <QDir>
133 #include <QGraphicsObject>
134
135-#include <unity2dapplication.h>
136-
137 #include "config.h"
138 #include "launcherview.h"
139 #include "launcherdbus.h"
140@@ -73,9 +71,7 @@
141 QDir::addSearchPath("artwork", unity2dDirectory() + "/launcher/artwork");
142
143 /* Configure translations */
144- GettextTranslator translator;
145- translator.init("unity-2d", INSTALL_PREFIX "/share/locale");
146- QApplication::installTranslator(&translator);
147+ Unity2dTr::init("unity-2d", INSTALL_PREFIX "/share/locale");
148
149 /* Panel containing the QML declarative view */
150 Unity2dPanel panel;
151@@ -109,6 +105,8 @@
152 launcherView->rootContext()->setContextProperty("engineBaseUrl",
153 launcherView->engine()->baseUrl().toLocalFile());
154
155+ Unity2dTr::qmlInit(launcherView->rootContext());
156+
157 LauncherDBus launcherDBus(visibilityController, launcherView);
158 launcherDBus.connectToBus();
159
160
161=== modified file 'libunity-2d-private/src/CMakeLists.txt'
162--- libunity-2d-private/src/CMakeLists.txt 2011-03-07 14:26:03 +0000
163+++ libunity-2d-private/src/CMakeLists.txt 2011-03-16 17:45:58 +0000
164@@ -3,7 +3,6 @@
165
166 # Sources
167 set(libunity-2d-private_SRCS
168- gettexttranslator.cpp
169 gnomesessionclient.cpp
170 keyboardmodifiersmonitor.cpp
171 hotkeymonitor.cpp
172@@ -12,6 +11,7 @@
173 unity2dapplication.cpp
174 unity2ddebug.cpp
175 unity2dpanel.cpp
176+ unity2dtr.cpp
177 mimedata.cpp
178 dragdropevent.cpp
179 propertybinder.cpp
180@@ -36,6 +36,7 @@
181 ${QT_QTGUI_LIBRARIES}
182 ${QT_QTCORE_LIBRARIES}
183 ${QT_QTDBUS_LIBRARIES}
184+ ${QT_QTDECLARATIVE_LIBRARIES}
185 ${X11_LIBRARIES}
186 ${GLIB_LDFLAGS}
187 )
188
189=== removed file 'libunity-2d-private/src/gettexttranslator.cpp'
190--- libunity-2d-private/src/gettexttranslator.cpp 2011-02-18 16:17:59 +0000
191+++ libunity-2d-private/src/gettexttranslator.cpp 1970-01-01 00:00:00 +0000
192@@ -1,85 +0,0 @@
193-/*
194- * This file is part of unity-2d
195- *
196- * Copyright 2011 Canonical Ltd.
197- *
198- * Authors:
199- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
200- *
201- * This program is free software; you can redistribute it and/or modify
202- * it under the terms of the GNU General Public License as published by
203- * the Free Software Foundation; version 3.
204- *
205- * This program is distributed in the hope that it will be useful,
206- * but WITHOUT ANY WARRANTY; without even the implied warranty of
207- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
208- * GNU General Public License for more details.
209- *
210- * You should have received a copy of the GNU General Public License
211- * along with this program. If not, see <http://www.gnu.org/licenses/>.
212- */
213-// Self
214-#include "gettexttranslator.h"
215-
216-// Local
217-#include <debug_p.h>
218-
219-// Qt
220-
221-// libc
222-#include <libintl.h>
223-
224-struct GettextTranslatorPrivate
225-{
226-};
227-
228-GettextTranslator::GettextTranslator(QObject* parent)
229-: QTranslator(parent)
230-, d(new GettextTranslatorPrivate)
231-{
232-}
233-
234-GettextTranslator::~GettextTranslator()
235-{
236- delete d;
237-}
238-
239-QString GettextTranslator::translate(const char* context, const char* sourceText, const char* disambiguation) const
240-{
241- char* text;
242- if (qstrlen(disambiguation) > 0) {
243- // Constant copied from /usr/share/gettext/gettext.h
244- const char GETTEXT_CONTEXT_GLUE = '\004';
245- QByteArray array(disambiguation);
246- array.append(GETTEXT_CONTEXT_GLUE);
247- array.append(sourceText);
248- text = gettext(array.constData());
249- } else {
250- text = gettext(sourceText);
251- }
252- return QString::fromUtf8(text);
253-}
254-
255-bool GettextTranslator::init(const QString& domain_, const QString& directory)
256-{
257- const char* domain = domain_.toLocal8Bit().constData();
258- char* out;
259- setlocale(LC_ALL, "");
260- out = bindtextdomain(domain, directory.toLocal8Bit().constData());
261- if (!out) {
262- qWarning("bindtextdomain() failed: %s", strerror(errno));
263- return false;
264- }
265-
266- out = textdomain(domain);
267- if (!out) {
268- qWarning("textdomain() failed: %s", strerror(errno));
269- return false;
270- }
271-
272- bind_textdomain_codeset(domain, "UTF-8");
273-
274- return true;
275-}
276-
277-#include "gettexttranslator.moc"
278
279=== removed file 'libunity-2d-private/src/gettexttranslator.h'
280--- libunity-2d-private/src/gettexttranslator.h 2011-02-18 15:46:24 +0000
281+++ libunity-2d-private/src/gettexttranslator.h 1970-01-01 00:00:00 +0000
282@@ -1,61 +0,0 @@
283-/*
284- * This file is part of unity-2d
285- *
286- * Copyright 2011 Canonical Ltd.
287- *
288- * Authors:
289- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
290- *
291- * This program is free software; you can redistribute it and/or modify
292- * it under the terms of the GNU General Public License as published by
293- * the Free Software Foundation; version 3.
294- *
295- * This program is distributed in the hope that it will be useful,
296- * but WITHOUT ANY WARRANTY; without even the implied warranty of
297- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
298- * GNU General Public License for more details.
299- *
300- * You should have received a copy of the GNU General Public License
301- * along with this program. If not, see <http://www.gnu.org/licenses/>.
302- */
303-#ifndef GETTEXTTRANSLATOR_H
304-#define GETTEXTTRANSLATOR_H
305-
306-// Local
307-
308-// Qt
309-#include <QTranslator>
310-
311-struct GettextTranslatorPrivate;
312-/**
313- * A QTranslator which uses gettext
314- */
315-class GettextTranslator : public QTranslator
316-{
317- Q_OBJECT
318-public:
319- GettextTranslator(QObject* parent = 0);
320- ~GettextTranslator();
321-
322- /**
323- * Reimplemented. Note that context is ignored.
324- */
325- QString translate(const char* context, const char* sourceText, const char* disambiguation=0) const;
326-
327- /**
328- * Initialize the translator.
329- * Translations are then loaded from:
330- * $directory/$lang/locale/LC_MESSAGES/$domainName.mo
331- */
332- bool init(const QString& domainName, const QString& directory);
333-
334-private:
335- Q_DISABLE_COPY(GettextTranslator)
336- GettextTranslatorPrivate* const d;
337-
338- // Hide "load" methods because they are used to load .qm
339- bool load(const QString& filename, const QString& directory = QString(), const QString& search_delimiters = QString(), const QString& suffix = QString());
340- bool load(const uchar* data, int len);
341-};
342-
343-#endif /* GETTEXTTRANSLATOR_H */
344
345=== added file 'libunity-2d-private/src/unity2dtr.cpp'
346--- libunity-2d-private/src/unity2dtr.cpp 1970-01-01 00:00:00 +0000
347+++ libunity-2d-private/src/unity2dtr.cpp 2011-03-16 17:45:58 +0000
348@@ -0,0 +1,78 @@
349+/*
350+ * This file is part of unity-2d
351+ *
352+ * Copyright 2011 Canonical Ltd.
353+ *
354+ * Authors:
355+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
356+ *
357+ * This program is free software; you can redistribute it and/or modify
358+ * it under the terms of the GNU General Public License as published by
359+ * the Free Software Foundation; version 3.
360+ *
361+ * This program is distributed in the hope that it will be useful,
362+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
363+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
364+ * GNU General Public License for more details.
365+ *
366+ * You should have received a copy of the GNU General Public License
367+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
368+ */
369+// Self
370+#include <unity2dtr.h>
371+
372+// local
373+#include <config.h>
374+
375+// Qt
376+#include <QDeclarativeContext>
377+
378+// libc
379+#include <libintl.h>
380+
381+namespace Unity2dTr
382+{
383+
384+void init(const char* domain, const char* localeDir)
385+{
386+ setlocale(LC_ALL, "");
387+ bindtextdomain(domain, localeDir);
388+ textdomain(domain);
389+}
390+
391+void qmlInit(QDeclarativeContext* context)
392+{
393+ static QmlHelper helper;
394+ context->setContextProperty("u2d", &helper);
395+}
396+
397+QString QmlHelper::tr(const QString& text)
398+{
399+ return ::u2dTr(text.toUtf8().constData());
400+}
401+
402+QString QmlHelper::tr(const QString& singular, const QString& plural, int n)
403+{
404+ return ::u2dTr(
405+ singular.toUtf8().constData(),
406+ plural.toUtf8().constData(),
407+ n);
408+}
409+
410+} // namespace
411+
412+QString u2dTr(const char* text)
413+{
414+ return QString::fromUtf8(gettext(text));
415+}
416+
417+QString u2dTr(const char* singular, const char* plural, int n)
418+{
419+ QString text = QString::fromUtf8(ngettext(singular, plural, n));
420+ // Note: if `text` is "%%n" (meaning the string on screen should be "%n"
421+ // literally), this will fail. I think we don't care for now.
422+ text.replace("%n", QString::number(n));
423+ return text;
424+}
425+
426+#include <unity2dtr.moc>
427
428=== added file 'libunity-2d-private/src/unity2dtr.h'
429--- libunity-2d-private/src/unity2dtr.h 1970-01-01 00:00:00 +0000
430+++ libunity-2d-private/src/unity2dtr.h 2011-03-16 17:45:58 +0000
431@@ -0,0 +1,70 @@
432+/*
433+ * This file is part of unity-2d
434+ *
435+ * Copyright 2011 Canonical Ltd.
436+ *
437+ * Authors:
438+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
439+ *
440+ * This program is free software; you can redistribute it and/or modify
441+ * it under the terms of the GNU General Public License as published by
442+ * the Free Software Foundation; version 3.
443+ *
444+ * This program is distributed in the hope that it will be useful,
445+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
446+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
447+ * GNU General Public License for more details.
448+ *
449+ * You should have received a copy of the GNU General Public License
450+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
451+ */
452+#ifndef UNITY2DTR_H
453+#define UNITY2DTR_H
454+
455+// Qt
456+#include <QObject>
457+
458+class QString;
459+class QDeclarativeContext;
460+
461+namespace Unity2dTr
462+{
463+
464+/**
465+ * Installs our gettext catalog
466+ */
467+void init(const char* domain, const char* localeDir);
468+
469+/**
470+ * Add an object named "u2d" to context.
471+ *
472+ * One can then get translations with u2d.tr("english text")
473+ */
474+void qmlInit(QDeclarativeContext* context);
475+
476+/**
477+ * @internal
478+ */
479+class QmlHelper : public QObject
480+{
481+ Q_OBJECT
482+public:
483+ Q_INVOKABLE QString tr(const QString&);
484+ Q_INVOKABLE QString tr(const QString& singular, const QString& plural, int n);
485+};
486+
487+} // namespace
488+
489+/**
490+ * Translate the string text
491+ */
492+QString u2dTr(const char* text);
493+
494+/**
495+ * Plural version of utr. Should be called like this:
496+ *
497+ * u2dTr("%n file", "%n files", count)
498+ */
499+QString u2dTr(const char* singular, const char* plural, int n);
500+
501+#endif /* UNITY2DTR_H */
502
503=== modified file 'libunity-2d-private/tests/CMakeLists.txt'
504--- libunity-2d-private/tests/CMakeLists.txt 2011-02-24 00:31:39 +0000
505+++ libunity-2d-private/tests/CMakeLists.txt 2011-03-16 17:45:58 +0000
506@@ -31,18 +31,18 @@
507 endmacro(libunity_2d_tests)
508
509 libunity_2d_tests(
510- gettexttest
511 keyboardmodifiersmonitortest
512 paneltest
513+ unity2dtrtest
514 )
515
516-add_custom_target(gettexttest_po COMMAND
517+add_custom_target(unity2dtr_po COMMAND
518 mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/locale/fr/LC_MESSAGES/
519 && ${GETTEXT_MSGFMT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/fr.po
520- -o ${CMAKE_CURRENT_BINARY_DIR}/locale/fr/LC_MESSAGES/gettexttest.mo
521+ -o ${CMAKE_CURRENT_BINARY_DIR}/locale/fr/LC_MESSAGES/unity2dtrtest.mo
522 )
523
524-add_dependencies(gettexttest gettexttest_po)
525+add_dependencies(unity2dtrtest unity2dtr_po)
526
527 # gnomesessionclienttest
528 add_executable(gnomesessionclienttesthelper
529
530=== modified file 'libunity-2d-private/tests/fr.po'
531--- libunity-2d-private/tests/fr.po 2011-02-18 14:21:08 +0000
532+++ libunity-2d-private/tests/fr.po 2011-03-16 17:45:58 +0000
533@@ -8,3 +8,8 @@
534 msgctxt "Not far"
535 msgid "Close"
536 msgstr "Près"
537+
538+msgid "%n file"
539+msgid_plural "%n files"
540+msgstr[0] "%n fichier"
541+msgstr[1] "%n fichiers"
542
543=== removed file 'libunity-2d-private/tests/gettexttest.cpp'
544--- libunity-2d-private/tests/gettexttest.cpp 2011-02-18 16:18:16 +0000
545+++ libunity-2d-private/tests/gettexttest.cpp 1970-01-01 00:00:00 +0000
546@@ -1,74 +0,0 @@
547-/*
548- * This file is part of unity-2d
549- *
550- * Copyright 2011 Canonical Ltd.
551- *
552- * Authors:
553- * - Aurélien Gâteau <aurelien.gateau@canonical.com>
554- *
555- * This program is free software; you can redistribute it and/or modify
556- * it under the terms of the GNU General Public License as published by
557- * the Free Software Foundation; version 3.
558- *
559- * This program is distributed in the hope that it will be useful,
560- * but WITHOUT ANY WARRANTY; without even the implied warranty of
561- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
562- * GNU General Public License for more details.
563- *
564- * You should have received a copy of the GNU General Public License
565- * along with this program. If not, see <http://www.gnu.org/licenses/>.
566- */
567-
568-// Local
569-#include <gettexttranslator.h>
570-
571-// Qt
572-#include <QCoreApplication>
573-#include <QtTest>
574-
575-#include <config-test.h>
576-
577-class GettextTest : public QObject
578-{
579- Q_OBJECT
580-private Q_SLOTS:
581- void initTestCase()
582- {
583- setenv("LC_MESSAGES", "fr_FR.utf8", 1 /* overwrite */);
584- GettextTranslator* translator = new GettextTranslator(QCoreApplication::instance());
585- QVERIFY(translator->init("gettexttest", TEST_LOCALE_DIR));
586- QCoreApplication::installTranslator(translator);
587- }
588-
589- void testTranslate()
590- {
591- QCOMPARE(QCoreApplication::translate("", "Hello"),
592- QString("Bonjour"));
593-
594- QCOMPARE(QCoreApplication::translate("Qt-context-is-ignored", "Hello"),
595- QString("Bonjour"));
596-
597- QCOMPARE(QCoreApplication::translate("", "Not translated"),
598- QString("Not translated"));
599- }
600-
601- void testTranslateWithDisambiguation()
602- {
603- QCOMPARE(QCoreApplication::translate("", "Close", "Closing a door"),
604- QString("Fermer"));
605-
606- QCOMPARE(QCoreApplication::translate("", "Close", "Not far"),
607- QString::fromUtf8("Près"));
608- }
609-
610- void testTranslateWithEmptyNonNullDisambiguation()
611- {
612- // qsTr in QML calls translate with an empty but non-null disambiguation string
613- QCOMPARE(QCoreApplication::translate("", "Hello", ""),
614- QString("Bonjour"));
615- }
616-};
617-
618-QTEST_MAIN(GettextTest)
619-
620-#include "gettexttest.moc"
621
622=== added file 'libunity-2d-private/tests/unity2dtrtest.cpp'
623--- libunity-2d-private/tests/unity2dtrtest.cpp 1970-01-01 00:00:00 +0000
624+++ libunity-2d-private/tests/unity2dtrtest.cpp 2011-03-16 17:45:58 +0000
625@@ -0,0 +1,55 @@
626+/*
627+ * This file is part of unity-2d
628+ *
629+ * Copyright 2011 Canonical Ltd.
630+ *
631+ * Authors:
632+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
633+ *
634+ * This program is free software; you can redistribute it and/or modify
635+ * it under the terms of the GNU General Public License as published by
636+ * the Free Software Foundation; version 3.
637+ *
638+ * This program is distributed in the hope that it will be useful,
639+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
640+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
641+ * GNU General Public License for more details.
642+ *
643+ * You should have received a copy of the GNU General Public License
644+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
645+ */
646+
647+// Local
648+#include <unity2dtr.h>
649+
650+// Qt
651+#include <QCoreApplication>
652+#include <QtTest>
653+
654+#include <config-test.h>
655+
656+class Unity2dTrTest : public QObject
657+{
658+ Q_OBJECT
659+private Q_SLOTS:
660+ void initTestCase()
661+ {
662+ Unity2dTr::init("unity2dtrtest", TEST_LOCALE_DIR);
663+ }
664+
665+ void testTranslate()
666+ {
667+ QCOMPARE(u2dTr("Hello"), QString("Bonjour"));
668+ QCOMPARE(u2dTr("Not translated"), QString("Not translated"));
669+ }
670+
671+ void testPluralHandling()
672+ {
673+ QCOMPARE(u2dTr("%n file", "%n files", 1), QString("1 fichier"));
674+ QCOMPARE(u2dTr("%n file", "%n files", 2), QString("2 fichiers"));
675+ }
676+};
677+
678+QTEST_MAIN(Unity2dTrTest)
679+
680+#include "unity2dtrtest.moc"
681
682=== modified file 'panel/app/main.cpp'
683--- panel/app/main.cpp 2011-03-07 14:52:11 +0000
684+++ panel/app/main.cpp 2011-03-16 17:45:58 +0000
685@@ -30,12 +30,12 @@
686 #include <legacytray/legacytrayapplet.h>
687
688 // Unity
689-#include <gettexttranslator.h>
690 #include <gnomesessionclient.h>
691 #include <unity2ddebug.h>
692 #include <unity2dpanel.h>
693 #include <unity2dapplication.h>
694 #include <unity2dstyle.h>
695+#include <unity2dtr.h>
696
697 // Qt
698 #include <QAbstractFileEngineHandler>
699@@ -107,9 +107,7 @@
700 client.connectToSessionManager();
701
702 /* Configure translations */
703- GettextTranslator translator;
704- translator.init("unity-2d", INSTALL_PREFIX "/share/locale");
705- QApplication::installTranslator(&translator);
706+ Unity2dTr::init("unity-2d", INSTALL_PREFIX "/share/locale");
707
708 Unity2dPanel panel;
709 panel.setEdge(Unity2dPanel::TopEdge);
710
711=== modified file 'places/GroupHeader.qml'
712--- places/GroupHeader.qml 2011-02-21 21:04:36 +0000
713+++ places/GroupHeader.qml 2011-03-16 17:45:58 +0000
714@@ -65,7 +65,7 @@
715 TextCustom {
716 id: label
717
718- text: groupHeader.folded ? qsTr("See %1 more results").arg(availableCount) : qsTr("See fewer results")
719+ text: groupHeader.folded ? u2d.tr("See %1 more results").arg(availableCount) : u2d.tr("See fewer results")
720 anchors.left: parent.left
721 anchors.baseline: parent.baseline
722 }
723
724=== modified file 'places/Home.qml'
725--- places/Home.qml 2011-03-12 14:41:36 +0000
726+++ places/Home.qml 2011-03-16 17:45:58 +0000
727@@ -155,47 +155,47 @@
728
729 /* FIXME: dummy icons need to be replaced by design's */
730 HomeButton {
731- label: qsTr("Find Media Apps")
732+ label: u2d.tr("Find Media Apps")
733 icon: "artwork/find_media_apps.png"
734 onClicked: activatePlaceEntry("/usr/share/unity/places/applications.place", "Files", 9)
735 }
736
737 HomeButton {
738- label: qsTr("Find Internet Apps")
739+ label: u2d.tr("Find Internet Apps")
740 icon: "artwork/find_internet_apps.png"
741 onClicked: activatePlaceEntry("/usr/share/unity/places/applications.place", "Files", 8)
742 }
743
744 HomeButton {
745- label: qsTr("Find More Apps")
746+ label: u2d.tr("Find More Apps")
747 icon: "artwork/find_more_apps.png"
748 onClicked: activatePlaceEntry("/usr/share/unity/places/applications.place", "Files", 0)
749 }
750
751 HomeButton {
752- label: qsTr("Find Files")
753+ label: u2d.tr("Find Files")
754 icon: "artwork/find_files.png"
755 onClicked: activatePlaceEntry("/usr/share/unity/places/files.place", "Files", 0)
756 }
757
758 /* FIXME: use user's preferred applications instead of hardcoding them */
759 HomeButtonApplication {
760- label: qsTr("Browse the Web")
761+ label: u2d.tr("Browse the Web")
762 desktopFile: "firefox.desktop"
763 }
764
765 HomeButtonApplication {
766- label: qsTr("View Photos")
767+ label: u2d.tr("View Photos")
768 desktopFile: "shotwell.desktop"
769 }
770
771 HomeButtonApplication {
772- label: qsTr("Check Email")
773+ label: u2d.tr("Check Email")
774 desktopFile: "evolution.desktop"
775 }
776
777 HomeButtonApplication {
778- label: qsTr("Listen to Music")
779+ label: u2d.tr("Listen to Music")
780 desktopFile: "banshee-1.desktop"
781 }
782 }
783
784=== modified file 'places/SearchEntry.qml'
785--- places/SearchEntry.qml 2011-03-11 14:36:05 +0000
786+++ places/SearchEntry.qml 2011-03-16 17:45:58 +0000
787@@ -140,9 +140,9 @@
788 if(search_input.text)
789 return ""
790 else if(dash.currentPage != undefined && dash.currentPage.model.name)
791- return qsTr("Search for %1").arg(dash.currentPage.model.name)
792+ return u2d.tr("Search for %1").arg(dash.currentPage.model.name)
793 else
794- return qsTr("Search")
795+ return u2d.tr("Search")
796 }
797 }
798 }
799
800=== modified file 'places/SearchRefine.qml'
801--- places/SearchRefine.qml 2011-02-14 13:53:03 +0000
802+++ places/SearchRefine.qml 2011-03-16 17:45:58 +0000
803@@ -40,7 +40,7 @@
804 TextCustom {
805 id: title
806
807- text: qsTr("Refine search")
808+ text: u2d.tr("Refine search")
809 font.bold: true
810 font.pixelSize: 16
811
812@@ -63,7 +63,7 @@
813 id: optionsModel
814
815 SearchRefineOptionType {
816- title: qsTr("Type")
817+ title: u2d.tr("Type")
818 placeEntryModel: searchRefine.placeEntryModel
819 }
820 }
821
822=== modified file 'places/app/places.cpp'
823--- places/app/places.cpp 2011-03-12 14:12:29 +0000
824+++ places/app/places.cpp 2011-03-16 17:45:58 +0000
825@@ -34,8 +34,8 @@
826 #include <gtk/gtk.h>
827
828 // unity-2d
829-#include <gettexttranslator.h>
830 #include <unity2ddebug.h>
831+#include <unity2dtr.h>
832
833 #include "dashdeclarativeview.h"
834 #include "config.h"
835@@ -65,9 +65,8 @@
836 }
837
838 /* Configure translations */
839- GettextTranslator translator;
840- translator.init("unity-2d", INSTALL_PREFIX "/share/locale");
841- QApplication::installTranslator(&translator);
842+ Unity2dTr::init("unity-2d", INSTALL_PREFIX "/share/locale");
843+ Unity2dTr::qmlInit(view.rootContext());
844
845 view.engine()->addImportPath(unity2dImportPath());
846 /* Note: baseUrl seems to be picky: if it does not end with a slash,
847
848=== modified file 'po/fr.po'
849--- po/fr.po 2011-03-01 16:40:00 +0000
850+++ po/fr.po 2011-03-16 17:45:58 +0000
851@@ -8,7 +8,7 @@
852 msgstr ""
853 "Project-Id-Version: PACKAGE VERSION\n"
854 "Report-Msgid-Bugs-To: https://bugs.launchpad.net/unity-2d/+filebug\n"
855-"POT-Creation-Date: 2011-02-21 11:06+0100\n"
856+"POT-Creation-Date: 2011-03-16 18:27+0100\n"
857 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
858 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
859 "Language-Team: LANGUAGE <LL@li.org>\n"
860@@ -17,76 +17,95 @@
861 "Content-Type: text/plain; charset=UTF-8\n"
862 "Content-Transfer-Encoding: 8bit\n"
863
864-#: launcher/UnityApplications/trash.cpp:198
865+#: launcher/UnityApplications/trash.cpp:194
866 #, c-format, qt-plural-format
867-msgid "%n item(s) in trash"
868-msgstr ""
869-
870-#: launcher/UnityApplications/launcherdevice.cpp:222
871+msgid "%n item in trash"
872+msgid_plural "%n items in trash"
873+msgstr[0] "%n élément dans la corbeille"
874+msgstr[1] "%n éléments dans la corbeille"
875+
876+#: places/Home.qml:183
877+msgid "Browse the Web"
878+msgstr ""
879+
880+#: places/Home.qml:193
881+msgid "Check Email"
882+msgstr ""
883+
884+#: launcher/UnityApplications/launcherdevice.cpp:228
885 msgid "Eject"
886 msgstr ""
887
888-#: places/Home.qml:111
889-msgid "Email & Chat"
890-msgstr ""
891-
892-#: launcher/UnityApplications/trash.cpp:205
893+#: launcher/UnityApplications/trash.cpp:201
894 msgid "Empty Trash"
895 msgstr ""
896
897-#: places/Home.qml:123
898-msgid "Files & Folders"
899-msgstr ""
900-
901-#: places/Home.qml:105
902-msgid "Games"
903-msgstr ""
904-
905-#: places/Home.qml:129
906-msgid "Get New Apps"
907-msgstr ""
908-
909-#: launcher/UnityApplications/launcherapplication.cpp:719
910+#: places/Home.qml:176
911+msgid "Find Files"
912+msgstr ""
913+
914+#: places/Home.qml:164
915+msgid "Find Internet Apps"
916+msgstr ""
917+
918+#: places/Home.qml:158
919+msgid "Find Media Apps"
920+msgstr ""
921+
922+#: places/Home.qml:170
923+msgid "Find More Apps"
924+msgstr ""
925+
926+#: launcher/UnityApplications/launcherapplication.cpp:751
927 msgid "Keep In Launcher"
928 msgstr ""
929
930-#: places/Home.qml:93
931-msgid "Music"
932-msgstr ""
933-
934-#: places/Home.qml:117
935-msgid "Office"
936-msgstr ""
937-
938-#: places/Home.qml:99
939-msgid "Photos & Videos"
940-msgstr ""
941-
942-#: launcher/UnityApplications/launcherapplication.cpp:727
943+#: places/Home.qml:198
944+msgid "Listen to Music"
945+msgstr ""
946+
947+#: launcher/UnityApplications/launcherapplication.cpp:758
948 msgid "Quit"
949 msgstr ""
950
951-#: launcher/UnityApplications/launcherapplication.cpp:719
952+#: places/SearchRefine.qml:43
953+msgid "Refine search"
954+msgstr ""
955+
956+#: launcher/UnityApplications/launcherapplication.cpp:751
957 msgid "Remove From Launcher"
958 msgstr ""
959
960-#: places/SearchEntry.qml:114
961+#: places/SearchEntry.qml:145
962 msgid "Search"
963 msgstr ""
964
965-#: places/SearchEntry.qml:112
966-#, qt-format
967-msgid "Search %1"
968-msgstr ""
969-
970-#: launcher/UnityApplications/trash.cpp:71
971+#: places/SearchEntry.qml:143
972+#, qt-format
973+msgid "Search for %1"
974+msgstr ""
975+
976+#: places/GroupHeader.qml:68
977+#, qt-format
978+msgid "See %1 more results"
979+msgstr ""
980+
981+#: places/GroupHeader.qml:68
982+msgid "See fewer results"
983+msgstr ""
984+
985+#: launcher/UnityApplications/trash.cpp:74
986 msgid "Trash"
987 msgstr ""
988
989-#: places/Home.qml:77
990-msgid "Web"
991-msgstr ""
992-
993-#: launcher/UnityApplications/workspaces.cpp:66
994+#: places/SearchRefine.qml:66
995+msgid "Type"
996+msgstr ""
997+
998+#: places/Home.qml:188
999+msgid "View Photos"
1000+msgstr ""
1001+
1002+#: launcher/UnityApplications/workspaces.cpp:69
1003 msgid "Workspaces"
1004 msgstr ""
1005
1006=== modified file 'po/unity-2d.pot'
1007--- po/unity-2d.pot 2011-02-24 14:01:49 +0000
1008+++ po/unity-2d.pot 2011-03-16 17:45:58 +0000
1009@@ -8,7 +8,7 @@
1010 msgstr ""
1011 "Project-Id-Version: unity-2d\n"
1012 "Report-Msgid-Bugs-To: https://bugs.launchpad.net/unity-2d/+filebug\n"
1013-"POT-Creation-Date: 2011-02-24 14:57+0100\n"
1014+"POT-Creation-Date: 2011-03-16 18:27+0100\n"
1015 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1016 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1017 "Language-Team: LANGUAGE <LL@li.org>\n"
1018@@ -16,6 +16,7 @@
1019 "MIME-Version: 1.0\n"
1020 "Content-Type: text/plain; charset=CHARSET\n"
1021 "Content-Transfer-Encoding: 8bit\n"
1022+"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
1023
1024 #: places/Home.qml:158
1025 msgid "Find Media Apps"
1026@@ -57,12 +58,12 @@
1027 msgid "Type"
1028 msgstr ""
1029
1030-#: places/SearchEntry.qml:137
1031+#: places/SearchEntry.qml:143
1032 #, qt-format
1033 msgid "Search for %1"
1034 msgstr ""
1035
1036-#: places/SearchEntry.qml:139
1037+#: places/SearchEntry.qml:145
1038 msgid "Search"
1039 msgstr ""
1040
1041@@ -75,35 +76,37 @@
1042 msgid "See fewer results"
1043 msgstr ""
1044
1045-#: launcher/UnityApplications/launcherapplication.cpp:758
1046+#: launcher/UnityApplications/launcherapplication.cpp:751
1047 msgid "Keep In Launcher"
1048 msgstr ""
1049
1050-#: launcher/UnityApplications/launcherapplication.cpp:758
1051+#: launcher/UnityApplications/launcherapplication.cpp:751
1052 msgid "Remove From Launcher"
1053 msgstr ""
1054
1055-#: launcher/UnityApplications/launcherapplication.cpp:766
1056+#: launcher/UnityApplications/launcherapplication.cpp:758
1057 msgid "Quit"
1058 msgstr ""
1059
1060-#: launcher/UnityApplications/launcherdevice.cpp:222
1061+#: launcher/UnityApplications/launcherdevice.cpp:228
1062 msgid "Eject"
1063 msgstr ""
1064
1065-#: launcher/UnityApplications/workspaces.cpp:66
1066+#: launcher/UnityApplications/workspaces.cpp:69
1067 msgid "Workspaces"
1068 msgstr ""
1069
1070-#: launcher/UnityApplications/trash.cpp:71
1071+#: launcher/UnityApplications/trash.cpp:74
1072 msgid "Trash"
1073 msgstr ""
1074
1075-#: launcher/UnityApplications/trash.cpp:198
1076+#: launcher/UnityApplications/trash.cpp:194
1077 #, c-format, qt-plural-format
1078-msgid "%n item(s) in trash"
1079-msgstr ""
1080+msgid "%n item in trash"
1081+msgid_plural "%n items in trash"
1082+msgstr[0] ""
1083+msgstr[1] ""
1084
1085-#: launcher/UnityApplications/trash.cpp:205
1086+#: launcher/UnityApplications/trash.cpp:201
1087 msgid "Empty Trash"
1088 msgstr ""
1089
1090=== modified file 'po/update-unity-2d-pot'
1091--- po/update-unity-2d-pot 2011-02-24 14:01:26 +0000
1092+++ po/update-unity-2d-pot 2011-03-16 17:45:58 +0000
1093@@ -10,15 +10,18 @@
1094 trap 'rm -f "$GETTEXT_FILES"' EXIT
1095 cd ..
1096 find \( -name '*.cpp' -o -name '*.qml' \) \
1097- -a ! \( -path './debian/*' -o -path './build/*' -o -path './obj-*-linux-gnu/*' -o -path './.bzr/*' \) \
1098+ -a ! \( -path './debian/*' -o -path './build/*' -o -path './obj-*-linux-gnu/*' -o -path './.bzr/*' -o -path './libunity-2d-private/tests/*' \) \
1099 > $GETTEXT_FILES
1100
1101 # Generate pot from our list
1102+# Note: we use --keyword=tr for QML files because --keyword=u2d.tr does not
1103+# work
1104 xgettext \
1105 --output $PO_DIR/unity-2d.pot \
1106 --files-from $GETTEXT_FILES \
1107 --qt --c++ \
1108- --keyword=tr --keyword=qsTr \
1109+ --keyword=u2dTr:1,1t --keyword=u2dTr:1,2,3t \
1110+ --keyword=tr:1,1t --keyword=tr:1,2,3t \
1111 --package-name unity-2d \
1112 --copyright-holder "Canonical Ltd" \
1113 --msgid-bugs-address "https://bugs.launchpad.net/unity-2d/+filebug"

Subscribers

People subscribed via source and target branches