]> git.saurik.com Git - apt.git/commitdiff
CMake: Translations: Add support for shell scripts
authorJulian Andres Klode <jak@debian.org>
Sun, 7 Aug 2016 13:52:59 +0000 (15:52 +0200)
committerJulian Andres Klode <jak@debian.org>
Wed, 10 Aug 2016 14:11:05 +0000 (16:11 +0200)
Rework the arguments to apt_add_translation_domain so a user
can specify TARGETS and SCRIPTS, the latter being Shell scripts.

For each language (TARGETS being C++, SCRIPTS being Shell), a separate
template is generated via xgettext. Those templates are then merged
together by using msgcomm. In case there are no Shell scripts in
the translation domain, msgcomm will receive /dev/null instead of
a shell translation template.

This also reintroduces line numbers, as msgcomm would otherwise
re-order the merged files not only by filename, but also by message
string. It's unclear why it does that, it could just leave strings
within a file alone.

In contrast to the old build system, we use xgettext for shell scripts
instead of bash --dump-strings, as it's just easier to use the same
tool for everything. We also create valid headers.

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

index a26bf1c171bbd72e9f5fdcdcf1d6b5fbe8354943..1b9781d697a8c1097e6c9c550ede19942eff93d4 100644 (file)
@@ -1,11 +1,30 @@
 # translations.cmake - Translations using APT's translation system.
 # Copyright (C) 2009, 2016 Julian Andres Klode <jak@debian.org>
 
 # translations.cmake - Translations using APT's translation system.
 # Copyright (C) 2009, 2016 Julian Andres Klode <jak@debian.org>
 
-function(apt_add_translation_domain domain)
-    set(targets ${ARGN})
+function(apt_add_translation_domain)
+    set(options)
+    set(oneValueArgs DOMAIN)
+    set(multiValueArgs TARGETS SCRIPTS)
+    cmake_parse_arguments(NLS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
     # Build the list of source files of the target
     set(files "")
     set(abs_files "")
     # Build the list of source files of the target
     set(files "")
     set(abs_files "")
+    set(scripts "")
+    set(abs_scripts "")
+    set(targets ${NLS_TARGETS})
+    set(domain ${NLS_DOMAIN})
+    foreach(source ${NLS_SCRIPTS})
+            string(SUBSTRING ${source} 0 1 init_char)
+            string(COMPARE EQUAL ${init_char} "/" is_absolute)
+            if (${is_absolute})
+                set(file "${source}")
+            else()
+                set(file "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
+            endif()
+            file(RELATIVE_PATH relfile ${PROJECT_SOURCE_DIR} ${file})
+            list(APPEND scripts ${relfile})
+            list(APPEND abs_scripts ${file})
+        endforeach()
     foreach(target ${targets})
         get_target_property(source_dir ${target} SOURCE_DIR)
         get_target_property(sources ${target} SOURCES)
     foreach(target ${targets})
         get_target_property(source_dir ${target} SOURCE_DIR)
         get_target_property(sources ${target} SOURCES)
@@ -25,15 +44,38 @@ function(apt_add_translation_domain domain)
         target_compile_definitions(${target} PRIVATE -DAPT_DOMAIN="${domain}")
     endforeach()
 
         target_compile_definitions(${target} PRIVATE -DAPT_DOMAIN="${domain}")
     endforeach()
 
-    # Create the template for this specific sub-domain
-    add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/${domain}.pot
+    if("${scripts}" STREQUAL "")
+        set(sh_pot "/dev/null")
+    else()
+        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
+                             -o ${sh_pot} ${scripts}
+            DEPENDS ${abs_scripts}
+            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 --add-comments --foreign -k_ -kN_
-                         --add-location=file --keyword=P_:1,2
-                         -o ${PROJECT_BINARY_DIR}/${domain}.pot ${files}
+                         --keyword=P_:1,2
+                         -o ${PROJECT_BINARY_DIR}/${domain}.c.pot ${files}
         DEPENDS ${abs_files}
         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
     )
 
         DEPENDS ${abs_files}
         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
     )
 
+    add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/${domain}.pot
+        COMMAND msgcomm --more-than=0 --sort-by-file
+                         ${sh_pot}
+                         ${PROJECT_BINARY_DIR}/${domain}.c.pot
+                         --output=${PROJECT_BINARY_DIR}/${domain}.pot
+        DEPENDS ${sh_pot}
+                ${PROJECT_BINARY_DIR}/${domain}.c.pot
+        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+    )
+
     # Build .mo files
     file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
     list(SORT translations)
     # Build .mo files
     file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
     list(SORT translations)
index a993b25890a3fe5a25304bc6ca7c2df04801d7c0..1a4d2a4488787f33d8c7ea89a70c166e11943596 100644 (file)
@@ -32,6 +32,5 @@ TODO
 The following features have not been implemented yet:
 
  - Translated docbook guides
 The following features have not been implemented yet:
 
  - Translated docbook guides
- - dselect translations
  - unit tests
  - update-po
  - unit tests
  - update-po
index dc36221560505d20337666462d5ad2a832781405..c7dfcb0fb91c2dbe540ce52675aa4b7111e59ca0 100644 (file)
@@ -1,22 +1,28 @@
-apt_add_translation_domain(libapt-pkg${APT_PKG_MAJOR} apt-pkg)
-
-apt_add_translation_domain(apt              # Domain
-                           apt apt-cache apt-get apt-config apt-cdrom
-                           apt-helper apt-mark
-                           apt-private
-                           # Methods
-                           file copy store gpgv cdrom http https ftp rred rsh
-                           mirror
+apt_add_translation_domain(
+    DOMAIN libapt-pkg${APT_PKG_MAJOR}
+    TARGETS apt-pkg
 )
 
 )
 
+apt_add_translation_domain(
+    DOMAIN apt
+    TARGETS apt apt-cache apt-get apt-config apt-cdrom apt-helper apt-mark
+            apt-private
+            # Methods
+            file copy store gpgv cdrom http https ftp rred rsh mirror
+    SCRIPTS ../dselect/install ../dselect/update
+)
 
 
-apt_add_translation_domain(apt-utils        # Domain
-                           apt-sortpkgs
-                           apt-extracttemplates
-                           apt-internal-solver
-                           apt-dump-solver
-                           apt-internal-planner
-                           apt-ftparchive)
+apt_add_translation_domain(
+    DOMAIN apt-utils
+    TARGETS apt-sortpkgs
+            apt-extracttemplates
+            apt-internal-solver
+            apt-dump-solver
+            apt-internal-planner
+            apt-ftparchive
+)
 
 
-# Add the translations for libapt-inst, and set the translation domain.
-apt_add_translation_domain(libapt-inst${APT_INST_MAJOR} apt-inst)
+apt_add_translation_domain(
+    DOMAIN libapt-inst${APT_INST_MAJOR}
+    TARGETS apt-inst
+)