diff --git a/resources/localization/en_US/Slic3rPE.mo b/resources/localization/en_US/Slic3rPE.mo new file mode 100644 index 000000000..46e2c85b9 Binary files /dev/null and b/resources/localization/en_US/Slic3rPE.mo differ diff --git a/resources/localization/uk/Slic3rPE.mo b/resources/localization/uk/Slic3rPE.mo new file mode 100644 index 000000000..82aa2e48e Binary files /dev/null and b/resources/localization/uk/Slic3rPE.mo differ diff --git a/xs/src/libslic3r/Utils.hpp b/xs/src/libslic3r/Utils.hpp index fd60cf91a..d49995f95 100644 --- a/xs/src/libslic3r/Utils.hpp +++ b/xs/src/libslic3r/Utils.hpp @@ -19,6 +19,8 @@ std::string var(const std::string &file_name); void set_resources_dir(const std::string &path); // Return a full path to the resources directory. const std::string& resources_dir(); +// Return a full path to the localization directory. +std::string localization_dir(); // Set a path with preset files. void set_data_dir(const std::string &path); diff --git a/xs/src/libslic3r/utils.cpp b/xs/src/libslic3r/utils.cpp index 1a7e16f11..7cd82f931 100644 --- a/xs/src/libslic3r/utils.cpp +++ b/xs/src/libslic3r/utils.cpp @@ -103,6 +103,11 @@ const std::string& resources_dir() return g_resources_dir; } +std::string localization_dir() +{ + return resources_dir() + "\\localization\\"; +} + static std::string g_data_dir; void set_data_dir(const std::string &dir) diff --git a/xs/src/slic3r/GUI/BedShapeDialog.cpp b/xs/src/slic3r/GUI/BedShapeDialog.cpp index 5903b8ec6..591188443 100644 --- a/xs/src/slic3r/GUI/BedShapeDialog.cpp +++ b/xs/src/slic3r/GUI/BedShapeDialog.cpp @@ -11,16 +11,15 @@ #include #include #include +#include "Utils.hpp" namespace Slic3r { namespace GUI { -//! macro used to localization -#define _L(s) s - void BedShapeDialog::build_dialog(ConfigOptionPoints* default_pt) { m_App = get_app(); + LoadLanguage(); m_panel = new BedShapePanel(this); m_panel->build_panel(default_pt); @@ -56,14 +55,14 @@ bool BedShapeDialog::LoadLanguage() { if (identifiers[i] == language) { - if (m_Locale) wxDELETE(m_Locale); - m_Locale = new wxLocale; + m_Locale = new wxLocale; m_Locale->Init(identifiers[i]); - m_Locale->AddCatalogLookupPathPrefix(wxPathOnly(m_App->argv[0])); + m_Locale->AddCatalogLookupPathPrefix(wxPathOnly(m_local_dir)); m_Locale->AddCatalog(m_App->GetAppName()); return true; } } + return false; } void BedShapeDialog::GetInstalledLanguages(wxArrayString & names, @@ -71,7 +70,9 @@ void BedShapeDialog::GetInstalledLanguages(wxArrayString & names, { names.Clear(); identifiers.Clear(); - wxDir dir(wxPathOnly(m_App->argv[0])); + m_local_dir = localization_dir(); + + wxDir dir(wxPathOnly(m_local_dir)); wxString filename; const wxLanguageInfo * langinfo; wxString name = wxLocale::GetLanguageName(wxLANGUAGE_DEFAULT); @@ -80,7 +81,7 @@ void BedShapeDialog::GetInstalledLanguages(wxArrayString & names, names.Add(_L("Default")); identifiers.Add(wxLANGUAGE_DEFAULT); } - for (bool cont = dir.GetFirst(&filename, wxT("*.*"), wxDIR_DIRS); + for (bool cont = dir.GetFirst(&filename, wxEmptyString/*wxT("*.*")*/, wxDIR_DIRS); cont; cont = dir.GetNext(&filename)) { wxLogTrace(wxTraceMask(), @@ -89,9 +90,10 @@ void BedShapeDialog::GetInstalledLanguages(wxArrayString & names, langinfo = wxLocale::FindLanguageInfo(filename); if (langinfo != NULL) { - if (wxFileExists(dir.GetName() + wxFileName::GetPathSeparator() + + auto full_file_name = dir.GetName() + wxFileName::GetPathSeparator() + filename + wxFileName::GetPathSeparator() + - m_App->GetAppName() + wxT(".mo"))) + m_App->GetAppName() + wxT(".mo"); + if (wxFileExists(full_file_name)) { names.Add(langinfo->Description); identifiers.Add(langinfo->Language); @@ -104,7 +106,6 @@ void BedShapePanel::build_panel(ConfigOptionPoints* default_pt) { // on_change(nullptr); -// auto box = new wxStaticBox(this, wxID_ANY, "Shape"); auto box = new wxStaticBox(this, wxID_ANY, _L("Shape")); auto sbsizer = new wxStaticBoxSizer(box, wxVERTICAL); @@ -112,31 +113,28 @@ void BedShapePanel::build_panel(ConfigOptionPoints* default_pt) m_shape_options_book = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxSize(300, -1), wxCHB_TOP); sbsizer->Add(m_shape_options_book); -// auto optgroup = init_shape_options_page("Rectangular"); auto optgroup = init_shape_options_page(_L("Rectangular")); ConfigOptionDef def; def.type = coPoints; def.default_value = new ConfigOptionPoints{ Pointf(200, 200) }; -// def.label = "Size"; -// def.tooltip = "Size in X and Y of the rectangular plate."; - def.label = _L("Size"); - def.tooltip = _L("Size in X and Y of the rectangular plate."); + def.label = _LU8("Size"); + def.tooltip = _LU8("Size in X and Y of the rectangular plate."); Option option(def, "rect_size"); optgroup->append_single_option_line(option); def.type = coPoints; def.default_value = new ConfigOptionPoints{ Pointf(0, 0) }; - def.label = _L("Origin"); - def.tooltip = _L("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle."); + def.label = _LU8("Origin"); + def.tooltip = _LU8("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle."); option = Option(def, "rect_origin"); optgroup->append_single_option_line(option); optgroup = init_shape_options_page(_L("Circular")); def.type = coFloat; def.default_value = new ConfigOptionFloat(200); - def.sidetext = _L("mm"); - def.label = _L("Diameter"); - def.tooltip = _L("Diameter of the print bed. It is assumed that origin (0,0) is located in the center."); + def.sidetext = _LU8("mm"); + def.label = _LU8("Diameter"); + def.tooltip = _LU8("Diameter of the print bed. It is assumed that origin (0,0) is located in the center."); option = Option(def, "diameter"); optgroup->append_single_option_line(option); @@ -185,7 +183,7 @@ void BedShapePanel::build_panel(ConfigOptionPoints* default_pt) // Called from the constructor. // Create a panel for a rectangular / circular / custom bed shape. -ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(std::string title){ +ConfigOptionsGroupShp BedShapePanel::init_shape_options_page(wxString title){ auto panel = new wxPanel(m_shape_options_book); ConfigOptionsGroupShp optgroup; diff --git a/xs/src/slic3r/GUI/BedShapeDialog.hpp b/xs/src/slic3r/GUI/BedShapeDialog.hpp index 606c8013c..5bd7d68b9 100644 --- a/xs/src/slic3r/GUI/BedShapeDialog.hpp +++ b/xs/src/slic3r/GUI/BedShapeDialog.hpp @@ -25,7 +25,7 @@ public: void build_panel(ConfigOptionPoints* default_pt); - ConfigOptionsGroupShp init_shape_options_page(std::string title); + ConfigOptionsGroupShp init_shape_options_page(wxString title); void set_shape(ConfigOptionPoints* points); void update_preview(); void update_shape(); @@ -40,10 +40,11 @@ class BedShapeDialog : public wxDialog BedShapePanel* m_panel; wxLocale* m_Locale; wxApp* m_App; + std::string m_local_dir; public: - BedShapeDialog(wxWindow* parent) : wxDialog(parent, wxID_ANY, "Bed Shape", + BedShapeDialog(wxWindow* parent) : wxDialog(parent, wxID_ANY, _L("Bed Shape"), wxDefaultPosition, wxSize(350, 700), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER){} - ~BedShapeDialog(){ if (m_Locale){ wxDELETE(m_Locale);} } + ~BedShapeDialog(){ } void build_dialog(ConfigOptionPoints* default_pt); std::vector GetValue() { return m_panel->GetValue(); } diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 96350fcb4..291a83e4f 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -30,10 +30,11 @@ namespace Slic3r { namespace GUI { wxString Field::get_tooltip_text(const wxString& default_string) { wxString tooltip_text(""); - if (m_opt.tooltip.length() > 0) + wxString tooltip = wxString::FromUTF8(m_opt.tooltip.c_str()); + if (tooltip.length() > 0) tooltip_text = boost::iends_with(m_opt_id, "_gcode") ? - m_opt.tooltip + "(default: \n" + default_string + ")" : - m_opt.tooltip + "(default: " + default_string + ")"; + tooltip + "(" + _L("default") + ": \n" + default_string + ")" : + tooltip + "(" + _L("default") + ": " + default_string + ")"; return tooltip_text; } diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 87bae567f..624962002 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -195,12 +195,6 @@ void create_preset_tabs(PresetBundle *preset_bundle, AppConfig *app_config, add_created_tab(new TabFilament (g_wxTabPanel, no_controller), preset_bundle, app_config); add_created_tab(new TabPrinter (g_wxTabPanel, no_controller, is_disabled_button_browse, is_user_agent), preset_bundle, app_config); -// g_wxTabPanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, ([](wxCommandEvent e){ -// Tab* panel = (Tab*)g_wxTabPanel->GetCurrentPage(); -// if (panel->GetName().compare("Print Settings")==0 || -// panel->GetName().compare("Filament Settings") == 0) -// panel->OnActivate(); -// }), g_wxTabPanel->GetId() ); for (size_t i = 0; i < g_wxTabPanel->GetPageCount(); ++ i) { Tab *tab = dynamic_cast(g_wxTabPanel->GetPage(i)); if (! tab) @@ -320,12 +314,12 @@ void add_created_tab(Tab* panel, PresetBundle *preset_bundle, AppConfig *app_con g_wxTabPanel->AddPage(panel, panel->title()); } -void show_error(wxWindow* parent, std::string message){ +void show_error(wxWindow* parent, wxString message){ auto msg_wingow = new wxMessageDialog(parent, message, "Error", wxOK | wxICON_ERROR); msg_wingow->ShowModal(); } -void show_info(wxWindow* parent, std::string message, std::string title){ +void show_info(wxWindow* parent, wxString message, wxString title){ auto msg_wingow = new wxMessageDialog(parent, message, title.empty() ? "Notice" : title, wxOK | wxICON_INFORMATION); msg_wingow->ShowModal(); } diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index 5f087e41a..cc6bae964 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -10,6 +10,7 @@ class wxFrame; class wxWindow; class wxMenuBar; class wxNotebook; +class wxString; namespace Slic3r { @@ -19,6 +20,11 @@ class AppConfig; class DynamicPrintConfig; class TabIface; +//! macro used to localization, return wxString +#define _L(s) wxGetTranslation(s) +//! macro used to localization, return const CharType * +#define _LU8(s) wxGetTranslation(s).ToUTF8().data() + namespace GUI { class Tab; @@ -63,8 +69,8 @@ void add_created_tab(Tab* panel, PresetBundle *preset_bundle, AppConfig *app_con // Change option value in config void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, boost::any value); -void show_error(wxWindow* parent, std::string message); -void show_info(wxWindow* parent, std::string message, std::string title); +void show_error(wxWindow* parent, wxString message); +void show_info(wxWindow* parent, wxString message, wxString title); wxApp* get_app(); diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp index 7f3b4ee66..46f395e5c 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.cpp +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -112,12 +112,13 @@ void OptionsGroup::append_line(const Line& line) { // Build a label if we have it if (label_width != 0) { - auto label = new wxStaticText(parent(), wxID_ANY, line.label + (line.label.IsEmpty() ? "" : ":" ), wxDefaultPosition, wxSize(label_width, -1)); + auto label = new wxStaticText(parent(), wxID_ANY, line.label + (line.label.IsEmpty() ? "" : ":"), + wxDefaultPosition, wxSize(label_width, -1)); label->SetFont(label_font); label->Wrap(label_width); // avoid a Linux/GTK bug grid_sizer->Add(label, 0, wxALIGN_CENTER_VERTICAL,0); - if (line.label_tooltip.compare("") != 0) - label->SetToolTip(line.label_tooltip); + if (line.label_tooltip.compare("") != 0) + label->SetToolTip(line.label_tooltip); } // If there's a widget, build it and add the result to the sizer. @@ -151,7 +152,7 @@ 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, wxString(option.label) + ":", wxDefaultPosition, wxDefaultSize); + auto field_label = new wxStaticText(parent(), wxID_ANY, wxString::FromUTF8(option.label.c_str()) + ":", wxDefaultPosition, wxDefaultSize); field_label->SetFont(sidetext_font); sizer->Add(field_label, 0, wxALIGN_CENTER_VERTICAL, 0); } @@ -187,7 +188,7 @@ void OptionsGroup::append_line(const Line& line) { } Line OptionsGroup::create_single_option_line(const Option& option) const { - Line retval {option.opt.label, option.opt.tooltip}; + Line retval{ wxString::FromUTF8(option.opt.label.c_str()), wxString::FromUTF8(option.opt.tooltip.c_str()) }; Option tmp(option); tmp.opt.label = std::string(""); retval.append_option(tmp); diff --git a/xs/src/slic3r/GUI/OptionsGroup.hpp b/xs/src/slic3r/GUI/OptionsGroup.hpp index 42b0b5344..0e54de70c 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.hpp +++ b/xs/src/slic3r/GUI/OptionsGroup.hpp @@ -54,8 +54,8 @@ public: void append_widget(const widget_t widget) { m_extra_widgets.push_back(widget); } - Line(std::string label, std::string tooltip) : - label(wxString(label)), label_tooltip(wxString(tooltip)) {} + Line(wxString label, wxString tooltip) : + label(label), label_tooltip(tooltip) {} const std::vector& get_extra_widgets() const {return m_extra_widgets;} const std::vector