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

Proposed by David Planella
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
dobey (community) Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
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.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
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
Revision history for this message
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

Finished cmake module conversion of i18n rules

148. By David Planella

Made path to i18n source files relative to po folder

147. By David Planella

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

146. By David Planella

Finished conversion of i18n rules to a module

145. By David Planella

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
=== modified file '.bzrignore'
--- .bzrignore 2014-07-15 12:41:13 +0000
+++ .bzrignore 2014-10-13 20:01:49 +0000
@@ -1,2 +1,3 @@
1*.user1*.user
2builddir2builddir
3*.click
34
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-09-27 10:36:56 +0000
+++ CMakeLists.txt 2014-10-13 20:01:49 +0000
@@ -1,18 +1,12 @@
1project(com.ubuntu.clock C CXX)1project(com.ubuntu.clock C CXX)
2cmake_minimum_required(VERSION 2.8.9)2cmake_minimum_required(VERSION 2.8.9)
33
4find_program(INTLTOOL_MERGE intltool-merge)4list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
5if(NOT INTLTOOL_MERGE)5
6 message(FATAL_ERROR "Could not find intltool-merge, please install the intltool package")6set(GETTEXT_PACKAGE ${CMAKE_PROJECT_NAME})
7endif()7
88set(UBUNTU_MANIFEST_PATH "manifest.json.in" CACHE INTERNAL "Relative path to the manifest file")
9find_program(INTLTOOL_EXTRACT intltool-extract)9set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra")
10if(NOT INTLTOOL_EXTRACT)
11 message(FATAL_ERROR "Could not find intltool-extract, please install the intltool package")
12endif()
13
14set (UBUNTU_MANIFEST_PATH "manifest.json.in" CACHE INTERNAL "Relative path to the manifest file")
15set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra")
1610
17find_package(Qt5Core)11find_package(Qt5Core)
18find_package(Qt5Qml)12find_package(Qt5Qml)
@@ -88,22 +82,6 @@
8882
89install(FILES ${URLS_FILE} DESTINATION "${CMAKE_INSTALL_DATADIR}/url-dispatcher/urls")83install(FILES ${URLS_FILE} DESTINATION "${CMAKE_INSTALL_DATADIR}/url-dispatcher/urls")
9084
91file(GLOB_RECURSE I18N_SRC_FILES
92 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/po
93 *.qml *.js)
94list(APPEND I18N_SRC_FILES ${DESKTOP_FILE}.in.in.h)
95list(SORT I18N_SRC_FILES)
96
97configure_file(${DESKTOP_FILE}.in.in ${DESKTOP_FILE}.in)
98
99add_custom_target(${DESKTOP_FILE} ALL
100 COMMENT "Merging translations into ${DESKTOP_FILE}..."
101 COMMAND LC_ALL=C ${INTLTOOL_MERGE} -d -u ${CMAKE_SOURCE_DIR}/po ${DESKTOP_FILE}.in ${DESKTOP_FILE}
102)
103
104install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE}
105 DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
106
107add_subdirectory(app)85add_subdirectory(app)
108add_subdirectory(backend)86add_subdirectory(backend)
109add_subdirectory(po)87add_subdirectory(po)
11088
=== added directory 'cmake'
=== added file 'cmake/FindIntltool.cmake'
--- cmake/FindIntltool.cmake 1970-01-01 00:00:00 +0000
+++ cmake/FindIntltool.cmake 2014-10-13 20:01:49 +0000
@@ -0,0 +1,11 @@
1# Finds the intltool program to merge and extract translations from .desktop files
2
3find_program(INTLTOOL_MERGE intltool-merge)
4if(NOT INTLTOOL_MERGE)
5 message(FATAL_ERROR "Could not find intltool-merge, please install the intltool package")
6endif()
7
8find_program(INTLTOOL_EXTRACT intltool-extract)
9if(NOT INTLTOOL_EXTRACT)
10 message(FATAL_ERROR "Could not find intltool-extract, please install the intltool package")
11endif()
012
=== added file 'cmake/Translations.cmake'
--- cmake/Translations.cmake 1970-01-01 00:00:00 +0000
+++ cmake/Translations.cmake 2014-10-13 20:01:49 +0000
@@ -0,0 +1,87 @@
1include(FindGettext)
2include(FindIntltool)
3
4# Builds and installs translations, compiling source .po files into binary .mo files.
5# It also merges .desktop file key translations from source .po files into a generated
6# .desktop file. It assumes a .desktop.in.in file exists at the top of the source tree
7#
8# Arguments:
9# - DOMAIN: translation domain, generally the name of the app or project.
10# It will determine the name of the installed .mo files
11# - DESKTOP_FILE: the name portion of the desktop file to merge translations into
12macro(add_translations DOMAIN DESKTOP_FILE)
13 # Find all translations (*.po files)
14 file(GLOB PO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.po)
15
16 # Iterate through all translations, build them and install them
17 foreach(PO_FILE ${PO_FILES})
18 get_filename_component(LANG ${PO_FILE} NAME_WE)
19 gettext_process_po_files(${LANG} ALL PO_FILES ${PO_FILE})
20 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${LANG}.gmo
21 DESTINATION ${CMAKE_INSTALL_LOCALEDIR}/${LANG}/LC_MESSAGES
22 RENAME ${DOMAIN}.mo)
23 endforeach(PO_FILE)
24
25 # Configure the desktop file and do cmake variable substitution
26 configure_file(${CMAKE_SOURCE_DIR}/${DESKTOP_FILE}.in.in ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE}.in)
27
28 # Extract translated desktop file keys from the po files and merge them
29 # into the final desktop file
30 add_custom_target(${DESKTOP_FILE} ALL
31 COMMENT "Merging translations into ${DESKTOP_FILE}..."
32 COMMAND LC_ALL=C ${INTLTOOL_MERGE} -d -u ${CMAKE_SOURCE_DIR}/po
33 ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE}.in
34 ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE}
35 )
36
37 # Install the generated desktop file
38 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE}
39 DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
40
41endmacro(add_translations)
42
43# Generates a translations template (.pot file) by extracting all translatable
44# strings from source files, including .desktop files. Requires a list of paths to
45# scan for translatable sources, relative to the root of the source tree
46#
47# Arguments:
48# - DOMAIN: translation domain, generally the name of the app or project.
49# It will determine the name of the generated .pot file
50# - DESKTOP_FILE: the name portion of the desktop file to merge translations into
51# - COPYRIGHT_HOLDER: the copyright holder arg to pass to xgettext
52macro(add_translations_template DOMAIN DESKTOP_FILE COPYRIGHT_HOLDER)
53 add_custom_target(pot ALL COMMENT "Generating translation template...")
54 find_program(XGETTEXT_EXECUTABLE xgettext)
55 set(PROJECT ${DOMAIN})
56 set(POT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${DOMAIN}.pot)
57
58 # Init the list which will hold all the sources across all dirs
59 set(SOURCES "")
60
61 # Add each directory's sources to the overall sources list
62 foreach(FILES_INPUT ${ARGN})
63 set(DIR ${CMAKE_SOURCE_DIR}/${FILES_INPUT})
64 file(GLOB_RECURSE DIR_SOURCES
65 RELATIVE ${CMAKE_SOURCE_DIR}/po
66 ${DIR}/*.c ${DIR}/*.cc ${DIR}/*.cpp ${DIR}/*.cxx
67 ${DIR}/*.h ${DIR}/*.vala ${DIR}/*.qml ${DIR}/*.js)
68 set(SOURCES ${SOURCES} ${DIR_SOURCES})
69 endforeach()
70
71 # Generate the translations template (.pot file)
72 add_custom_command(TARGET pot
73 COMMAND ${INTLTOOL_EXTRACT} --update --type=gettext/ini
74 --srcdir=${CMAKE_SOURCE_DIR} ${DESKTOP_FILE}.in.in
75 COMMAND ${XGETTEXT_EXECUTABLE} -o ${POT_FILE}
76 -d ${DOMAIN}
77 -D ${CMAKE_CURRENT_SOURCE_DIR}
78 -D ${CMAKE_CURRENT_BINARY_DIR}
79 --from-code=UTF-8
80 --c++ --qt --add-comments=TRANSLATORS
81 --keyword=tr --keyword=tr:1,2 --keyword=N_
82 --package-name='${PROJECT}'
83 --copyright-holder='${COPYRIGHT_HOLDER}'
84 ${SOURCES} ${DESKTOP_FILE}.in.in.h
85 COMMAND ${CMAKE_COMMAND} -E copy ${POT_FILE} ${CMAKE_CURRENT_SOURCE_DIR})
86
87endmacro(add_translations_template)
088
=== modified file 'po/CMakeLists.txt'
--- po/CMakeLists.txt 2014-08-13 06:41:37 +0000
+++ po/CMakeLists.txt 2014-10-13 20:01:49 +0000
@@ -1,30 +1,3 @@
1include(FindGettext)1include(Translations)
2find_program(GETTEXT_XGETTEXT_EXECUTABLE xgettext)2add_translations("${GETTEXT_PACKAGE}" "${DESKTOP_FILE}")
33add_translations_template("${GETTEXT_PACKAGE}" "${DESKTOP_FILE}" "Canonical Ltd." app backend)
4set(DOMAIN ${PROJECT_NAME})
5set(POT_FILE ${DOMAIN}.pot)
6file(GLOB PO_FILES *.po)
7
8add_custom_target(${POT_FILE} ALL
9 COMMENT "Generating translation template..."
10 COMMAND ${INTLTOOL_EXTRACT} --update --type=gettext/ini
11 --srcdir=${CMAKE_SOURCE_DIR} ${DESKTOP_FILE}.in.in
12 COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE} -o ${POT_FILE}
13 -D ${CMAKE_CURRENT_SOURCE_DIR}
14 -D ${CMAKE_CURRENT_BINARY_DIR}
15 --from-code=UTF-8
16 --c++ --qt --add-comments=TRANSLATORS
17 --keyword=tr --keyword=tr:1,2 --keyword=N_
18 --package-name='${PROJECT}'
19 --copyright-holder='Canonical Ltd.'
20 ${I18N_SRC_FILES}
21 COMMAND ${CMAKE_COMMAND} -E copy ${POT_FILE} ${CMAKE_CURRENT_SOURCE_DIR})
22
23foreach(PO_FILE ${PO_FILES})
24 get_filename_component(LANG ${PO_FILE} NAME_WE)
25 gettext_process_po_files(${LANG} ALL PO_FILES ${PO_FILE})
26 set(INSTALL_DIR ${CMAKE_INSTALL_LOCALEDIR}/${LANG}/LC_MESSAGES)
27 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${LANG}.gmo
28 DESTINATION ${INSTALL_DIR}
29 RENAME ${DOMAIN}.mo)
30endforeach(PO_FILE)

Subscribers

People subscribed via source and target branches