From 28115a847c6ef981e9bd1e24224d0e1f7d08fb72 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 7 Feb 2018 17:13:52 +0100 Subject: [PATCH] First steps for implementing localization * Created mo-files for Ukrainian and English languages * For this moment it works only on BedShapeDialog. --- resources/localization/en_US/Slic3rPE.mo | Bin 0 -> 1775 bytes resources/localization/uk/Slic3rPE.mo | Bin 0 -> 2205 bytes xs/src/libslic3r/Utils.hpp | 2 ++ xs/src/libslic3r/utils.cpp | 5 +++ xs/src/slic3r/GUI/BedShapeDialog.cpp | 42 +++++++++++------------ xs/src/slic3r/GUI/BedShapeDialog.hpp | 7 ++-- xs/src/slic3r/GUI/Field.cpp | 7 ++-- xs/src/slic3r/GUI/GUI.cpp | 10 ++---- xs/src/slic3r/GUI/GUI.hpp | 10 ++++-- xs/src/slic3r/GUI/OptionsGroup.cpp | 11 +++--- xs/src/slic3r/GUI/OptionsGroup.hpp | 10 +++--- xs/src/slic3r/GUI/Tab.cpp | 2 +- xs/src/slic3r/GUI/Tab.hpp | 4 +-- xs/src/slic3r/GUI/TabIface.cpp | 2 +- xs/src/slic3r/GUI/TabIface.hpp | 2 +- xs/xsp/GUI_Tab.xsp | 2 +- 16 files changed, 62 insertions(+), 54 deletions(-) create mode 100644 resources/localization/en_US/Slic3rPE.mo create mode 100644 resources/localization/uk/Slic3rPE.mo diff --git a/resources/localization/en_US/Slic3rPE.mo b/resources/localization/en_US/Slic3rPE.mo new file mode 100644 index 0000000000000000000000000000000000000000..46e2c85b9863630c7d7f68586a9d13c611be8f18 GIT binary patch literal 1775 zcmeH`O>YxN7{{l)m2QES9C~W2hZC`2HtV3EXpIbSTp0a z;Zszq`UQHfD!8{NFHKD|O@ZEfJv=*(2b3v1$k*PFAN2Z=SA8B8g6een_ zY2;l^%Y&l3vU~g9%B`L4m0o{uaI2Avmhr<`rMzg(LUgsbV^po9_9qK+BZ?DEQ*Z1% zWlEh$CXfnYR-;0ks7TJ6v9YwAUC$c4S-GK#*u*;y9%_r6DUyb$>`)&kg*)AqLs!DZ zIbRx!sD)Y%gKX5S^eAH6TkVhIydEOYxYDU;d++=e5?!a>IxP;Hrm5JS3lsfC!2F~G z9iy@1AO_qUF)&XT6N`OF%9ix#ojM#w(+b*BQ9xJF74qSD^M(&0QW+b_IvQ(-_W8s2 z`UQQUy{f1*;fdp}Dz8;YshFU1_*oYz%%*&Yx=ck~i=KB+P*HYD`9S+%oXu&_?X+(6 zsn@0l?f#&%`&H7{93pqZ*p%}2Y#e0aa!Pu;g>0chM3}sTL*%rYHP>afDzi0eHuJT$ zYgseP;3)h0z;OC^{cch-%d;cDE?PfRV=W71KEu$(cbe1VZu0+s>p%bB`WHT(+%y0H literal 0 HcmV?d00001 diff --git a/resources/localization/uk/Slic3rPE.mo b/resources/localization/uk/Slic3rPE.mo new file mode 100644 index 0000000000000000000000000000000000000000..82aa2e48e4c875208f3f5500d4a13dd5bbf2269f GIT binary patch literal 2205 zcmaJ>PfQ$D9DZu8y8dsB@u22Mq7}3=%x-Bz7S@JRXfO~6Yz>X^Fx`DDQ+H=JZ)S;Y zdT7B`O&T$_1=CpT!J`^LmjBSZiOCz|#f$N%2jj(g z=Yb1A_Wu$1IPhm6=lKozFz^rHKHy)#Cg9(|*MKiSBt#Fe8;C9ODewkrT>~ntn-KgA z@CzXG{ucNY@CV>E;4i@Qz!HkH-|xWJf&T&H{UscoH*n<~*Dep#row$76V7EqE}u?Ss$2`B@{@jR*JU zY4e7ub2JD-NiL0eMM+UWUa1_Yh|b77g`;j+(ufL5)HsywZSFt*R&z&Rck{sDsiBUh zwCMCyu2OWB=&XcMP!cCRws>oEyQ2Jr2%EA31F#4I|gj$$C<_(@85AOo9Eo67 zzEt%%C3DDAC`wy&DHW&&61{?oAO&krIBD`oDX%-f<=5(6qYi;7lH-g;ZA&hE+4%|FVfU{#)}fe)=7yjyHTLhG!V$V7g5S~?4yZZH$-|4Ll@YZ7${btq17Fz zQkW*cY?fi>a2p!MmQ17nYSPJMl63GO@vGC2NhawSIRtmC-^`@yruIw=znTcAJ?YSe z3$+mV;65LtBw|ucZJ<$;B2AU|5<-8bm-MWz#uwwMcs#yJ@dtWFFYDDq6o0HY^en|w zdQIQa8}Jy9C-j`2iO2O4`(aD3#S_FeP@HG>Ai53> z_sCfLmoSETmTZng2>F+w8DdZaf{r5>IeW5JsU%XaKrqi^Ep*3`*a|-Wpb` zyru@Br@;X|Vs@ApFjw#C)gs|vh4^oUWA7^iJoc!ImfS+-RS5MF6fide=U9&?h5ovB zC-jWaUxC;nuE!KNZQEk6!)(OUyE=(WgaZwe5#Th~eyL~CSH66F`sK}w$|6?DRN@Yp zJ`u#M8fDC_0g36Y47=i)&~rvqlFFuIgo6 YzFSP?4)>NX2YBN9*t&n #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