1 #ifndef _ 2 #define _(s) Slic3r::GUI::I18N::translate((s)) 3 #define _L(s) Slic3r::GUI::I18N::translate((s)) 4 #define _utf8(s) Slic3r::GUI::I18N::translate_utf8((s)) 5 #define _u8L(s) Slic3r::GUI::I18N::translate_utf8((s)) 6 #endif /* _ */ 7 8 #ifndef _CTX 9 #define _CTX(s, ctx) Slic3r::GUI::I18N::translate((s), (ctx)) 10 #define _CTX_utf8(s, ctx) Slic3r::GUI::I18N::translate_utf8((s), (ctx)) 11 #endif /* _ */ 12 13 #ifndef L 14 // !!! If you needed to translate some wxString, 15 // !!! please use _L(string) 16 // !!! _() - is a standard wxWidgets macro to translate 17 // !!! L() is used only for marking localizable string 18 // !!! It will be used in "xgettext" to create a Locating Message Catalog. 19 #define L(s) s 20 #endif /* L */ 21 22 #ifndef L_CONTEXT 23 #define L_CONTEXT(s, context) s 24 #endif /* L */ 25 26 #ifndef _CHB 27 //! macro used to localization, return wxScopedCharBuffer 28 //! With wxConvUTF8 explicitly specify that the source string is already in UTF-8 encoding 29 #define _CHB(s) wxGetTranslation(wxString(s, wxConvUTF8)).utf8_str() 30 #endif /* _CHB */ 31 32 #ifndef slic3r_GUI_I18N_hpp_ 33 #define slic3r_GUI_I18N_hpp_ 34 35 #include <wx/intl.h> 36 #include <wx/version.h> 37 38 namespace Slic3r { namespace GUI { 39 40 namespace I18N { translate(const char * s)41 inline wxString translate(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)); } translate(const wchar_t * s)42 inline wxString translate(const wchar_t *s) { return wxGetTranslation(s); } translate(const std::string & s)43 inline wxString translate(const std::string &s) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8)); } translate(const std::wstring & s)44 inline wxString translate(const std::wstring &s) { return wxGetTranslation(s.c_str()); } translate(const wxString & s)45 inline wxString translate(const wxString &s) { return wxGetTranslation(s); } 46 translate(const char * s,const char * plural,unsigned int n)47 inline wxString translate(const char *s, const char *plural, unsigned int n) { return wxGetTranslation(wxString(s, wxConvUTF8), wxString(plural, wxConvUTF8), n); } translate(const wchar_t * s,const wchar_t * plural,unsigned int n)48 inline wxString translate(const wchar_t *s, const wchar_t *plural, unsigned int n) { return wxGetTranslation(s, plural, n); } translate(const std::string & s,const std::string & plural,unsigned int n)49 inline wxString translate(const std::string &s, const std::string &plural, unsigned int n) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8), wxString(plural.c_str(), wxConvUTF8), n); } translate(const std::wstring & s,const std::wstring & plural,unsigned int n)50 inline wxString translate(const std::wstring &s, const std::wstring &plural, unsigned int n) { return wxGetTranslation(s.c_str(), plural.c_str(), n); } translate(const wxString & s,const wxString & plural,unsigned int n)51 inline wxString translate(const wxString &s, const wxString &plural, unsigned int n) { return wxGetTranslation(s, plural, n); } 52 translate_utf8(const char * s)53 inline std::string translate_utf8(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)).ToUTF8().data(); } translate_utf8(const wchar_t * s)54 inline std::string translate_utf8(const wchar_t *s) { return wxGetTranslation(s).ToUTF8().data(); } translate_utf8(const std::string & s)55 inline std::string translate_utf8(const std::string &s) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8)).ToUTF8().data(); } translate_utf8(const std::wstring & s)56 inline std::string translate_utf8(const std::wstring &s) { return wxGetTranslation(s.c_str()).ToUTF8().data(); } translate_utf8(const wxString & s)57 inline std::string translate_utf8(const wxString &s) { return wxGetTranslation(s).ToUTF8().data(); } 58 translate_utf8(const char * s,const char * plural,unsigned int n)59 inline std::string translate_utf8(const char *s, const char *plural, unsigned int n) { return translate(s, plural, n).ToUTF8().data(); } translate_utf8(const wchar_t * s,const wchar_t * plural,unsigned int n)60 inline std::string translate_utf8(const wchar_t *s, const wchar_t *plural, unsigned int n) { return translate(s, plural, n).ToUTF8().data(); } translate_utf8(const std::string & s,const std::string & plural,unsigned int n)61 inline std::string translate_utf8(const std::string &s, const std::string &plural, unsigned int n) { return translate(s, plural, n).ToUTF8().data(); } translate_utf8(const std::wstring & s,const std::wstring & plural,unsigned int n)62 inline std::string translate_utf8(const std::wstring &s, const std::wstring &plural, unsigned int n) { return translate(s, plural, n).ToUTF8().data(); } translate_utf8(const wxString & s,const wxString & plural,unsigned int n)63 inline std::string translate_utf8(const wxString &s, const wxString &plural, unsigned int n) { return translate(s, plural, n).ToUTF8().data(); } 64 65 #if wxCHECK_VERSION(3, 1, 1) 66 #define _wxGetTranslation_ctx(S, CTX) wxGetTranslation((S), wxEmptyString, (CTX)) 67 #else 68 #define _wxGetTranslation_ctx(S, CTX) ((void)(CTX), wxGetTranslation((S))) 69 #endif 70 translate(const char * s,const char * ctx)71 inline wxString translate(const char *s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s, wxConvUTF8), ctx); } translate(const wchar_t * s,const char * ctx)72 inline wxString translate(const wchar_t *s, const char* ctx) { return _wxGetTranslation_ctx(s, ctx); } translate(const std::string & s,const char * ctx)73 inline wxString translate(const std::string &s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s.c_str(), wxConvUTF8), ctx); } translate(const std::wstring & s,const char * ctx)74 inline wxString translate(const std::wstring &s, const char* ctx) { return _wxGetTranslation_ctx(s.c_str(), ctx); } translate(const wxString & s,const char * ctx)75 inline wxString translate(const wxString &s, const char* ctx) { return _wxGetTranslation_ctx(s, ctx); } 76 translate_utf8(const char * s,const char * ctx)77 inline std::string translate_utf8(const char *s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s, wxConvUTF8), ctx).ToUTF8().data(); } translate_utf8(const wchar_t * s,const char * ctx)78 inline std::string translate_utf8(const wchar_t *s, const char* ctx) { return _wxGetTranslation_ctx(s, ctx).ToUTF8().data(); } translate_utf8(const std::string & s,const char * ctx)79 inline std::string translate_utf8(const std::string &s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s.c_str(), wxConvUTF8), ctx).ToUTF8().data(); } translate_utf8(const std::wstring & s,const char * ctx)80 inline std::string translate_utf8(const std::wstring &s, const char* ctx) { return _wxGetTranslation_ctx(s.c_str(), ctx).ToUTF8().data(); } translate_utf8(const wxString & s,const char * ctx)81 inline std::string translate_utf8(const wxString &s, const char* ctx) { return _wxGetTranslation_ctx(s, ctx).ToUTF8().data(); } 82 83 #undef _wxGetTranslation_ctx 84 } // namespace I18N 85 86 // Return translated std::string as a wxString 87 wxString L_str(const std::string &str); 88 89 } // namespace GUI 90 } // namespace Slic3r 91 92 // Macro to function both as a marker for xgettext and to actually perform the translation. 93 #ifndef _L_PLURAL 94 #define _L_PLURAL(s, plural, n) Slic3r::GUI::I18N::translate(s, plural, n) 95 #endif /* L */ 96 97 #endif /* slic3r_GUI_I18N_hpp_ */ 98