mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-09 12:29:10 +08:00
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:
parent
6b2b970b9a
commit
02d4f3e14d
@ -21,6 +21,7 @@ xs/src/slic3r/GUI/UpdateDialogs.cpp
|
|||||||
xs/src/slic3r/GUI/WipeTowerDialog.cpp
|
xs/src/slic3r/GUI/WipeTowerDialog.cpp
|
||||||
xs/src/slic3r/Utils/OctoPrint.cpp
|
xs/src/slic3r/Utils/OctoPrint.cpp
|
||||||
xs/src/slic3r/Utils/PresetUpdater.cpp
|
xs/src/slic3r/Utils/PresetUpdater.cpp
|
||||||
|
xs/src/libslic3r/Print.cpp
|
||||||
xs/src/libslic3r/PrintConfig.cpp
|
xs/src/libslic3r/PrintConfig.cpp
|
||||||
xs/src/libslic3r/GCode/PreviewData.cpp
|
xs/src/libslic3r/GCode/PreviewData.cpp
|
||||||
lib/Slic3r/GUI.pm
|
lib/Slic3r/GUI.pm
|
||||||
|
@ -5,11 +5,13 @@
|
|||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
typedef std::string (*translate_fn_type)(const char*);
|
namespace I18N {
|
||||||
extern translate_fn_type translate_fn;
|
typedef std::string (*translate_fn_type)(const char*);
|
||||||
inline void set_translate_callback(translate_fn_type fn) { translate_fn = fn; }
|
extern translate_fn_type translate_fn;
|
||||||
inline std::string translate(const std::string &s) { return (translate_fn == nullptr) ? s : (*translate_fn)(s.c_str()); }
|
inline void set_translate_callback(translate_fn_type fn) { translate_fn = fn; }
|
||||||
inline std::string translate(const char *ptr) { return (translate_fn == nullptr) ? std::string(ptr) : (*translate_fn)(ptr); }
|
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
|
} // namespace Slic3r
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ namespace Slic3r {
|
|||||||
|
|
||||||
//! macro used to mark string used at localization,
|
//! macro used to mark string used at localization,
|
||||||
//! return same string
|
//! return same string
|
||||||
#define L(s) translate(s)
|
#define L(s) Slic3r::I18N::translate(s)
|
||||||
|
|
||||||
PrintConfigDef::PrintConfigDef()
|
PrintConfigDef::PrintConfigDef()
|
||||||
{
|
{
|
||||||
|
@ -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 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;
|
static std::string g_data_dir;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
|
|
||||||
#include "../Utils/PresetUpdater.hpp"
|
#include "../Utils/PresetUpdater.hpp"
|
||||||
#include "../Config/Snapshot.hpp"
|
#include "../Config/Snapshot.hpp"
|
||||||
|
#include "libslic3r/I18N.hpp"
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
@ -149,9 +149,13 @@ void update_label_colours_from_appconfig()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string libslic3r_translate_callback(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)); }
|
||||||
|
|
||||||
void set_wxapp(wxApp *app)
|
void set_wxapp(wxApp *app)
|
||||||
{
|
{
|
||||||
g_wxApp = app;
|
g_wxApp = app;
|
||||||
|
// Let the libslic3r know the callback, which will translate messages on demand.
|
||||||
|
Slic3r::I18N::set_translate_callback(libslic3r_translate_callback);
|
||||||
init_label_colours();
|
init_label_colours();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,11 +33,14 @@ class PresetUpdater;
|
|||||||
class DynamicPrintConfig;
|
class DynamicPrintConfig;
|
||||||
class TabIface;
|
class TabIface;
|
||||||
|
|
||||||
#define _(s) Slic3r::translate((s))
|
#define _(s) Slic3r::GUI::I18N::translate((s))
|
||||||
inline wxString translate(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)); }
|
|
||||||
inline wxString translate(const wchar_t *s) { return wxGetTranslation(s); }
|
namespace GUI { namespace I18N {
|
||||||
inline wxString translate(const std::string &s) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8)); }
|
inline wxString translate(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)); }
|
||||||
inline wxString translate(const std::wstring &s) { return wxGetTranslation(s.c_str()); }
|
inline wxString translate(const wchar_t *s) { return wxGetTranslation(s); }
|
||||||
|
inline wxString translate(const std::string &s) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8)); }
|
||||||
|
inline wxString translate(const std::wstring &s) { return wxGetTranslation(s.c_str()); }
|
||||||
|
} }
|
||||||
|
|
||||||
// !!! If you needed to translate some wxString,
|
// !!! If you needed to translate some wxString,
|
||||||
// !!! please use _(L(string))
|
// !!! please use _(L(string))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user