Merge lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/i18ntagRTM into lp:ubuntu-ui-toolkit/rtm

Proposed by Cris Dywan
Status: Merged
Approved by: Tim Peeters
Approved revision: 1145
Merged at revision: 1145
Proposed branch: lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/i18ntagRTM
Merge into: lp:ubuntu-ui-toolkit/rtm
Diff against target: 144 lines (+58/-3)
8 files modified
components.api (+3/-0)
modules/Ubuntu/Components/plugin/i18n.cpp (+27/-0)
modules/Ubuntu/Components/plugin/i18n.h (+1/-0)
po/update-pot.sh (+1/-1)
tests/unit/tst_i18n/po/en_US.po (+3/-0)
tests/unit/tst_i18n/src/LocalizedApp.qml (+7/-0)
tests/unit/tst_i18n/src/tst_i18n.cpp (+9/-1)
tests/unit/tst_i18n/tst_i18n.pro (+7/-1)
To merge this branch: bzr merge lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/i18ntagRTM
Reviewer Review Type Date Requested Status
Tim Peeters Approve
Review via email: mp+249357@code.launchpad.net

Commit message

Implement i18n.tag function and unit tests

To post a comment you must log in.
Revision history for this message
Tim Peeters (tpeeters) wrote :

Same change as for changing, but without the context parameter.

review: Approve
Revision history for this message
Tim Peeters (tpeeters) wrote :

*Same change as for _staging_, but without the context parameter.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'components.api'
2--- components.api 2014-11-27 13:40:49 +0000
3+++ components.api 2015-02-11 16:53:22 +0000
4@@ -1058,6 +1058,9 @@
5 Parameter { name: "singular"; type: "string" }
6 Parameter { name: "plural"; type: "string" }
7 Parameter { name: "n"; type: "int" }
8+ Method {
9+ name: "tag"
10+ Parameter { name: "text"; type: "string" }
11 prototype: "QObject"
12 name: "Haptics"
13 exports: ["Haptics -1.-1"]
14
15=== modified file 'modules/Ubuntu/Components/plugin/i18n.cpp'
16--- modules/Ubuntu/Components/plugin/i18n.cpp 2014-05-27 11:44:09 +0000
17+++ modules/Ubuntu/Components/plugin/i18n.cpp 2015-02-11 16:53:22 +0000
18@@ -187,3 +187,30 @@
19 return QString::fromUtf8(C::dngettext(domain.toUtf8(), singular.toUtf8(), plural.toUtf8(), n));
20 }
21 }
22+
23+/*!
24+ * \qmlmethod string i18n::tag(string text)
25+ * Mark \a text for translation at a later point. Typically this allows an API
26+ * to take the original string and pass it to dtr (or dgettext).
27+ *
28+ * \qml
29+ * import QtQuick 2.0
30+ * import UserMetrics 0.1
31+ *
32+ * Metric {
33+ * name: "distance"
34+ * format: i18n.tag("Distance covered today: %1 km")
35+ * emptyFormat: i18n.tag("No running today")
36+ * domain: "runner.forest"
37+ * }
38+ * \endqml
39+ *
40+ * The strings tagged for localzation above are passed to the implementation
41+ * of UserMetrics verbatim, as well as the domain of the app. Display and
42+ * translation of the strings will happen in the lockscreen, where the same
43+ * strings will be passed to i18n.tr.
44+ */
45+QString UbuntuI18n::tag(const QString& text)
46+{
47+ return text;
48+}
49
50=== modified file 'modules/Ubuntu/Components/plugin/i18n.h'
51--- modules/Ubuntu/Components/plugin/i18n.h 2013-10-29 10:57:08 +0000
52+++ modules/Ubuntu/Components/plugin/i18n.h 2015-02-11 16:53:22 +0000
53@@ -46,6 +46,7 @@
54 Q_INVOKABLE QString tr(const QString& singular, const QString& plural, int n);
55 Q_INVOKABLE QString dtr(const QString& domain, const QString& text);
56 Q_INVOKABLE QString dtr(const QString& domain, const QString& singular, const QString& plural, int n);
57+ Q_INVOKABLE QString tag(const QString& text);
58
59 // getter
60 QString domain() const;
61
62=== modified file 'po/update-pot.sh'
63--- po/update-pot.sh 2014-09-01 17:02:40 +0000
64+++ po/update-pot.sh 2015-02-11 16:53:22 +0000
65@@ -50,7 +50,7 @@
66 --keyword=tr:1,2 \
67 --keyword=dtr:2 \
68 --keyword=dtr:2,3 \
69- --package-name $DOMAIN \
70+ --keyword=tag \
71 --package-name $DOMAIN \
72 --copyright-holder "Canonical Ltd"
73
74
75=== modified file 'tests/unit/tst_i18n/po/en_US.po'
76--- tests/unit/tst_i18n/po/en_US.po 2013-10-04 18:41:28 +0000
77+++ tests/unit/tst_i18n/po/en_US.po 2015-02-11 16:53:22 +0000
78@@ -15,3 +15,6 @@
79
80 msgid "Count the kilometres"
81 msgstr "Count the clicks"
82+
83+msgid "Count the kittens"
84+msgstr "Contar los gatitos"
85
86=== modified file 'tests/unit/tst_i18n/src/LocalizedApp.qml'
87--- tests/unit/tst_i18n/src/LocalizedApp.qml 2014-10-02 13:03:22 +0000
88+++ tests/unit/tst_i18n/src/LocalizedApp.qml 2015-02-11 16:53:22 +0000
89@@ -31,5 +31,12 @@
90 text: i18n.tr('Count the kilometres')
91 width: units.gu(15)
92 }
93+ Button {
94+ id: button2
95+ objectName: 'button2'
96+ anchors.top: button.bottom
97+ text: i18n.tag('Count the kittens')
98+ width: units.gu(15)
99+ }
100 }
101 }
102
103=== modified file 'tests/unit/tst_i18n/src/tst_i18n.cpp'
104--- tests/unit/tst_i18n/src/tst_i18n.cpp 2014-05-14 10:19:17 +0000
105+++ tests/unit/tst_i18n/src/tst_i18n.cpp 2015-02-11 16:53:22 +0000
106@@ -151,10 +151,18 @@
107 QQuickItem* button(testItem(page, "button"));
108 QVERIFY(button);
109 QCOMPARE(button->property("text").toString(), QString("Count the clicks"));
110-
111+ // Only tagged, not actually translated
112+ QQuickItem* button2(testItem(page, "button2"));
113+ QVERIFY(button2);
114+ QCOMPARE(button2->property("text").toString(), QString("Count the kittens"));
115+
116 // Translate in C++
117 QCOMPARE(i18n->dtr(i18n->domain(), QString("Welcome")), QString("Greets"));
118 QCOMPARE(i18n->tr(QString("Count the kilometres")), QString("Count the clicks"));
119+ // Only tagged, not actually translated
120+ QCOMPARE(i18n->tag(QString("Count the kittens")), QString("Count the kittens"));
121+ // Sanity-check that the test strings would otherwise work and not no-op by accident
122+ QCOMPARE(i18n->tr(QString("Count the kittens")), QString("Contar los gatitos"));
123 }
124 };
125
126
127=== modified file 'tests/unit/tst_i18n/tst_i18n.pro'
128--- tests/unit/tst_i18n/tst_i18n.pro 2014-05-14 10:19:17 +0000
129+++ tests/unit/tst_i18n/tst_i18n.pro 2015-02-11 16:53:22 +0000
130@@ -2,7 +2,13 @@
131 QT += gui
132 DEFINES += SRCDIR=\\\"$$PWD/\\\"
133
134-system(msgfmt po/en_US.po -o localizedApp/share/locale/en/LC_MESSAGES/localizedApp.mo)
135+DOMAIN = localizedApp
136+mo.target = mo
137+mo.commands = set -e;
138+mo.commands += echo Generating localization for $$DOMAIN;
139+mo.commands += msgfmt po/en_US.po -o $${DOMAIN}/share/locale/en/LC_MESSAGES/$${DOMAIN}.mo;
140+QMAKE_EXTRA_TARGETS += mo
141+PRE_TARGETDEPS += mo
142
143 SOURCES += \
144 src\/tst_i18n.cpp

Subscribers

People subscribed via source and target branches

to all changes: