diff --git a/modules/ECMPoQmTools.cmake b/modules/ECMPoQmTools.cmake --- a/modules/ECMPoQmTools.cmake +++ b/modules/ECMPoQmTools.cmake @@ -47,8 +47,12 @@ # :: # # ecm_install_po_files_as_qm() +# [PO_PATTERN ]) # -# Searches for .po files and installs them to the standard location. +# Searches for .po files whose name without extension matches the globbing +# expression (default value: *) and installs them to the +# standard location. +# PO_PATTERN option available since 5.32. # # This is a convenience function which relies on all .po files being kept in # ``//``, where ```` is the language the .po files are @@ -59,9 +63,13 @@ # po/ # fr/ # mylib.po +# otherlib.po # # ``ecm_install_po_files_as_qm(po)`` compiles ``mylib.po`` into ``mylib.mo`` and -# installs it in ``/fr/LC_MESSAGES``. +# installs it in ``/fr/LC_MESSAGES``. ``otherlib.po`` +# is handled in the same way. +# ``ecm_install_po_files_as_qm(po PO_FILTER "my*")`` works like the previous +# case, but only ``mylib.po`` is matched, compiled and installed. # ```` defaults to ``${LOCALE_INSTALL_DIR}`` if defined, # otherwise it uses ``${CMAKE_INSTALL_LOCALEDIR}`` if that is defined, otherwise # it uses ``share/locale``. @@ -205,15 +213,28 @@ function(ecm_install_po_files_as_qm podir) + # Parse arguments + set(options) + set(oneValueArgs PO_PATTERN) + set(multiValueArgs) + cmake_parse_arguments(ECM_IASQ "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(ECM_IASQ_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unknown keywords given to ecm_install_po_files_as_qm(): \"${ECM_IASQ_UNPARSED_ARGUMENTS}\"") + endif() + + if(NOT ECM_IASQ_PO_PATTERN) + set(ECM_IASQ_PO_PATTERN "*") + endif() if (LOCALE_INSTALL_DIR) set(install_destination "${LOCALE_INSTALL_DIR}") elseif (CMAKE_INSTALL_LOCALEDIR) set(install_destination "${CMAKE_INSTALL_LOCALEDIR}") else() set(install_destination share/locale) endif() - file(GLOB po_files "${podir}/*/*.po") + file(GLOB po_files "${podir}/*/${ECM_IASQ_PO_PATTERN}.po") foreach(po_file ${po_files}) get_filename_component(po_dir ${po_file} DIRECTORY) get_filename_component(lang ${po_dir} NAME) diff --git a/tests/ECMPoQmToolsTest/CMakeLists.txt b/tests/ECMPoQmToolsTest/CMakeLists.txt --- a/tests/ECMPoQmToolsTest/CMakeLists.txt +++ b/tests/ECMPoQmToolsTest/CMakeLists.txt @@ -46,6 +46,15 @@ # Should create a bunch of .qm files and install them in # ${CMAKE_INSTALL_LOCALEDIR} +# Should ignore files directly under po/ as well as directories under po/ which +# do not contain any .po files and files whose name does not contain the +# specified pattern. +set(CMAKE_INSTALL_LOCALEDIR custom-dir-pofilter) +ecm_install_po_files_as_qm(pofilter PO_PATTERN "*pattern*") + + +# Should create a bunch of .qm files and install them in +# ${CMAKE_INSTALL_LOCALEDIR} set(CMAKE_INSTALL_LOCALEDIR custom-dir1) ecm_install_po_files_as_qm(po-custom-dir1) diff --git a/tests/ECMPoQmToolsTest/check.cmake.in b/tests/ECMPoQmToolsTest/check.cmake.in --- a/tests/ECMPoQmToolsTest/check.cmake.in +++ b/tests/ECMPoQmToolsTest/check.cmake.in @@ -26,6 +26,10 @@ "share/locale/en/LC_MESSAGES/catalog2.qm" "share/locale/de/LC_MESSAGES/catalog.qm" "share/locale/de/LC_MESSAGES/catalog2.qm" + "custom-dir-pofilter/es/LC_MESSAGES/install-pattern1.qm" + "custom-dir-pofilter/es/LC_MESSAGES/install-pattern2.qm" + "custom-dir-pofilter/fr/LC_MESSAGES/install-pattern1.qm" + "custom-dir-pofilter/fr/LC_MESSAGES/install-pattern2.qm" "custom-dir1/es/LC_MESSAGES/custom-dir1-install-test.qm" "custom-dir1/fr/LC_MESSAGES/custom-dir1-install-test.qm" "custom-dir2/es/LC_MESSAGES/custom-dir2-install-test.qm" diff --git a/tests/ECMPoQmToolsTest/pofilter/es/install-pattern1.po b/tests/ECMPoQmToolsTest/pofilter/es/install-pattern1.po new file mode 100644 --- /dev/null +++ b/tests/ECMPoQmToolsTest/pofilter/es/install-pattern1.po @@ -0,0 +1,18 @@ +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Language: fr\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Qt-Contexts: true\n" +"X-Generator: Poedit 1.5.4\n" + +#: ../../home/aurelien/src/kf5/frameworks/kbookmarks/src/kbookmark.cpp:307 +msgctxt "KBookmark|Bookmark separator" +msgid "--- separator ---" +msgstr "" diff --git a/tests/ECMPoQmToolsTest/pofilter/es/install-pattern2.po b/tests/ECMPoQmToolsTest/pofilter/es/install-pattern2.po new file mode 100644 --- /dev/null +++ b/tests/ECMPoQmToolsTest/pofilter/es/install-pattern2.po @@ -0,0 +1,18 @@ +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Language: fr\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Qt-Contexts: true\n" +"X-Generator: Poedit 1.5.4\n" + +#: ../../home/aurelien/src/kf5/frameworks/kbookmarks/src/kbookmark.cpp:307 +msgctxt "KBookmark|Bookmark separator" +msgid "--- separator ---" +msgstr "" diff --git a/tests/ECMPoQmToolsTest/pofilter/es/install-test.po b/tests/ECMPoQmToolsTest/pofilter/es/install-test.po new file mode 100644 --- /dev/null +++ b/tests/ECMPoQmToolsTest/pofilter/es/install-test.po @@ -0,0 +1,18 @@ +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Language: fr\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Qt-Contexts: true\n" +"X-Generator: Poedit 1.5.4\n" + +#: ../../home/aurelien/src/kf5/frameworks/kbookmarks/src/kbookmark.cpp:307 +msgctxt "KBookmark|Bookmark separator" +msgid "--- separator ---" +msgstr "" diff --git a/tests/ECMPoQmToolsTest/pofilter/fr/install-pattern1.po b/tests/ECMPoQmToolsTest/pofilter/fr/install-pattern1.po new file mode 100644 --- /dev/null +++ b/tests/ECMPoQmToolsTest/pofilter/fr/install-pattern1.po @@ -0,0 +1,18 @@ +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Language: fr\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Qt-Contexts: true\n" +"X-Generator: Poedit 1.5.4\n" + +#: ../../home/aurelien/src/kf5/frameworks/kbookmarks/src/kbookmark.cpp:307 +msgctxt "KBookmark|Bookmark separator" +msgid "--- separator ---" +msgstr "" diff --git a/tests/ECMPoQmToolsTest/pofilter/fr/install-pattern2.po b/tests/ECMPoQmToolsTest/pofilter/fr/install-pattern2.po new file mode 100644 --- /dev/null +++ b/tests/ECMPoQmToolsTest/pofilter/fr/install-pattern2.po @@ -0,0 +1,18 @@ +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Language: fr\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Qt-Contexts: true\n" +"X-Generator: Poedit 1.5.4\n" + +#: ../../home/aurelien/src/kf5/frameworks/kbookmarks/src/kbookmark.cpp:307 +msgctxt "KBookmark|Bookmark separator" +msgid "--- separator ---" +msgstr "" diff --git a/tests/ECMPoQmToolsTest/pofilter/fr/install-test.po b/tests/ECMPoQmToolsTest/pofilter/fr/install-test.po new file mode 100644 --- /dev/null +++ b/tests/ECMPoQmToolsTest/pofilter/fr/install-test.po @@ -0,0 +1,18 @@ +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Language: fr\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Qt-Contexts: true\n" +"X-Generator: Poedit 1.5.4\n" + +#: ../../home/aurelien/src/kf5/frameworks/kbookmarks/src/kbookmark.cpp:307 +msgctxt "KBookmark|Bookmark separator" +msgid "--- separator ---" +msgstr "" diff --git a/tests/ECMPoQmToolsTest/pofilter/no-po/placeholder b/tests/ECMPoQmToolsTest/pofilter/no-po/placeholder new file mode 100644 diff --git a/tests/ECMPoQmToolsTest/pofilter/should-not-be-installed b/tests/ECMPoQmToolsTest/pofilter/should-not-be-installed new file mode 100644