]> git.saurik.com Git - apt.git/commitdiff
CMake: Add support for building and installing .mo files
authorJulian Andres Klode <jak@debian.org>
Sat, 6 Aug 2016 19:11:06 +0000 (21:11 +0200)
committerJulian Andres Klode <jak@debian.org>
Sat, 6 Aug 2016 20:36:02 +0000 (22:36 +0200)
Introduce support for building translation domain-specific
templates, merging them with the translations, and building
a language-specific .mo file.

The invocation of xgettext is done in the project source
directory, not in the current source directory, and all paths
are made relative to the project root, in order to have clean
templates.

This only supports the C++ source code for now, it unfortunately
does not handle the shell scripts of deselect yet.

CMake/Translations.cmake [new file with mode: 0644]
CMakeLists.txt
README.cmake
po/CMakeLists.txt [new file with mode: 0644]

diff --git a/CMake/Translations.cmake b/CMake/Translations.cmake
new file mode 100644 (file)
index 0000000..2a1e03d
--- /dev/null
@@ -0,0 +1,53 @@
+# 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})
+    # Build the list of source files of the target
+    set(files "")
+    foreach(target ${targets})
+        get_target_property(source_dir ${target} SOURCE_DIR)
+        get_target_property(sources ${target} SOURCES)
+        foreach(source ${sources})
+            string(SUBSTRING ${source} 0 1 init_char)
+            string(COMPARE EQUAL ${init_char} "/" is_absolute)
+            if (${is_absolute})
+                set(file "${source}")
+            else()
+                set(file "${source_dir}/${source}")
+            endif()
+            file(RELATIVE_PATH relfile ${PROJECT_SOURCE_DIR} ${file})
+            set(files ${files} ${relfile})
+        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
+        COMMAND xgettext --add-comments --foreign -k_ -kN_
+                         -o ${PROJECT_BINARY_DIR}/${domain}.pot ${files}
+        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+    )
+
+    # Build .mo files
+    file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
+    list(SORT translations)
+    foreach(file ${translations})
+        get_filename_component(langcode ${file} NAME_WE)
+        set(outdir ${PROJECT_BINARY_DIR}/locale/${langcode}/LC_MESSAGES)
+        file(MAKE_DIRECTORY ${outdir})
+        # Command to merge and compile the messages
+        add_custom_command(OUTPUT ${outdir}/${domain}.mo
+            COMMAND msgmerge -qo - ${file} ${PROJECT_BINARY_DIR}/${domain}.pot |
+                    msgfmt -o ${outdir}/${domain}.mo -
+            DEPENDS ${file} ${PROJECT_BINARY_DIR}/${domain}.pot
+        )
+
+        set(mofiles ${mofiles} ${outdir}/${domain}.mo)
+        install(FILES ${outdir}/${domain}.mo
+                DESTINATION "${CMAKE_INSTALL_LOCALEDIR}/${langcode}/LC_MESSAGES")
+    endforeach(file ${translations})
+
+    add_custom_target(nls-${domain} ALL DEPENDS ${mofiles})
+endfunction()
index 90e5272c9912aad58ee5bc2c4be832697d21738c..cba89322706faeb4e09bb9a2fbcab83ceec38fc0 100644 (file)
@@ -17,6 +17,7 @@ endif()
 
 # Include stuff
 include(Misc)
 
 # Include stuff
 include(Misc)
+include(Translations)
 include(CheckIncludeFiles)
 include(CheckFunctionExists)
 include(CheckStructHasMember)
 include(CheckIncludeFiles)
 include(CheckFunctionExists)
 include(CheckStructHasMember)
@@ -130,3 +131,4 @@ add_subdirectory(cmdline)
 add_subdirectory(dselect)
 add_subdirectory(ftparchive)
 add_subdirectory(methods)
 add_subdirectory(dselect)
 add_subdirectory(ftparchive)
 add_subdirectory(methods)
+add_subdirectory(po)
index c9347a05756936bfb23a15487a134073d60940cf..d94a46f12e4f5ff772ef9e6e5eb93689655ef480 100644 (file)
@@ -32,5 +32,7 @@ TODO
 The following features have not been implemented yet:
 
  - documentation
 The following features have not been implemented yet:
 
  - documentation
- - translation
+ - Translated docbook guides
+ - dselect translations
  - unit tests
  - unit tests
+ - update-po
diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0dd1483
--- /dev/null
@@ -0,0 +1,20 @@
+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)
+
+
+apt_add_translation_domain(apt-utils        # Domain
+                           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)