Merge lp:~dpm/ubuntu-clock-app/i18n-module into lp:ubuntu-clock-app

Proposed by David Planella on 2014-10-13
Status: Work in progress
Proposed branch: lp:~dpm/ubuntu-clock-app/i18n-module
Merge into: lp:ubuntu-clock-app
Diff against target: 206 lines (+108/-58)
5 files modified
.bzrignore (+1/-0)
CMakeLists.txt (+6/-28)
cmake/FindIntltool.cmake (+11/-0)
cmake/Translations.cmake (+87/-0)
po/CMakeLists.txt (+3/-30)
To merge this branch: bzr merge lp:~dpm/ubuntu-clock-app/i18n-module
Reviewer Review Type Date Requested Status
Nekhelesh Ramananthan Needs Information on 2015-04-06
dobey (community) 2014-10-13 Approve on 2014-10-14
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2014-10-13
Review via email: mp+238213@code.launchpad.net

Commit message

Convert the cmake rules for internationalization to a cmake module we can easily reuse for all core apps.

Description of the change

Convert the cmake rules for internationalization to a cmake module we can easily reuse for all core apps.

Some notes on which I'd appreciate feedback from anyone reviewing this MP:

- It'd be nice to make the configuration and merging of the .desktop file optional, for those projects which don't use .desktop files. An example is indicators, which already use their own Translations.cmake module - it'd be good if all projects could use one and only module.
- I'm tempted to assume that DESKTOP_FILE == DOMAIN to make things easier and thus make it not a required arg to the macros
- I've not figured out how to pass a COPYRIGHT_HOLDER with spaces without showing escaped spaces in the final .pot file ("\ ")

To post a comment you must log in.
dobey (dobey) wrote :

I would add an if() to check that ${ARGN} is empty and recurse over all paths if so, or just get rid of the path arguments list, and always recurse over everything.

If this makes things easier for the core apps in the short-term I think it's fine. But I don't think this is a long-term solution to fixing builds of translations. For that, I think we need to fix up intltool to behave well with cmake, and provide an Intltool.cmake.

It looks fine to me otherwise though.

review: Approve
Nekhelesh Ramananthan (nik90) wrote :

Is this ready to be top-approved and merged? Might need to resync with trunk to check for any code conflicts.

review: Needs Information

Unmerged revisions

149. By David Planella on 2014-10-13

Finished cmake module conversion of i18n rules

148. By David Planella on 2014-10-13

Made path to i18n source files relative to po folder

147. By David Planella on 2014-10-13

Fix to pot file variable name, ignored generated clicks from bzr

146. By David Planella on 2014-10-13

Finished conversion of i18n rules to a module

145. By David Planella on 2014-10-13

Initial move of the translations cmake rules to a cmake module

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2014-07-15 12:41:13 +0000
3+++ .bzrignore 2014-10-13 20:01:49 +0000
4@@ -1,2 +1,3 @@
5 *.user
6 builddir
7+*.click
8
9=== modified file 'CMakeLists.txt'
10--- CMakeLists.txt 2014-09-27 10:36:56 +0000
11+++ CMakeLists.txt 2014-10-13 20:01:49 +0000
12@@ -1,18 +1,12 @@
13 project(com.ubuntu.clock C CXX)
14 cmake_minimum_required(VERSION 2.8.9)
15
16-find_program(INTLTOOL_MERGE intltool-merge)
17-if(NOT INTLTOOL_MERGE)
18- message(FATAL_ERROR "Could not find intltool-merge, please install the intltool package")
19-endif()
20-
21-find_program(INTLTOOL_EXTRACT intltool-extract)
22-if(NOT INTLTOOL_EXTRACT)
23- message(FATAL_ERROR "Could not find intltool-extract, please install the intltool package")
24-endif()
25-
26-set (UBUNTU_MANIFEST_PATH "manifest.json.in" CACHE INTERNAL "Relative path to the manifest file")
27-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra")
28+list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
29+
30+set(GETTEXT_PACKAGE ${CMAKE_PROJECT_NAME})
31+
32+set(UBUNTU_MANIFEST_PATH "manifest.json.in" CACHE INTERNAL "Relative path to the manifest file")
33+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra")
34
35 find_package(Qt5Core)
36 find_package(Qt5Qml)
37@@ -88,22 +82,6 @@
38
39 install(FILES ${URLS_FILE} DESTINATION "${CMAKE_INSTALL_DATADIR}/url-dispatcher/urls")
40
41-file(GLOB_RECURSE I18N_SRC_FILES
42- RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/po
43- *.qml *.js)
44-list(APPEND I18N_SRC_FILES ${DESKTOP_FILE}.in.in.h)
45-list(SORT I18N_SRC_FILES)
46-
47-configure_file(${DESKTOP_FILE}.in.in ${DESKTOP_FILE}.in)
48-
49-add_custom_target(${DESKTOP_FILE} ALL
50- COMMENT "Merging translations into ${DESKTOP_FILE}..."
51- COMMAND LC_ALL=C ${INTLTOOL_MERGE} -d -u ${CMAKE_SOURCE_DIR}/po ${DESKTOP_FILE}.in ${DESKTOP_FILE}
52-)
53-
54-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE}
55- DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
56-
57 add_subdirectory(app)
58 add_subdirectory(backend)
59 add_subdirectory(po)
60
61=== added directory 'cmake'
62=== added file 'cmake/FindIntltool.cmake'
63--- cmake/FindIntltool.cmake 1970-01-01 00:00:00 +0000
64+++ cmake/FindIntltool.cmake 2014-10-13 20:01:49 +0000
65@@ -0,0 +1,11 @@
66+# Finds the intltool program to merge and extract translations from .desktop files
67+
68+find_program(INTLTOOL_MERGE intltool-merge)
69+if(NOT INTLTOOL_MERGE)
70+ message(FATAL_ERROR "Could not find intltool-merge, please install the intltool package")
71+endif()
72+
73+find_program(INTLTOOL_EXTRACT intltool-extract)
74+if(NOT INTLTOOL_EXTRACT)
75+ message(FATAL_ERROR "Could not find intltool-extract, please install the intltool package")
76+endif()
77
78=== added file 'cmake/Translations.cmake'
79--- cmake/Translations.cmake 1970-01-01 00:00:00 +0000
80+++ cmake/Translations.cmake 2014-10-13 20:01:49 +0000
81@@ -0,0 +1,87 @@
82+include(FindGettext)
83+include(FindIntltool)
84+
85+# Builds and installs translations, compiling source .po files into binary .mo files.
86+# It also merges .desktop file key translations from source .po files into a generated
87+# .desktop file. It assumes a .desktop.in.in file exists at the top of the source tree
88+#
89+# Arguments:
90+# - DOMAIN: translation domain, generally the name of the app or project.
91+# It will determine the name of the installed .mo files
92+# - DESKTOP_FILE: the name portion of the desktop file to merge translations into
93+macro(add_translations DOMAIN DESKTOP_FILE)
94+ # Find all translations (*.po files)
95+ file(GLOB PO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.po)
96+
97+ # Iterate through all translations, build them and install them
98+ foreach(PO_FILE ${PO_FILES})
99+ get_filename_component(LANG ${PO_FILE} NAME_WE)
100+ gettext_process_po_files(${LANG} ALL PO_FILES ${PO_FILE})
101+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${LANG}.gmo
102+ DESTINATION ${CMAKE_INSTALL_LOCALEDIR}/${LANG}/LC_MESSAGES
103+ RENAME ${DOMAIN}.mo)
104+ endforeach(PO_FILE)
105+
106+ # Configure the desktop file and do cmake variable substitution
107+ configure_file(${CMAKE_SOURCE_DIR}/${DESKTOP_FILE}.in.in ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE}.in)
108+
109+ # Extract translated desktop file keys from the po files and merge them
110+ # into the final desktop file
111+ add_custom_target(${DESKTOP_FILE} ALL
112+ COMMENT "Merging translations into ${DESKTOP_FILE}..."
113+ COMMAND LC_ALL=C ${INTLTOOL_MERGE} -d -u ${CMAKE_SOURCE_DIR}/po
114+ ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE}.in
115+ ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE}
116+ )
117+
118+ # Install the generated desktop file
119+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE}
120+ DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
121+
122+endmacro(add_translations)
123+
124+# Generates a translations template (.pot file) by extracting all translatable
125+# strings from source files, including .desktop files. Requires a list of paths to
126+# scan for translatable sources, relative to the root of the source tree
127+#
128+# Arguments:
129+# - DOMAIN: translation domain, generally the name of the app or project.
130+# It will determine the name of the generated .pot file
131+# - DESKTOP_FILE: the name portion of the desktop file to merge translations into
132+# - COPYRIGHT_HOLDER: the copyright holder arg to pass to xgettext
133+macro(add_translations_template DOMAIN DESKTOP_FILE COPYRIGHT_HOLDER)
134+ add_custom_target(pot ALL COMMENT "Generating translation template...")
135+ find_program(XGETTEXT_EXECUTABLE xgettext)
136+ set(PROJECT ${DOMAIN})
137+ set(POT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${DOMAIN}.pot)
138+
139+ # Init the list which will hold all the sources across all dirs
140+ set(SOURCES "")
141+
142+ # Add each directory's sources to the overall sources list
143+ foreach(FILES_INPUT ${ARGN})
144+ set(DIR ${CMAKE_SOURCE_DIR}/${FILES_INPUT})
145+ file(GLOB_RECURSE DIR_SOURCES
146+ RELATIVE ${CMAKE_SOURCE_DIR}/po
147+ ${DIR}/*.c ${DIR}/*.cc ${DIR}/*.cpp ${DIR}/*.cxx
148+ ${DIR}/*.h ${DIR}/*.vala ${DIR}/*.qml ${DIR}/*.js)
149+ set(SOURCES ${SOURCES} ${DIR_SOURCES})
150+ endforeach()
151+
152+ # Generate the translations template (.pot file)
153+ add_custom_command(TARGET pot
154+ COMMAND ${INTLTOOL_EXTRACT} --update --type=gettext/ini
155+ --srcdir=${CMAKE_SOURCE_DIR} ${DESKTOP_FILE}.in.in
156+ COMMAND ${XGETTEXT_EXECUTABLE} -o ${POT_FILE}
157+ -d ${DOMAIN}
158+ -D ${CMAKE_CURRENT_SOURCE_DIR}
159+ -D ${CMAKE_CURRENT_BINARY_DIR}
160+ --from-code=UTF-8
161+ --c++ --qt --add-comments=TRANSLATORS
162+ --keyword=tr --keyword=tr:1,2 --keyword=N_
163+ --package-name='${PROJECT}'
164+ --copyright-holder='${COPYRIGHT_HOLDER}'
165+ ${SOURCES} ${DESKTOP_FILE}.in.in.h
166+ COMMAND ${CMAKE_COMMAND} -E copy ${POT_FILE} ${CMAKE_CURRENT_SOURCE_DIR})
167+
168+endmacro(add_translations_template)
169
170=== modified file 'po/CMakeLists.txt'
171--- po/CMakeLists.txt 2014-08-13 06:41:37 +0000
172+++ po/CMakeLists.txt 2014-10-13 20:01:49 +0000
173@@ -1,30 +1,3 @@
174-include(FindGettext)
175-find_program(GETTEXT_XGETTEXT_EXECUTABLE xgettext)
176-
177-set(DOMAIN ${PROJECT_NAME})
178-set(POT_FILE ${DOMAIN}.pot)
179-file(GLOB PO_FILES *.po)
180-
181-add_custom_target(${POT_FILE} ALL
182- COMMENT "Generating translation template..."
183- COMMAND ${INTLTOOL_EXTRACT} --update --type=gettext/ini
184- --srcdir=${CMAKE_SOURCE_DIR} ${DESKTOP_FILE}.in.in
185- COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE} -o ${POT_FILE}
186- -D ${CMAKE_CURRENT_SOURCE_DIR}
187- -D ${CMAKE_CURRENT_BINARY_DIR}
188- --from-code=UTF-8
189- --c++ --qt --add-comments=TRANSLATORS
190- --keyword=tr --keyword=tr:1,2 --keyword=N_
191- --package-name='${PROJECT}'
192- --copyright-holder='Canonical Ltd.'
193- ${I18N_SRC_FILES}
194- COMMAND ${CMAKE_COMMAND} -E copy ${POT_FILE} ${CMAKE_CURRENT_SOURCE_DIR})
195-
196-foreach(PO_FILE ${PO_FILES})
197- get_filename_component(LANG ${PO_FILE} NAME_WE)
198- gettext_process_po_files(${LANG} ALL PO_FILES ${PO_FILE})
199- set(INSTALL_DIR ${CMAKE_INSTALL_LOCALEDIR}/${LANG}/LC_MESSAGES)
200- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${LANG}.gmo
201- DESTINATION ${INSTALL_DIR}
202- RENAME ${DOMAIN}.mo)
203-endforeach(PO_FILE)
204+include(Translations)
205+add_translations("${GETTEXT_PACKAGE}" "${DESKTOP_FILE}")
206+add_translations_template("${GETTEXT_PACKAGE}" "${DESKTOP_FILE}" "Canonical Ltd." app backend)

Subscribers

People subscribed via source and target branches