Added a check that libslic3r/I18N.hpp is not included on the frontend by mistake,
also added a check that L macro is not defined when including libslic3r/I18N.hpp
This commit is contained in:
parent
19f2a1d9e9
commit
73857703b8
3 changed files with 26 additions and 6 deletions
|
@ -3,6 +3,12 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#ifdef SLIC3R_CURRENTLY_COMPILING_GUI_MODULE
|
||||
#ifndef SLIC3R_ALLOW_LIBSLIC3R_I18N_IN_SLIC3R
|
||||
#error You included libslic3r/I18N.hpp into a file belonging to slic3r module.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
namespace I18N {
|
||||
|
@ -15,11 +21,18 @@ namespace I18N {
|
|||
|
||||
} // namespace Slic3r
|
||||
|
||||
namespace {
|
||||
const char* L(const char* s) { return s; }
|
||||
std::string _u8L(const char* s) { return Slic3r::I18N::translate(s); }
|
||||
std::string _utf8(const char* s) { return Slic3r::I18N::translate(s); }
|
||||
std::string _utf8(const std::string& s) { return Slic3r::I18N::translate(s); }
|
||||
}
|
||||
// When this is included from slic3r, better do not define the translation functions.
|
||||
// Macros from slic3r/GUI/I18N.hpp should be used there.
|
||||
#ifndef SLIC3R_CURRENTLY_COMPILING_GUI_MODULE
|
||||
#ifdef L
|
||||
#error L macro is defined where it shouldn't be. Didn't you include slic3r/GUI/I18N.hpp in libslic3r by mistake?
|
||||
#endif
|
||||
namespace {
|
||||
const char* L(const char* s) { return s; }
|
||||
std::string _u8L(const char* s) { return Slic3r::I18N::translate(s); }
|
||||
std::string _utf8(const char* s) { return Slic3r::I18N::translate(s); }
|
||||
std::string _utf8(const std::string& s) { return Slic3r::I18N::translate(s); }
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* slic3r_I18N_hpp_ */
|
||||
|
|
|
@ -344,3 +344,6 @@ if (UNIX AND NOT APPLE)
|
|||
target_include_directories(libslic3r_gui PRIVATE ${GTK${SLIC3R_GTK}_INCLUDE_DIRS})
|
||||
target_link_libraries(libslic3r_gui ${GTK${SLIC3R_GTK}_LIBRARIES} fontconfig)
|
||||
endif ()
|
||||
|
||||
# Add a definition so that we can tell we are compiling slic3r.
|
||||
target_compile_definitions(libslic3r_gui PRIVATE SLIC3R_CURRENTLY_COMPILING_GUI_MODULE)
|
||||
|
|
|
@ -8,7 +8,11 @@
|
|||
|
||||
// Localization headers: include libslic3r version first so everything in this file
|
||||
// uses the slic3r/GUI version (the macros will take precedence over the functions).
|
||||
// Also, there is a check that the former is not included from slic3r module.
|
||||
// This is the only place where we want to allow that, so define an override macro.
|
||||
#define SLIC3R_ALLOW_LIBSLIC3R_I18N_IN_SLIC3R
|
||||
#include "libslic3r/I18N.hpp"
|
||||
#undef SLIC3R_ALLOW_LIBSLIC3R_I18N_IN_SLIC3R
|
||||
#include "slic3r/GUI/I18N.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
|
Loading…
Reference in a new issue