First steps for implementing localization
* Created mo-files for Ukrainian and English languages * For this moment it works only on BedShapeDialog.
This commit is contained in:
parent
407f50a66f
commit
28115a847c
BIN
resources/localization/en_US/Slic3rPE.mo
Normal file
BIN
resources/localization/en_US/Slic3rPE.mo
Normal file
Binary file not shown.
BIN
resources/localization/uk/Slic3rPE.mo
Normal file
BIN
resources/localization/uk/Slic3rPE.mo
Normal file
Binary file not shown.
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -11,16 +11,15 @@
|
||||
#include <wx/config.h>
|
||||
#include <wx/dir.h>
|
||||
#include <wx/filename.h>
|
||||
#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;
|
||||
|
@ -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<Pointf> GetValue() { return m_panel->GetValue(); }
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<Tab*>(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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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<widget_t>& get_extra_widgets() const {return m_extra_widgets;}
|
||||
const std::vector<Option>& get_options() const { return m_options; }
|
||||
@ -96,8 +96,8 @@ public:
|
||||
inline void enable() { for (auto& field : m_fields) field.second->enable(); }
|
||||
inline void disable() { for (auto& field : m_fields) field.second->disable(); }
|
||||
|
||||
OptionsGroup(wxWindow* _parent, std::string title) :
|
||||
m_parent(_parent), title(wxString(title)) {
|
||||
OptionsGroup(wxWindow* _parent, wxString title) :
|
||||
m_parent(_parent), title(title) {
|
||||
sizer = (staticbox ? new wxStaticBoxSizer(new wxStaticBox(_parent, wxID_ANY, title), wxVERTICAL) : new wxBoxSizer(wxVERTICAL));
|
||||
auto num_columns = 1U;
|
||||
if (label_width != 0) num_columns++;
|
||||
@ -133,7 +133,7 @@ protected:
|
||||
|
||||
class ConfigOptionsGroup: public OptionsGroup {
|
||||
public:
|
||||
ConfigOptionsGroup(wxWindow* parent, std::string title, DynamicPrintConfig* _config = nullptr) :
|
||||
ConfigOptionsGroup(wxWindow* parent, wxString title, DynamicPrintConfig* _config = nullptr) :
|
||||
OptionsGroup(parent, title), m_config(_config) {}
|
||||
|
||||
/// reference to libslic3r config, non-owning pointer (?).
|
||||
|
@ -1735,7 +1735,7 @@ bool Page::set_value(t_config_option_key opt_key, boost::any value){
|
||||
}
|
||||
|
||||
// package Slic3r::GUI::Tab::Page;
|
||||
ConfigOptionsGroupShp Page::new_optgroup(std::string title, int noncommon_label_width /*= -1*/)
|
||||
ConfigOptionsGroupShp Page::new_optgroup(wxString title, int noncommon_label_width /*= -1*/)
|
||||
{
|
||||
//! config_ have to be "right"
|
||||
ConfigOptionsGroupShp optgroup = std::make_shared<ConfigOptionsGroup>(this, title, m_config);
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
~Page(){}
|
||||
|
||||
public:
|
||||
std::vector <ConfigOptionsGroupShp> m_optgroups; // $self->{optgroups} = [];
|
||||
std::vector <ConfigOptionsGroupShp> m_optgroups;
|
||||
DynamicPrintConfig* m_config;
|
||||
|
||||
wxBoxSizer* vsizer() const { return m_vsizer; }
|
||||
@ -66,7 +66,7 @@ public:
|
||||
void reload_config();
|
||||
Field* get_field(t_config_option_key opt_key, int opt_index = -1) const;
|
||||
bool set_value(t_config_option_key opt_key, boost::any value);
|
||||
ConfigOptionsGroupShp new_optgroup(std::string title, int noncommon_label_width = -1);
|
||||
ConfigOptionsGroupShp new_optgroup(wxString title, int noncommon_label_width = -1);
|
||||
};
|
||||
|
||||
// Slic3r::GUI::Tab;
|
||||
|
@ -7,11 +7,11 @@ void TabIface::load_current_preset() { m_tab->load_current_preset(); }
|
||||
void TabIface::update_tab_ui() { m_tab->update_tab_ui(); }
|
||||
void TabIface::update_ui_from_settings() { m_tab->update_ui_from_settings();}
|
||||
void TabIface::select_preset(char* name) { m_tab->select_preset(name);}
|
||||
char* TabIface::title() { return (char*)m_tab->title().ToStdString().data();}
|
||||
void TabIface::load_config(DynamicPrintConfig* config) { m_tab->load_config(*config);}
|
||||
void TabIface::load_key_value(char* opt_key, char* value){ m_tab->load_key_value(opt_key, static_cast<std::string>(value)); }
|
||||
bool TabIface::current_preset_is_dirty() { return m_tab->current_preset_is_dirty();}
|
||||
void TabIface::OnActivate() { return m_tab->OnActivate();}
|
||||
std::string TabIface::title() { return m_tab->title().ToStdString();}
|
||||
DynamicPrintConfig* TabIface::get_config() { return m_tab->get_config(); }
|
||||
PresetCollection* TabIface::get_presets() { return m_tab->get_presets(); }
|
||||
std::vector<std::string> TabIface::get_dependent_tabs() { return m_tab->get_dependent_tabs(); }
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
void update_tab_ui();
|
||||
void update_ui_from_settings();
|
||||
void select_preset(char* name);
|
||||
char* title();
|
||||
std::string title();
|
||||
void load_config(DynamicPrintConfig* config);
|
||||
void load_key_value(char* opt_key, char* value);
|
||||
bool current_preset_is_dirty();
|
||||
|
@ -15,8 +15,8 @@
|
||||
void load_config(DynamicPrintConfig* config);
|
||||
bool current_preset_is_dirty();
|
||||
void load_key_value(char* opt_key, char* value);
|
||||
char* title();
|
||||
void OnActivate();
|
||||
std::string title();
|
||||
Ref<DynamicPrintConfig> get_config();
|
||||
Ref<PresetCollection> get_presets();
|
||||
std::vector<std::string> get_dependent_tabs();
|
||||
|
Loading…
Reference in New Issue
Block a user