From 751c97c503f3d8764370c07fadcde68406074042 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 28 Feb 2018 15:39:20 +0100 Subject: [PATCH] Localize the Plater tab * Marking and translation of Plater tab are complited * GUI.pm is marked to l10n * Fix small bug with Extruder adding at Printer Settings tab --- lib/Slic3r/GUI.pm | 7 +++++-- xs/src/libslic3r/GCode/PreviewData.cpp | 7 ++++--- xs/src/slic3r/GUI/3DScene.cpp | 4 ++-- xs/src/slic3r/GUI/Field.cpp | 3 +-- xs/src/slic3r/GUI/GUI.cpp | 2 +- xs/src/slic3r/GUI/GUI.hpp | 3 +++ xs/src/slic3r/GUI/OptionsGroup.cpp | 7 ++++++- xs/src/slic3r/GUI/Tab.cpp | 7 ++++--- 8 files changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 54b797419..7a3b30a6b 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -31,6 +31,8 @@ use Slic3r::GUI::OptionsGroup; use Slic3r::GUI::OptionsGroup::Field; use Slic3r::GUI::SystemInfo; +use Wx::Locale gettext => 'L'; + our $have_OpenGL = eval "use Slic3r::GUI::3DScene; 1"; our $have_LWP = eval "use LWP::UserAgent; 1"; @@ -280,8 +282,9 @@ sub update_ui_from_settings { sub open_model { my ($self, $window) = @_; - - my $dialog = Wx::FileDialog->new($window // $self->GetTopWindow, 'Choose one or more files (STL/OBJ/AMF/PRUSA):', + + my $dlg_title = L('Choose one or more files (STL/OBJ/AMF/3MF/PRUSA):'); + my $dialog = Wx::FileDialog->new($window // $self->GetTopWindow, $dlg_title, $self->{app_config}->get_last_dir, "", MODEL_WILDCARD, wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST); if ($dialog->ShowModal != wxID_OK) { diff --git a/xs/src/libslic3r/GCode/PreviewData.cpp b/xs/src/libslic3r/GCode/PreviewData.cpp index fef10468c..1923505e4 100644 --- a/xs/src/libslic3r/GCode/PreviewData.cpp +++ b/xs/src/libslic3r/GCode/PreviewData.cpp @@ -1,6 +1,7 @@ #include "Analyzer.hpp" #include "PreviewData.hpp" #include +#include #include "slic3r/GUI/GUI.hpp" namespace Slic3r { @@ -369,7 +370,7 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std:: items.reserve(last_valid - first_valid + 1); for (unsigned int i = (unsigned int)first_valid; i <= (unsigned int)last_valid; ++i) { - items.emplace_back(extrusion.role_names[i], extrusion.role_colors[i]); + items.emplace_back(_CHB(extrusion.role_names[i].c_str()).data(), extrusion.role_colors[i]); } break; @@ -395,8 +396,8 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std:: items.reserve(tools_colors_count); for (unsigned int i = 0; i < tools_colors_count; ++i) { - char buf[32]; - sprintf(buf, "Extruder %d", i + 1); + char buf[MIN_BUF_LENGTH_FOR_L]; + sprintf(buf, _CHB(L("Extruder %d")), i + 1); GCodePreviewData::Color color; ::memcpy((void*)color.rgba, (const void*)(tool_colors.data() + i * 4), 4 * sizeof(float)); diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 46d955cf4..04e7f7dc6 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1168,7 +1168,7 @@ bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, con unsigned int max_text_height = 0; for (const GCodePreviewData::LegendItem& item : items) { - memDC.GetTextExtent(GUI::L_str(item.text), &w, &h); + memDC.GetTextExtent(GUI::from_u8(item.text), &w, &h); max_text_width = std::max(max_text_width, (unsigned int)w); max_text_height = std::max(max_text_height, (unsigned int)h); } @@ -1245,7 +1245,7 @@ bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, con memDC.DrawRectangle(wxRect(icon_x_inner, icon_y + 1, px_inner_square, px_inner_square)); // draw text - memDC.DrawText(GUI::L_str(item.text), text_x, icon_y + text_y_offset); + memDC.DrawText(GUI::from_u8(item.text), text_x, icon_y + text_y_offset); // update y icon_y += icon_y_step; diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 532d3d106..045c55d96 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -23,8 +23,7 @@ namespace Slic3r { namespace GUI { // Also, docs for wxEvent::Skip() say "In general, it is recommended to skip all // non-command events to allow the default handling to take place." event.Skip(); - std::cerr << "calling Field::on_kill_focus from " << m_opt_id<< "\n"; - // call the registered function if it is available + // call the registered function if it is available if (m_on_kill_focus!=nullptr) m_on_kill_focus(); } diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 6f97bc494..4cdafed5a 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -519,7 +519,7 @@ void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string comboCtrl->EnablePopupAnimation(false); comboCtrl->SetPopupControl(popup); - popup->SetStringValue(text); + popup->SetStringValue(from_u8(text)); popup->Bind(wxEVT_CHECKLISTBOX, [popup](wxCommandEvent& evt) { popup->OnCheckListBox(evt); }); popup->Bind(wxEVT_LISTBOX, [popup](wxCommandEvent& evt) { popup->OnListBoxSelection(evt); }); popup->Bind(wxEVT_KEY_DOWN, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index 3e519b691..c6922cebc 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -34,6 +34,9 @@ class TabIface; //! With wxConvUTF8 explicitly specify that the source string is already in UTF-8 encoding #define _CHB(s) wxGetTranslation(wxString(s, wxConvUTF8)).utf8_str() +// Minimal buffer length for translated string (char buf[MIN_BUF_LENGTH_FOR_L]) +#define MIN_BUF_LENGTH_FOR_L 128 + namespace GUI { class Tab; diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp index d0084313c..f88b3f8c0 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.cpp +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -151,7 +151,12 @@ void OptionsGroup::append_line(const Line& line) { ConfigOptionDef option = opt.opt; // add label if any if (option.label != "") { - auto field_label = new wxStaticText(parent(), wxID_ANY, L_str(option.label) + ":", wxDefaultPosition, wxDefaultSize); + wxString str_label = L_str(option.label); +//! To correct translation by context have to use wxGETTEXT_IN_CONTEXT macro from wxWidget 3.1.1 +// wxString str_label = (option.label == "Top" || option.label == "Bottom") ? +// wxGETTEXT_IN_CONTEXT("Layers", wxString(option.label.c_str()): +// L_str(option.label); + auto field_label = new wxStaticText(parent(), wxID_ANY, str_label + ":", wxDefaultPosition, wxDefaultSize); field_label->SetFont(label_font); sizer->Add(field_label, 0, wxALIGN_CENTER_VERTICAL, 0); } diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index 1df422328..946719356 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -113,8 +113,7 @@ PageShp Tab::add_options_page(wxString title, std::string icon, bool is_extruder // Index of icon in an icon list $self->{icons}. auto icon_idx = 0; if (!icon.empty()) { - if (m_icon_index.find(icon) == m_icon_index.end()) - icon_idx = -1; + icon_idx = (m_icon_index.find(icon) == m_icon_index.end()) ? -1 : m_icon_index.at(icon); if (icon_idx == -1) { // Add a new icon to the icon list. const auto img_icon = new wxIcon(from_u8(Slic3r::var(icon)), wxBITMAP_TYPE_PNG); @@ -1184,7 +1183,9 @@ void TabPrinter::extruders_count_changed(size_t extruders_count){ void TabPrinter::build_extruder_pages(){ for (auto extruder_idx = m_extruder_pages.size(); extruder_idx < m_extruders_count; ++extruder_idx){ //# build page - auto page = add_options_page(_(L("Extruder ")) + wxString::Format(_T("%i"), extruder_idx + 1), "funnel.png", true); + char buf[MIN_BUF_LENGTH_FOR_L]; + sprintf(buf, _CHB(L("Extruder %d")), extruder_idx + 1); + auto page = add_options_page(from_u8(buf), "funnel.png", true); m_extruder_pages.push_back(page); auto optgroup = page->new_optgroup(_(L("Size")));