Merge lp:~unity-api-team/qtcreator-plugin-ubuntu/scope-template-translation-support into lp:qtcreator-plugin-ubuntu

Proposed by Pete Woods
Status: Merged
Approved by: Zoltan Balogh
Approved revision: 287
Merged at revision: 286
Proposed branch: lp:~unity-api-team/qtcreator-plugin-ubuntu/scope-template-translation-support
Merge into: lp:qtcreator-plugin-ubuntu
Diff against target: 224 lines (+77/-14)
9 files modified
share/qtcreator/templates/wizards/ubuntu/scope/CMakeLists.txt (+8/-3)
share/qtcreator/templates/wizards/ubuntu/scope/include/scope/localization.h (+22/-0)
share/qtcreator/templates/wizards/ubuntu/scope/po/CMakeLists.txt (+8/-0)
share/qtcreator/templates/wizards/ubuntu/scope/src/api/client.cpp (+18/-7)
share/qtcreator/templates/wizards/ubuntu/scope/src/scope/query.cpp (+4/-2)
share/qtcreator/templates/wizards/ubuntu/scope/src/scope/scope.cpp (+8/-2)
share/qtcreator/templates/wizards/ubuntu/scope/tests/CMakeLists.txt (+5/-0)
share/qtcreator/templates/wizards/ubuntu/scope/tests/unit/scope/test-scope.cpp (+1/-0)
share/qtcreator/templates/wizards/ubuntu/scope/wizard.xml (+3/-0)
To merge this branch: bzr merge lp:~unity-api-team/qtcreator-plugin-ubuntu/scope-template-translation-support
Reviewer Review Type Date Requested Status
Benjamin Zeller Approve
PS Jenkins bot continuous-integration Approve
Ubuntu SDK team Pending
Review via email: mp+238163@code.launchpad.net

Commit message

Add translation support to scope templates

Description of the change

Add translation support to scope templates

Requires this MR (https://code.launchpad.net/~unity-api-team/click/add-cmake-extras/+merge/235768) adding cmake-extras to the SDK.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
287. By Pete Woods

Fix unit tests

Revision history for this message
Pete Woods (pete-woods) wrote :

Okay, the tests should work again!

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Benjamin Zeller (zeller-benjamin) wrote :

OK

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'share/qtcreator/templates/wizards/ubuntu/scope/CMakeLists.txt'
2--- share/qtcreator/templates/wizards/ubuntu/scope/CMakeLists.txt 2014-10-10 07:46:06 +0000
3+++ share/qtcreator/templates/wizards/ubuntu/scope/CMakeLists.txt 2014-10-16 12:49:26 +0000
4@@ -2,9 +2,6 @@
5 cmake_minimum_required(VERSION 2.8.10)
6 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}")
7
8-#do not remove this line, its required for the correct functionality of the Ubuntu-SDK
9-set(UBUNTU_MANIFEST_PATH "manifest.json.in" CACHE INTERNAL "Tells QtCreator location and name of the manifest file")
10-
11 # We require g++ 4.9, to avoid ABI breakage with earlier version.
12 set(cxx_version_required 4.9)
13 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
14@@ -51,12 +48,19 @@
15 ${SCOPE_INCLUDE_DIRS}
16 )
17
18+# Do not remove this line, its required for the correct functionality of the Ubuntu-SDK
19+set(UBUNTU_MANIFEST_PATH "manifest.json.in" CACHE INTERNAL "Tells QtCreator location and name of the manifest file")
20 set(UBUNTU_PROJECT_TYPE "Scope" CACHE INTERNAL "Tells QtCreator this is a Scope project")
21+
22+# Important project paths
23+set(CMAKE_INSTALL_PREFIX /)
24 set(SCOPE_INSTALL_DIR "/%ClickHookName:l%")
25+set(GETTEXT_PACKAGE "%ProjectName:l%")
26
27 # If we need to refer to the scope's name or package in code, these definitions will help
28 add_definitions(-DPACKAGE_NAME="%ClickDomain:l%.%ProjectName:l%")
29 add_definitions(-DSCOPE_NAME="%ClickDomain:l%.%ProjectName:l%_%ClickHookName:l%")
30+add_definitions(-DGETTEXT_PACKAGE="${GETTEXT_PACKAGE}")
31
32 #This command figures out the target architecture and puts it into the manifest file
33 execute_process(
34@@ -82,6 +86,7 @@
35 # Add our main directories
36 add_subdirectory(src)
37 add_subdirectory(data)
38+add_subdirectory(po)
39
40 # Set up the tests
41 enable_testing()
42
43=== added file 'share/qtcreator/templates/wizards/ubuntu/scope/include/scope/localization.h'
44--- share/qtcreator/templates/wizards/ubuntu/scope/include/scope/localization.h 1970-01-01 00:00:00 +0000
45+++ share/qtcreator/templates/wizards/ubuntu/scope/include/scope/localization.h 2014-10-16 12:49:26 +0000
46@@ -0,0 +1,22 @@
47+#ifndef SCOPE_LOCALIZATION_H_
48+#define SCOPE_LOCALIZATION_H_
49+
50+#include <libintl.h>
51+#include <string>
52+
53+inline char * _(const char *__msgid) {
54+ return dgettext(GETTEXT_PACKAGE, __msgid);
55+}
56+
57+inline std::string _(const char *__msgid1, const char *__msgid2,
58+ unsigned long int __n) {
59+ char buffer [256];
60+ if (snprintf ( buffer, 256, dngettext(GETTEXT_PACKAGE, __msgid1, __msgid2, __n), __n ) >= 0) {
61+ return buffer;
62+ } else {
63+ return std::string();
64+ }
65+}
66+
67+#endif // SCOPE_LOCALIZATION_H_
68+
69
70=== added directory 'share/qtcreator/templates/wizards/ubuntu/scope/po'
71=== added file 'share/qtcreator/templates/wizards/ubuntu/scope/po/CMakeLists.txt'
72--- share/qtcreator/templates/wizards/ubuntu/scope/po/CMakeLists.txt 1970-01-01 00:00:00 +0000
73+++ share/qtcreator/templates/wizards/ubuntu/scope/po/CMakeLists.txt 2014-10-16 12:49:26 +0000
74@@ -0,0 +1,8 @@
75+include(UseXGettext)
76+
77+add_translations_directory(${GETTEXT_PACKAGE})
78+
79+add_translations_catalog(
80+ GETTEXT_PACKAGE ${GETTEXT_PACKAGE}
81+ SOURCE_DIRECTORIES "${CMAKE_SOURCE_DIR}/src"
82+)
83\ No newline at end of file
84
85=== modified file 'share/qtcreator/templates/wizards/ubuntu/scope/src/api/client.cpp'
86--- share/qtcreator/templates/wizards/ubuntu/scope/src/api/client.cpp 2014-09-23 12:19:52 +0000
87+++ share/qtcreator/templates/wizards/ubuntu/scope/src/api/client.cpp 2014-10-16 12:49:26 +0000
88@@ -23,13 +23,24 @@
89 Client::ResultList Client::search(const string &query) {
90 ResultList results;
91
92- Result result;
93- result.uri = "uri";
94- result.title = query;
95- result.art = "art.png";
96- result.subtitle = "subtitle";
97- result.description = "description";
98- results.emplace_back(result);
99+ {
100+ Result result;
101+ result.uri = "uri";
102+ result.title = query;
103+ result.art = "art.png";
104+ result.subtitle = "subtitle";
105+ result.description = "description";
106+ results.emplace_back(result);
107+ }
108+ {
109+ Result result;
110+ result.uri = "uri2";
111+ result.title = query;
112+ result.art = "art2.png";
113+ result.subtitle = "subtitle2";
114+ result.description = "description2";
115+ results.emplace_back(result);
116+ }
117
118 return results;
119 }
120
121=== modified file 'share/qtcreator/templates/wizards/ubuntu/scope/src/scope/query.cpp'
122--- share/qtcreator/templates/wizards/ubuntu/scope/src/scope/query.cpp 2014-09-23 12:19:52 +0000
123+++ share/qtcreator/templates/wizards/ubuntu/scope/src/scope/query.cpp 2014-10-16 12:49:26 +0000
124@@ -1,5 +1,6 @@
125 #include <boost/algorithm/string/trim.hpp>
126
127+#include <scope/localization.h>
128 #include <scope/query.h>
129
130 #include <unity/scopes/Annotation.h>
131@@ -125,7 +126,8 @@
132 }
133
134 // Register a category
135- auto cat = reply->register_category("results", "Results", "",
136+ auto cat = reply->register_category("results",
137+ _("1 result", "%d results", results.size()), "",
138 sc::CategoryRenderer(CATEGORY_TEMPLATE));
139
140 for (const auto &result : results) {
141@@ -219,7 +221,7 @@
142
143 // Register a category for the forecast
144 auto forecast_cat = reply->register_category("forecast",
145- "7 day forecast", "", sc::CategoryRenderer(WEATHER_TEMPLATE));
146+ _("7 day forecast"), "", sc::CategoryRenderer(WEATHER_TEMPLATE));
147
148 // For each of the forecast days
149 for (const auto &weather : forecast.weather) {
150
151=== modified file 'share/qtcreator/templates/wizards/ubuntu/scope/src/scope/scope.cpp'
152--- share/qtcreator/templates/wizards/ubuntu/scope/src/scope/scope.cpp 2014-09-23 12:19:52 +0000
153+++ share/qtcreator/templates/wizards/ubuntu/scope/src/scope/scope.cpp 2014-10-16 12:49:26 +0000
154@@ -1,6 +1,7 @@
155+#include <scope/localization.h>
156+#include <scope/preview.h>
157+#include <scope/query.h>
158 #include <scope/scope.h>
159-#include <scope/query.h>
160-#include <scope/preview.h>
161
162 #include <iostream>
163 #include <sstream>
164@@ -14,6 +15,11 @@
165 void Scope::start(string const&) {
166 config_ = make_shared<Config>();
167
168+ setlocale(LC_ALL, "");
169+ string translation_directory = ScopeBase::scope_directory()
170+ + "/../share/locale/";
171+ bindtextdomain(GETTEXT_PACKAGE, translation_directory.c_str());
172+
173 @if "%ContentType%" == "network"
174 // Under test we set a different API root
175 char *apiroot = getenv("NETWORK_SCOPE_APIROOT");
176
177=== modified file 'share/qtcreator/templates/wizards/ubuntu/scope/tests/CMakeLists.txt'
178--- share/qtcreator/templates/wizards/ubuntu/scope/tests/CMakeLists.txt 2014-09-25 14:21:35 +0000
179+++ share/qtcreator/templates/wizards/ubuntu/scope/tests/CMakeLists.txt 2014-10-16 12:49:26 +0000
180@@ -18,6 +18,11 @@
181 ${TEST_INCLUDE_DIRS}
182 )
183
184+# Where to find the scope ini file and .so
185+add_definitions(
186+ -DTEST_SCOPE_DIRECTORY="${CMAKE_BINARY_DIR}/src"
187+)
188+
189 @if "%ContentType%" == "network"
190 file(GLOB_RECURSE
191 TEST_FIXTURES
192
193=== modified file 'share/qtcreator/templates/wizards/ubuntu/scope/tests/unit/scope/test-scope.cpp'
194--- share/qtcreator/templates/wizards/ubuntu/scope/tests/unit/scope/test-scope.cpp 2014-09-23 12:19:52 +0000
195+++ share/qtcreator/templates/wizards/ubuntu/scope/tests/unit/scope/test-scope.cpp 2014-10-16 12:49:26 +0000
196@@ -68,6 +68,7 @@
197 setenv("NETWORK_SCOPE_APIROOT", apiroot.c_str(), true);
198
199 // Do the parent SetUp
200+ TypedScopeFixture::set_scope_directory(TEST_SCOPE_DIRECTORY);
201 TypedScopeFixtureScope::SetUp();
202 }
203
204
205=== modified file 'share/qtcreator/templates/wizards/ubuntu/scope/wizard.xml'
206--- share/qtcreator/templates/wizards/ubuntu/scope/wizard.xml 2014-10-09 07:03:22 +0000
207+++ share/qtcreator/templates/wizards/ubuntu/scope/wizard.xml 2014-10-16 12:49:26 +0000
208@@ -19,6 +19,7 @@
209
210 <file source="include/api/config.h"/>
211 <file source="include/api/client.h"/>
212+ <file source="include/scope/localization.h"/>
213 <file source="include/scope/preview.h"/>
214 <file source="include/scope/query.h"/>
215 <file source="include/scope/scope.h"/>
216@@ -29,6 +30,8 @@
217 <file source="src/scope/scope.cpp" openeditor="true"/>
218 <file source="src/scope/preview.cpp"/>
219
220+ <file source="po/CMakeLists.txt"/>
221+
222 <file source="tests/server/forecast/daily/Manchester,uk.json"/>
223 <file source="tests/server/forecast/daily/London,uk.json"/>
224 <file source="tests/server/weather/Manchester,uk.json"/>

Subscribers

People subscribed via source and target branches