diff --git a/doc/Localization_guide.md b/doc/Localization_guide.md index 3394d2958..abf898cb8 100644 --- a/doc/Localization_guide.md +++ b/doc/Localization_guide.md @@ -36,7 +36,7 @@ Each string resource in Slic3rPE available for translation needs to be explicitl ```C++ auto msg = L("This message to be localized") ``` -To get translated text use one of needed macro/function (`_(s)`, `_CHB(s)` or `L_str(s)` ). +To get translated text use one of needed macro/function (`_(s)` or `_CHB(s)` ). If you add new file resource, add it to the list of files containing macro `L()` ### Scenario 4. How do I use GNUgettext to localize my own application taking Slic3rPE as an example diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 307b0af59..8619bec1c 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3035,10 +3035,10 @@ void GLCanvas3D::set_tooltip(const std::string& tooltip) const if (tooltip.empty()) m_canvas->UnsetToolTip(); else - t->SetTip(tooltip); + t->SetTip(wxString::FromUTF8(tooltip.data())); } else if (!tooltip.empty()) // Avoid "empty" tooltips => unset of the empty tooltip leads to application crash under OSX - m_canvas->SetToolTip(tooltip); + m_canvas->SetToolTip(wxString::FromUTF8(tooltip.data())); } } @@ -3389,7 +3389,7 @@ bool GLCanvas3D::_init_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "add.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("Add...") + " [" + GUI::shortkey_ctrl_prefix() + "I]"; + item.tooltip = _utf8(L("Add...")) + " [" + GUI::shortkey_ctrl_prefix() + "I]"; item.sprite_id = 0; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_ADD)); }; if (!m_toolbar.add_item(item)) @@ -3399,7 +3399,7 @@ bool GLCanvas3D::_init_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "remove.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("Delete") + " [Del]"; + item.tooltip = _utf8(L("Delete")) + " [Del]"; item.sprite_id = 1; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_DELETE)); }; item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_delete(); }; @@ -3410,7 +3410,7 @@ bool GLCanvas3D::_init_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "delete_all.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("Delete all") + " [" + GUI::shortkey_ctrl_prefix() + "Del]"; + item.tooltip = _utf8(L("Delete all")) + " [" + GUI::shortkey_ctrl_prefix() + "Del]"; item.sprite_id = 2; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_DELETE_ALL)); }; item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_delete_all(); }; @@ -3421,7 +3421,7 @@ bool GLCanvas3D::_init_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "arrange.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("Arrange [A]"); + item.tooltip = _utf8(L("Arrange")) + " [A]"; item.sprite_id = 3; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_ARRANGE)); }; item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_arrange(); }; @@ -3435,7 +3435,7 @@ bool GLCanvas3D::_init_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "copy.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("Copy") + " [" + GUI::shortkey_ctrl_prefix() + "C]"; + item.tooltip = _utf8(L("Copy")) + " [" + GUI::shortkey_ctrl_prefix() + "C]"; item.sprite_id = 4; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_COPY)); }; item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_copy(); }; @@ -3446,7 +3446,7 @@ bool GLCanvas3D::_init_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "paste.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("Paste") + " [" + GUI::shortkey_ctrl_prefix() + "V]"; + item.tooltip = _utf8(L("Paste")) + " [" + GUI::shortkey_ctrl_prefix() + "V]"; item.sprite_id = 5; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_PASTE)); }; item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_paste(); }; @@ -3460,7 +3460,7 @@ bool GLCanvas3D::_init_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "instance_add.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("Add instance [+]"); + item.tooltip = _utf8(L("Add instance")) + " [+]"; item.sprite_id = 6; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_MORE)); }; item.visibility_callback = []()->bool { return wxGetApp().get_mode() != comSimple; }; @@ -3472,7 +3472,7 @@ bool GLCanvas3D::_init_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "instance_remove.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("Remove instance [-]"); + item.tooltip = _utf8(L("Remove instance")) + " [-]"; item.sprite_id = 7; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_FEWER)); }; item.visibility_callback = []()->bool { return wxGetApp().get_mode() != comSimple; }; @@ -3487,7 +3487,7 @@ bool GLCanvas3D::_init_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "split_objects.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("Split to objects"); + item.tooltip = _utf8(L("Split to objects")); item.sprite_id = 8; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_SPLIT_OBJECTS)); }; item.visibility_callback = GLToolbarItem::Default_Visibility_Callback; @@ -3499,7 +3499,7 @@ bool GLCanvas3D::_init_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "split_parts.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("Split to parts"); + item.tooltip = _utf8(L("Split to parts")); item.sprite_id = 9; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_SPLIT_VOLUMES)); }; item.visibility_callback = []()->bool { return wxGetApp().get_mode() != comSimple; }; @@ -3514,7 +3514,7 @@ bool GLCanvas3D::_init_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "layers_white.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("Layers editing"); + item.tooltip = _utf8(L("Layers editing")); item.sprite_id = 10; item.is_toggable = true; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_LAYERSEDITING)); }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp index cabede8cd..8934bc52b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp @@ -85,7 +85,7 @@ bool GLGizmoCut::on_init() std::string GLGizmoCut::on_get_name() const { - return L("Cut [C]"); + return (_(L("Cut")) + " [C]").ToUTF8().data(); } void GLGizmoCut::on_set_state() diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp index 56dbf4f54..ec991a241 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp @@ -29,7 +29,7 @@ bool GLGizmoFlatten::on_init() std::string GLGizmoFlatten::on_get_name() const { - return L("Place on face [F]"); + return (_(L("Place on face")) + " [F]").ToUTF8().data(); } bool GLGizmoFlatten::on_is_activable(const Selection& selection) const diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp index 346bf5b06..c8925ad60 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp @@ -48,7 +48,7 @@ bool GLGizmoMove3D::on_init() std::string GLGizmoMove3D::on_get_name() const { - return L("Move [M]"); + return (_(L("Move")) + " [M]").ToUTF8().data(); } void GLGizmoMove3D::on_start_dragging(const Selection& selection) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index ff9cf380e..68b9a8c33 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -455,7 +455,7 @@ bool GLGizmoRotate3D::on_init() std::string GLGizmoRotate3D::on_get_name() const { - return L("Rotate [R]"); + return (_(L("Rotate")) + " [R]").ToUTF8().data(); } void GLGizmoRotate3D::on_start_dragging(const Selection& selection) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp index a4f396934..30b60d372 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp @@ -48,7 +48,7 @@ bool GLGizmoScale3D::on_init() std::string GLGizmoScale3D::on_get_name() const { - return L("Scale [S]"); + return (_(L("Scale")) + " [S]").ToUTF8().data(); } void GLGizmoScale3D::on_start_dragging(const Selection& selection) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 1400bef5e..b2b7c9872 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -994,7 +994,7 @@ bool GLGizmoSlaSupports::on_is_selectable() const std::string GLGizmoSlaSupports::on_get_name() const { - return L("SLA Support Points [L]"); + return (_(L("SLA Support Points")) + " [L]").ToUTF8().data(); } void GLGizmoSlaSupports::on_set_state() diff --git a/src/slic3r/GUI/I18N.hpp b/src/slic3r/GUI/I18N.hpp index a899eaa59..cf85f7410 100644 --- a/src/slic3r/GUI/I18N.hpp +++ b/src/slic3r/GUI/I18N.hpp @@ -1,9 +1,11 @@ #ifndef _ #define _(s) Slic3r::GUI::I18N::translate((s)) +#define _utf8(s) Slic3r::GUI::I18N::translate_utf8((s)) #endif /* _ */ #ifndef _CTX #define _CTX(s, ctx) Slic3r::GUI::I18N::translate((s), (ctx)) +#define _CTX_utf8(s, ctx) Slic3r::GUI::I18N::translate_utf8((s), (ctx)) #endif /* _ */ #ifndef L @@ -35,6 +37,11 @@ namespace I18N { 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()); } + inline std::string translate_utf8(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)).ToUTF8().data(); } + inline std::string translate_utf8(const wchar_t *s) { return wxGetTranslation(s).ToUTF8().data(); } + inline std::string translate_utf8(const std::string &s) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8)).ToUTF8().data(); } + inline std::string translate_utf8(const std::wstring &s) { return wxGetTranslation(s.c_str()).ToUTF8().data(); } + #if wxCHECK_VERSION(3, 1, 1) #define _wxGetTranslation_ctx(S, CTX) wxGetTranslation((S), wxEmptyString, (CTX)) #else @@ -46,6 +53,11 @@ namespace I18N { inline wxString translate(const std::string &s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s.c_str(), wxConvUTF8), ctx); } inline wxString translate(const std::wstring &s, const char* ctx) { return _wxGetTranslation_ctx(s.c_str(), ctx); } + inline wxString translate_utf8(const char *s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s, wxConvUTF8), ctx).ToUTF8().data(); } + inline wxString translate_utf8(const wchar_t *s, const char* ctx) { return _wxGetTranslation_ctx(s, ctx).ToUTF8().data(); } + inline wxString translate_utf8(const std::string &s, const char* ctx) { return _wxGetTranslation_ctx(wxString(s.c_str(), wxConvUTF8), ctx).ToUTF8().data(); } + inline wxString translate_utf8(const std::wstring &s, const char* ctx) { return _wxGetTranslation_ctx(s.c_str(), ctx).ToUTF8().data(); } + #undef _wxGetTranslation_ctx } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 022cb2e9d..f5b4a6545 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -685,11 +685,11 @@ Sidebar::Sidebar(Plater *parent) }; p->combos_filament.push_back(nullptr); - init_combo(&p->combo_print, _(L("Print settings")), Preset::TYPE_PRINT, false); - init_combo(&p->combos_filament[0], _(L("Filament")), Preset::TYPE_FILAMENT, true); - init_combo(&p->combo_sla_print, _(L("SLA print")), Preset::TYPE_SLA_PRINT, false); - init_combo(&p->combo_sla_material, _(L("SLA material")), Preset::TYPE_SLA_MATERIAL, false); - init_combo(&p->combo_printer, _(L("Printer")), Preset::TYPE_PRINTER, false); + init_combo(&p->combo_print, _(L("Print settings")), Preset::TYPE_PRINT, false); + init_combo(&p->combos_filament[0], _(L("Filament")), Preset::TYPE_FILAMENT, true); + init_combo(&p->combo_sla_print, _(L("SLA print settings")), Preset::TYPE_SLA_PRINT, false); + init_combo(&p->combo_sla_material, _(L("SLA material")), Preset::TYPE_SLA_MATERIAL, false); + init_combo(&p->combo_printer, _(L("Printer")), Preset::TYPE_PRINTER, false); const int margin_5 = int(0.5*wxGetApp().em_unit());// 5; const int margin_10 = 10;//int(1.5*wxGetApp().em_unit());// 15; @@ -3071,7 +3071,7 @@ void Plater::priv::init_view_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "editor.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("3D editor view") + " [" + GUI::shortkey_ctrl_prefix() + "5]"; + item.tooltip = _utf8(L("3D editor view")) + " [" + GUI::shortkey_ctrl_prefix() + "5]"; item.sprite_id = 0; item.action_callback = [this]() { if (this->q != nullptr) wxPostEvent(this->q, SimpleEvent(EVT_GLVIEWTOOLBAR_3D)); }; item.is_toggable = false; @@ -3082,7 +3082,7 @@ void Plater::priv::init_view_toolbar() #if ENABLE_SVG_ICONS item.icon_filename = "preview.svg"; #endif // ENABLE_SVG_ICONS - item.tooltip = GUI::L_str("Preview") + " [" + GUI::shortkey_ctrl_prefix() + "6]"; + item.tooltip = _utf8(L("Preview")) + " [" + GUI::shortkey_ctrl_prefix() + "6]"; item.sprite_id = 1; item.action_callback = [this]() { if (this->q != nullptr) wxPostEvent(this->q, SimpleEvent(EVT_GLVIEWTOOLBAR_PREVIEW)); }; item.is_toggable = false;