Explorar el Código

CMake: Translations: Build apt-all.pot and update .po files

Merge all the per-domain templates into one template file using
msgcomm, stripping any line numbers in the input files, and sorting
the output per file.

This should create reasonably stable .pot and .po files that do not
change just because files move around. It should also be resilient
against some line changes, as long as one translated line is not
moved before/after another translated line.

Gbp-Dch: ignore
Julian Andres Klode hace 10 años
padre
commit
9a5537fcc6
Se han modificado 3 ficheros con 54 adiciones y 3 borrados
  1. 44 2
      CMake/Translations.cmake
  2. 0 1
      README.cmake
  3. 10 0
      po/CMakeLists.txt

+ 44 - 2
CMake/Translations.cmake

@@ -13,6 +13,13 @@ function(apt_add_translation_domain)
     set(abs_scripts "")
     set(targets ${NLS_TARGETS})
     set(domain ${NLS_DOMAIN})
+    set(xgettext_params
+        --add-comments
+        --foreign
+        --package-name=${PROJECT_NAME}
+        --package-version=${PACKAGE_VERSION}
+        --msgid-bugs-address=${PACKAGE_MAIL}
+    )
     foreach(source ${NLS_SCRIPTS})
             string(SUBSTRING ${source} 0 1 init_char)
             string(COMPARE EQUAL ${init_char} "/" is_absolute)
@@ -50,19 +57,21 @@ function(apt_add_translation_domain)
         set(sh_pot ${PROJECT_BINARY_DIR}/${domain}.sh.pot)
         # Create the template for this specific sub-domain
         add_custom_command (OUTPUT ${sh_pot}
-            COMMAND xgettext --add-comments --foreign -L Shell
+            COMMAND xgettext ${xgettext_params} -L Shell
                              -o ${sh_pot} ${scripts}
             DEPENDS ${abs_scripts}
+            VERBATIM
             WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
         )
     endif()
 
 
     add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/${domain}.c.pot
-        COMMAND xgettext --add-comments --foreign -k_ -kN_
+        COMMAND xgettext ${xgettext_params} -k_ -kN_
                          --keyword=P_:1,2
                          -o ${PROJECT_BINARY_DIR}/${domain}.c.pot ${files}
         DEPENDS ${abs_files}
+        VERBATIM
         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
     )
 
@@ -100,3 +109,36 @@ function(apt_add_translation_domain)
 
     add_custom_target(nls-${domain} ALL DEPENDS ${mofiles})
 endfunction()
+
+# Usage: apt_add_update_po(output domain [domain ...])
+function(apt_add_update_po)
+    set(options)
+    set(oneValueArgs TEMPLATE)
+    set(multiValueArgs DOMAINS)
+    cmake_parse_arguments(NLS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+    set(output ${CMAKE_CURRENT_SOURCE_DIR}/${NLS_TEMPLATE}.pot)
+    foreach(domain ${NLS_DOMAINS})
+        list(APPEND potfiles ${PROJECT_BINARY_DIR}/${domain}.pot)
+    endforeach()
+
+    get_filename_component(master_name ${output} NAME_WE)
+    add_custom_target(nls-${master_name}
+                       COMMAND msgcomm --sort-by-file --add-location=file
+                                        --more-than=0 --output=${output}
+                                ${potfiles}
+                       DEPENDS ${potfiles})
+
+    file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
+    if (NOT TARGET update-po)
+        add_custom_target(update-po)
+    endif()
+    foreach(translation ${translations})
+            get_filename_component(langcode ${translation} NAME_WE)
+            add_custom_target(update-po-${langcode}
+                COMMAND msgmerge -q --update --backup=none ${translation} ${output}
+                DEPENDS nls-${master_name}
+            )
+            add_dependencies(update-po update-po-${langcode})
+    endforeach()
+    add_dependencies(update-po nls-${master_name})
+endfunction()

+ 0 - 1
README.cmake

@@ -33,4 +33,3 @@ The following features have not been implemented yet:
 
  - Translated docbook guides
  - unit tests
- - update-po

+ 10 - 0
po/CMakeLists.txt

@@ -26,3 +26,13 @@ apt_add_translation_domain(
     DOMAIN libapt-inst${APT_INST_MAJOR}
     TARGETS apt-inst
 )
+
+apt_add_update_po(
+    TEMPLATE
+        apt-all
+    DOMAINS
+        libapt-pkg${APT_PKG_MAJOR}
+        libapt-inst${APT_INST_MAJOR}
+        apt
+        apt-utils
+)