[rkward] i18n: Avoid creating empty directories while installing translations (second attempt)

Thomas Friedrichsmeier null at kde.org
Tue Apr 17 08:20:26 UTC 2018


Git commit 23f685bb2d1eddd1eed2b16bde079c17112f5fdd by Thomas Friedrichsmeier.
Committed on 17/04/2018 at 08:19.
Pushed by tfry into branch 'master'.

Avoid creating empty directories while installing translations (second attempt)

M  +10   -7    i18n/CMakeLists.txt
M  +16   -3    i18n/compile_po.cmake

https://commits.kde.org/rkward/23f685bb2d1eddd1eed2b16bde079c17112f5fdd

diff --git a/i18n/CMakeLists.txt b/i18n/CMakeLists.txt
index ff259f09..bf3a4d65 100644
--- a/i18n/CMakeLists.txt
+++ b/i18n/CMakeLists.txt
@@ -9,7 +9,13 @@ MACRO(RKHandlePO _PO_FILES)
 		# NOTE: Could also be set only for specific ${_poid}s (e.g. recently added po files)
 		# SET(ACCEPT_INCOMPLETE_PO "-DACCEPT_INCOMPLETE_PO=1")
 
-		SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_poid}.${_lang}.gmo)
+		# Sort files into a proper tree layout during generation, so they can be installed using INSTALL(DIRECTORY ...)
+		# INSTALL(FILES ... OPTIONAL) will leave empty directories, if file does not exist (was not generated)
+		IF(${_poid} STREQUAL "rkward")
+			SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/main/${_lang}/rkward.mo)
+		ELSE(${_poid} STREQUAL "rkward")
+			SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/plugins/${_lang}/${_poid}.mo)
+		ENDIF(${_poid} STREQUAL "rkward")
 
 		# making the gmo be re-built, when the po changes, but not every time is surprsingly difficult
 		# (since the gmo file is only built for translations which are complete enough)
@@ -20,12 +26,6 @@ MACRO(RKHandlePO _PO_FILES)
 			COMMENT "Generating translation for language '${_lang}', catalog '${_poid}'"
 			DEPENDS ${_poFile})
 		LIST(APPEND active_translations ${_stampFile})
-
-		IF(${_poid} STREQUAL "rkward")
-			INSTALL(FILES ${_gmoFile} DESTINATION ${LOCALE_INSTALL_DIR}/${_lang}/LC_MESSAGES/ RENAME rkward.mo OPTIONAL)
-		ELSE(${_poid} STREQUAL "rkward")
-			INSTALL(FILES ${_gmoFile} DESTINATION ${DATA_INSTALL_DIR}/rkward/po/${_lang}/LC_MESSAGES/ RENAME ${_poid}.mo OPTIONAL)
-		ENDIF(${_poid} STREQUAL "rkward")
 	ENDFOREACH(_poFile ${_PO_FILES})
 ENDMACRO(RKHandlePO)
 
@@ -56,6 +56,9 @@ where (XX is your language code, such as \"de\"; optionally specify several code
 Should you have installed translations to a non-standard directory, you can specify that using
    cmake [...] -DTRANSLATION_SRC_DIR=/x/y/z
 ------")
+	ELSE(NOT PO_FILES)
+		INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/main/ DESTINATION ${LOCALE_INSTALL_DIR} OPTIONAL)
+		INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/plugins/ DESTINATION ${DATA_INSTALL_DIR}/rkward/po OPTIONAL)
 	ENDIF(NOT PO_FILES)
 ENDIF(NOT GETTEXT_MSGFMT_EXECUTABLE)
 
diff --git a/i18n/compile_po.cmake b/i18n/compile_po.cmake
index ea4ba456..9bcb9a73 100644
--- a/i18n/compile_po.cmake
+++ b/i18n/compile_po.cmake
@@ -1,8 +1,17 @@
 # helper script, which will compile a po into a gmo, if, and only if it is at least 80% translated.
 # this is basically, because ADD_CUSTOM_COMMAND won't capture stdout, and EXECUTE_PROCESS
 # can't be made to re-run when the po-file changes.
-EXECUTE_PROCESS(COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} --check -o ${_gmoFile} ${_poFile})	# For printing any errors / warnings
-EXECUTE_PROCESS(COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} --statistics -o ${_gmoFile} ${_poFile}	# Second run to grab stats
+
+# NOTE: Our mutli-step rename strategy may seem convoluted, but it needed to make sure files do not get mixed
+#       up during parallel builds!
+GET_FILENAME_COMPONENT(TARGETDIR ${_gmoFile} DIRECTORY)
+GET_FILENAME_COMPONENT(TARGETNAME ${_gmoFile} NAME)
+GET_FILENAME_COMPONENT(SOURCENAME ${_poFile} NAME)
+SET(COMPILEDNAME ${SOURCENAME}.compiled)
+SET(COMPILEDFILE "${CMAKE_CURRENT_BINARY_DIR}/${COMPILEDNAME}")
+
+EXECUTE_PROCESS(COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} --check -o ${COMPILEDFILE} ${_poFile})	# For printing any errors / warnings
+EXECUTE_PROCESS(COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} --statistics -o ${COMPILEDFILE} ${_poFile}	# Second run to grab stats
 	ERROR_VARIABLE MSGFMT_STATS ERROR_STRIP_TRAILING_WHITESPACE)
 
 # Try to extract statistics information on translated vs. untranslated strings
@@ -24,10 +33,14 @@ MATH(EXPR TRANSLATION_RATIO "${TRANSLATED_COUNT}*100/(${TRANSLATED_COUNT}+${UNTR
 IF(TRANSLATION_RATIO LESS 80)
 	IF(${ACCEPT_INCOMPLETE_PO})
 		MESSAGE (STATUS "${_poFile} is only ${TRANSLATION_RATIO}% translated. Accepting anyway as a temporary exception")
+		FILE(COPY ${COMPILEDFILE} DESTINATION ${TARGETDIR})
+		FILE(RENAME "${TARGETDIR}/${COMPILEDNAME}" "${TARGETDIR}/${TARGETNAME}")
 	ELSE(${ACCEPT_INCOMPLETE_PO})
 		MESSAGE (STATUS "${_poFile} is only ${TRANSLATION_RATIO}% translated. Will not be installed.")
-		FILE(REMOVE ${_gmoFile})
 	ENDIF(${ACCEPT_INCOMPLETE_PO})
 ELSE(TRANSLATION_RATIO LESS 80)
 	MESSAGE (STATUS "${_poFile} is ${TRANSLATION_RATIO}% translated.")
+		FILE(COPY ${COMPILEDFILE} DESTINATION ${TARGETDIR})
+		FILE(RENAME "${TARGETDIR}/${COMPILEDNAME}" "${TARGETDIR}/${TARGETNAME}")
 ENDIF(TRANSLATION_RATIO LESS 80)
+FILE(REMOVE ${COMPILEDFILE})



More information about the rkward-tracker mailing list