Fixed localization of 3D scene toolbar tips.

This commit is contained in:
bubnikv 2019-05-09 17:18:03 +02:00
parent 0cfac53d24
commit 8126ec33fc
10 changed files with 39 additions and 27 deletions

View File

@ -36,7 +36,7 @@ Each string resource in Slic3rPE available for translation needs to be explicitl
```C++ ```C++
auto msg = L("This message to be localized") 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()` 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 ### Scenario 4. How do I use GNUgettext to localize my own application taking Slic3rPE as an example

View File

@ -3035,10 +3035,10 @@ void GLCanvas3D::set_tooltip(const std::string& tooltip) const
if (tooltip.empty()) if (tooltip.empty())
m_canvas->UnsetToolTip(); m_canvas->UnsetToolTip();
else 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 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 #if ENABLE_SVG_ICONS
item.icon_filename = "add.svg"; item.icon_filename = "add.svg";
#endif // ENABLE_SVG_ICONS #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.sprite_id = 0;
item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_ADD)); }; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_ADD)); };
if (!m_toolbar.add_item(item)) if (!m_toolbar.add_item(item))
@ -3399,7 +3399,7 @@ bool GLCanvas3D::_init_toolbar()
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
item.icon_filename = "remove.svg"; item.icon_filename = "remove.svg";
#endif // ENABLE_SVG_ICONS #endif // ENABLE_SVG_ICONS
item.tooltip = GUI::L_str("Delete") + " [Del]"; item.tooltip = _utf8(L("Delete")) + " [Del]";
item.sprite_id = 1; item.sprite_id = 1;
item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_DELETE)); }; 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(); }; item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_delete(); };
@ -3410,7 +3410,7 @@ bool GLCanvas3D::_init_toolbar()
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
item.icon_filename = "delete_all.svg"; item.icon_filename = "delete_all.svg";
#endif // ENABLE_SVG_ICONS #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.sprite_id = 2;
item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_DELETE_ALL)); }; 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(); }; item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_delete_all(); };
@ -3421,7 +3421,7 @@ bool GLCanvas3D::_init_toolbar()
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
item.icon_filename = "arrange.svg"; item.icon_filename = "arrange.svg";
#endif // ENABLE_SVG_ICONS #endif // ENABLE_SVG_ICONS
item.tooltip = GUI::L_str("Arrange [A]"); item.tooltip = _utf8(L("Arrange")) + " [A]";
item.sprite_id = 3; item.sprite_id = 3;
item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_ARRANGE)); }; 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(); }; item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_arrange(); };
@ -3435,7 +3435,7 @@ bool GLCanvas3D::_init_toolbar()
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
item.icon_filename = "copy.svg"; item.icon_filename = "copy.svg";
#endif // ENABLE_SVG_ICONS #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.sprite_id = 4;
item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_COPY)); }; 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(); }; item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_copy(); };
@ -3446,7 +3446,7 @@ bool GLCanvas3D::_init_toolbar()
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
item.icon_filename = "paste.svg"; item.icon_filename = "paste.svg";
#endif // ENABLE_SVG_ICONS #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.sprite_id = 5;
item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_PASTE)); }; 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(); }; item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_paste(); };
@ -3460,7 +3460,7 @@ bool GLCanvas3D::_init_toolbar()
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
item.icon_filename = "instance_add.svg"; item.icon_filename = "instance_add.svg";
#endif // ENABLE_SVG_ICONS #endif // ENABLE_SVG_ICONS
item.tooltip = GUI::L_str("Add instance [+]"); item.tooltip = _utf8(L("Add instance")) + " [+]";
item.sprite_id = 6; item.sprite_id = 6;
item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_MORE)); }; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_MORE)); };
item.visibility_callback = []()->bool { return wxGetApp().get_mode() != comSimple; }; item.visibility_callback = []()->bool { return wxGetApp().get_mode() != comSimple; };
@ -3472,7 +3472,7 @@ bool GLCanvas3D::_init_toolbar()
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
item.icon_filename = "instance_remove.svg"; item.icon_filename = "instance_remove.svg";
#endif // ENABLE_SVG_ICONS #endif // ENABLE_SVG_ICONS
item.tooltip = GUI::L_str("Remove instance [-]"); item.tooltip = _utf8(L("Remove instance")) + " [-]";
item.sprite_id = 7; item.sprite_id = 7;
item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_FEWER)); }; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_FEWER)); };
item.visibility_callback = []()->bool { return wxGetApp().get_mode() != comSimple; }; item.visibility_callback = []()->bool { return wxGetApp().get_mode() != comSimple; };
@ -3487,7 +3487,7 @@ bool GLCanvas3D::_init_toolbar()
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
item.icon_filename = "split_objects.svg"; item.icon_filename = "split_objects.svg";
#endif // ENABLE_SVG_ICONS #endif // ENABLE_SVG_ICONS
item.tooltip = GUI::L_str("Split to objects"); item.tooltip = _utf8(L("Split to objects"));
item.sprite_id = 8; item.sprite_id = 8;
item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_SPLIT_OBJECTS)); }; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_SPLIT_OBJECTS)); };
item.visibility_callback = GLToolbarItem::Default_Visibility_Callback; item.visibility_callback = GLToolbarItem::Default_Visibility_Callback;
@ -3499,7 +3499,7 @@ bool GLCanvas3D::_init_toolbar()
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
item.icon_filename = "split_parts.svg"; item.icon_filename = "split_parts.svg";
#endif // ENABLE_SVG_ICONS #endif // ENABLE_SVG_ICONS
item.tooltip = GUI::L_str("Split to parts"); item.tooltip = _utf8(L("Split to parts"));
item.sprite_id = 9; item.sprite_id = 9;
item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_SPLIT_VOLUMES)); }; 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; }; item.visibility_callback = []()->bool { return wxGetApp().get_mode() != comSimple; };
@ -3514,7 +3514,7 @@ bool GLCanvas3D::_init_toolbar()
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
item.icon_filename = "layers_white.svg"; item.icon_filename = "layers_white.svg";
#endif // ENABLE_SVG_ICONS #endif // ENABLE_SVG_ICONS
item.tooltip = GUI::L_str("Layers editing"); item.tooltip = _utf8(L("Layers editing"));
item.sprite_id = 10; item.sprite_id = 10;
item.is_toggable = true; item.is_toggable = true;
item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_LAYERSEDITING)); }; item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_LAYERSEDITING)); };

View File

@ -85,7 +85,7 @@ bool GLGizmoCut::on_init()
std::string GLGizmoCut::on_get_name() const std::string GLGizmoCut::on_get_name() const
{ {
return L("Cut [C]"); return (_(L("Cut")) + " [C]").ToUTF8().data();
} }
void GLGizmoCut::on_set_state() void GLGizmoCut::on_set_state()

View File

@ -29,7 +29,7 @@ bool GLGizmoFlatten::on_init()
std::string GLGizmoFlatten::on_get_name() const 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 bool GLGizmoFlatten::on_is_activable(const Selection& selection) const

View File

@ -48,7 +48,7 @@ bool GLGizmoMove3D::on_init()
std::string GLGizmoMove3D::on_get_name() const 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) void GLGizmoMove3D::on_start_dragging(const Selection& selection)

View File

@ -455,7 +455,7 @@ bool GLGizmoRotate3D::on_init()
std::string GLGizmoRotate3D::on_get_name() const 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) void GLGizmoRotate3D::on_start_dragging(const Selection& selection)

View File

@ -48,7 +48,7 @@ bool GLGizmoScale3D::on_init()
std::string GLGizmoScale3D::on_get_name() const 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) void GLGizmoScale3D::on_start_dragging(const Selection& selection)

View File

@ -994,7 +994,7 @@ bool GLGizmoSlaSupports::on_is_selectable() const
std::string GLGizmoSlaSupports::on_get_name() 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() void GLGizmoSlaSupports::on_set_state()

View File

@ -1,9 +1,11 @@
#ifndef _ #ifndef _
#define _(s) Slic3r::GUI::I18N::translate((s)) #define _(s) Slic3r::GUI::I18N::translate((s))
#define _utf8(s) Slic3r::GUI::I18N::translate_utf8((s))
#endif /* _ */ #endif /* _ */
#ifndef _CTX #ifndef _CTX
#define _CTX(s, ctx) Slic3r::GUI::I18N::translate((s), (ctx)) #define _CTX(s, ctx) Slic3r::GUI::I18N::translate((s), (ctx))
#define _CTX_utf8(s, ctx) Slic3r::GUI::I18N::translate_utf8((s), (ctx))
#endif /* _ */ #endif /* _ */
#ifndef L #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::string &s) { return wxGetTranslation(wxString(s.c_str(), wxConvUTF8)); }
inline wxString translate(const std::wstring &s) { return wxGetTranslation(s.c_str()); } 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) #if wxCHECK_VERSION(3, 1, 1)
#define _wxGetTranslation_ctx(S, CTX) wxGetTranslation((S), wxEmptyString, (CTX)) #define _wxGetTranslation_ctx(S, CTX) wxGetTranslation((S), wxEmptyString, (CTX))
#else #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::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(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 #undef _wxGetTranslation_ctx
} }

View File

@ -687,7 +687,7 @@ Sidebar::Sidebar(Plater *parent)
p->combos_filament.push_back(nullptr); p->combos_filament.push_back(nullptr);
init_combo(&p->combo_print, _(L("Print settings")), Preset::TYPE_PRINT, 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->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_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_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_printer, _(L("Printer")), Preset::TYPE_PRINTER, false);
@ -3071,7 +3071,7 @@ void Plater::priv::init_view_toolbar()
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
item.icon_filename = "editor.svg"; item.icon_filename = "editor.svg";
#endif // ENABLE_SVG_ICONS #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.sprite_id = 0;
item.action_callback = [this]() { if (this->q != nullptr) wxPostEvent(this->q, SimpleEvent(EVT_GLVIEWTOOLBAR_3D)); }; item.action_callback = [this]() { if (this->q != nullptr) wxPostEvent(this->q, SimpleEvent(EVT_GLVIEWTOOLBAR_3D)); };
item.is_toggable = false; item.is_toggable = false;
@ -3082,7 +3082,7 @@ void Plater::priv::init_view_toolbar()
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
item.icon_filename = "preview.svg"; item.icon_filename = "preview.svg";
#endif // ENABLE_SVG_ICONS #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.sprite_id = 1;
item.action_callback = [this]() { if (this->q != nullptr) wxPostEvent(this->q, SimpleEvent(EVT_GLVIEWTOOLBAR_PREVIEW)); }; item.action_callback = [this]() { if (this->q != nullptr) wxPostEvent(this->q, SimpleEvent(EVT_GLVIEWTOOLBAR_PREVIEW)); };
item.is_toggable = false; item.is_toggable = false;