]> git.saurik.com Git - apt.git/commitdiff
CMake: Translations: Build apt-all.pot and update .po files
authorJulian Andres Klode <jak@debian.org>
Sun, 7 Aug 2016 14:01:18 +0000 (16:01 +0200)
committerJulian Andres Klode <jak@debian.org>
Wed, 10 Aug 2016 14:11:05 +0000 (16:11 +0200)
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

CMake/Translations.cmake
README.cmake
po/CMakeLists.txt

index 1b9781d697a8c1097e6c9c550ede19942eff93d4..6a986200510aa0803937561ad46c07d090f53c90 100644 (file)
@@ -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()
index 1a4d2a4488787f33d8c7ea89a70c166e11943596..0ffd08efc06d24da5c9cb217415ddc95ae1c38a0 100644 (file)
@@ -33,4 +33,3 @@ The following features have not been implemented yet:
 
  - Translated docbook guides
  - unit tests
- - update-po
index c7dfcb0fb91c2dbe540ce52675aa4b7111e59ca0..4fdac3959b50d8b180534e8b0e32099075d28a15 100644 (file)
@@ -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
+)