diff --git a/modules/ECMPoQmTools.cmake b/modules/ECMPoQmTools.cmake --- a/modules/ECMPoQmTools.cmake +++ b/modules/ECMPoQmTools.cmake @@ -26,7 +26,8 @@ # # :: # -# ecm_create_qm_loader( ) +# ecm_create_qm_loader( +# [NAMESPACE ]) # # Generates C++ code which ensures translations are automatically loaded at # startup. The generated files are appended to ````. @@ -44,6 +45,10 @@ # ecm_create_qm_loader(mylib_SRCS mylib) # add_library(mylib ${mylib_SRCS}) # +# If NAMESPACE is specified, a header file named _qmloader.h is created +# in the current binary directory with functions for controlling the qm loader. +# See the generated file for the available functions. +# # :: # # ecm_install_po_files_as_qm() @@ -72,6 +77,7 @@ # Copyright 2007-2009 Kitware, Inc. # Copyright 2007 Alexander Neundorf # Copyright 2014 Aurélien Gâteau +# Copyright 2018 Ralf Habacker # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -112,7 +118,27 @@ function(ecm_create_qm_loader out_var catalog_name) - set(loader_base ${CMAKE_CURRENT_BINARY_DIR}/ECMQmLoader-${catalog_name}) + # Parse arguments + set(options ALL) + set(oneValueArgs NAMESPACE) + set(multiValueArgs) + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if (ARGS_NAMESPACE) + string(TOUPPER "${ARGS_NAMESPACE}" _upper_namespace) + set(QM_LOADER_EXPORT_DECLARATION "${_upper_namespace}_EXPORT") + string(TOLOWER "${ARGS_NAMESPACE}" _lower_namespace) + set(QM_LOADER_INCLUDES "#include <${_lower_namespace}_export.h>\n") + set(QM_LOADER_LIBRARY_NAMESPACE "${ARGS_NAMESPACE}") + set(loader_base ${CMAKE_CURRENT_BINARY_DIR}/${_lower_namespace}_qmloader) + configure_file( + ${ECM_MODULE_DIR}/ECMQmLoader.h.in + "${loader_base}.h" + @ONLY + ) + else() + set(loader_base ${CMAKE_CURRENT_BINARY_DIR}/ECMQmLoader-${catalog_name}) + endif() set(QM_LOADER_CATALOG_NAME "${catalog_name}") diff --git a/modules/ECMQmLoader.h.in b/modules/ECMQmLoader.h.in new file mode 100644 --- /dev/null +++ b/modules/ECMQmLoader.h.in @@ -0,0 +1,43 @@ +/* This file was generated by ecm_create_qm_loader(). DO NOT EDIT! + * + * Provides helper functions for loading translations + * when an application makes use of the library. + * + * + * Copyright 2014 Aurélien Gâteau + * Copyright 2015 Alex Merry + * Copyright 2018 Ralf Habacker + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +@QM_LOADER_INCLUDES@ + +namespace @QM_LOADER_LIBRARY_NAMESPACE@ { + /** + * Auxiliary function for deactivating the loading of translations + */ + @QM_LOADER_EXPORT_DECLARATION@ void doNotLoadTranslations(); + +} diff --git a/modules/ECMQmLoader.cpp.in b/modules/ECMQmLoader.cpp.in --- a/modules/ECMQmLoader.cpp.in +++ b/modules/ECMQmLoader.cpp.in @@ -6,6 +6,7 @@ * * Copyright 2014 Aurélien Gâteau * Copyright 2015 Alex Merry + * Copyright 2018 Ralf Habacker * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -36,6 +37,18 @@ #include #include +@QM_LOADER_INCLUDES@ + +static bool doNotLoad = false; + +namespace @QM_LOADER_LIBRARY_NAMESPACE@ { + + void doNotLoadTranslations() + { + doNotLoad = true; + } +} + namespace { bool loadTranslation(const QString &localeDirName) @@ -56,6 +69,9 @@ void load() { + if (doNotLoad) + return; + // The way Qt translation system handles plural forms makes it necessary to // have a translation file which contains only plural forms for `en`. That's // why we load the `en` translation unconditionally, then load the