Provide a callback to libslic3r to translate texts.

Moved the "translate" functions to namespaces to avoid clashes
between the code in libslic3r and Slic3r GUI projects.
This commit is contained in:
bubnikv 2018-06-20 18:33:46 +02:00
parent 6b2b970b9a
commit 02d4f3e14d
6 changed files with 23 additions and 13 deletions

View file

@ -5,11 +5,13 @@
namespace Slic3r {
typedef std::string (*translate_fn_type)(const char*);
extern translate_fn_type translate_fn;
inline void set_translate_callback(translate_fn_type fn) { translate_fn = fn; }
inline std::string translate(const std::string &s) { return (translate_fn == nullptr) ? s : (*translate_fn)(s.c_str()); }
inline std::string translate(const char *ptr) { return (translate_fn == nullptr) ? std::string(ptr) : (*translate_fn)(ptr); }
namespace I18N {
typedef std::string (*translate_fn_type)(const char*);
extern translate_fn_type translate_fn;
inline void set_translate_callback(translate_fn_type fn) { translate_fn = fn; }
inline std::string translate(const std::string &s) { return (translate_fn == nullptr) ? s : (*translate_fn)(s.c_str()); }
inline std::string translate(const char *ptr) { return (translate_fn == nullptr) ? std::string(ptr) : (*translate_fn)(ptr); }
} // namespace I18N
} // namespace Slic3r

View file

@ -14,7 +14,7 @@ namespace Slic3r {
//! macro used to mark string used at localization,
//! return same string
#define L(s) translate(s)
#define L(s) Slic3r::I18N::translate(s)
PrintConfigDef::PrintConfigDef()
{

View file

@ -125,7 +125,7 @@ const std::string& localization_dir()
}
// Translate function callback, to call wxWidgets translate function to convert non-localized UTF8 string to a localized one.
translate_fn_type translate_fn = nullptr;
Slic3r::I18N::translate_fn_type Slic3r::I18N::translate_fn = nullptr;
static std::string g_data_dir;