Fixing wxString::Format encoding mismatches (part 1)

This commit is contained in:
Lukas Matena 2020-03-02 09:41:54 +01:00
parent a256cc9514
commit 8b16b2c12e
6 changed files with 44 additions and 41 deletions

View File

@ -36,7 +36,9 @@ void AboutDialogLogo::onRepaint(wxEvent &event)
// CopyrightsDialog // CopyrightsDialog
// ----------------------------------------- // -----------------------------------------
CopyrightsDialog::CopyrightsDialog() CopyrightsDialog::CopyrightsDialog()
: DPIDialog(NULL, wxID_ANY, wxString::Format("%s - %s", SLIC3R_APP_NAME, _(L("Portions copyright"))), : DPIDialog(NULL, wxID_ANY, wxString::FromUTF8((boost::format("%1% - %2%")
% SLIC3R_APP_NAME
% _utf8(L("Portions copyright"))).str()),
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{ {
this->SetFont(wxGetApp().normal_font()); this->SetFont(wxGetApp().normal_font());
@ -196,7 +198,7 @@ void CopyrightsDialog::onCloseDialog(wxEvent &)
} }
AboutDialog::AboutDialog() AboutDialog::AboutDialog()
: DPIDialog(NULL, wxID_ANY, wxString::Format(_(L("About %s")), SLIC3R_APP_NAME), wxDefaultPosition, : DPIDialog(NULL, wxID_ANY, wxString::FromUTF8((boost::format(_utf8(L("About %s"))) % SLIC3R_APP_NAME).str()), wxDefaultPosition,
wxDefaultSize, /*wxCAPTION*/wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) wxDefaultSize, /*wxCAPTION*/wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{ {
SetFont(wxGetApp().normal_font()); SetFont(wxGetApp().normal_font());
@ -253,32 +255,33 @@ AboutDialog::AboutDialog()
int size[] = {fs,fs,fs,fs,fs,fs,fs}; int size[] = {fs,fs,fs,fs,fs,fs,fs};
m_html->SetFonts(font.GetFaceName(), font.GetFaceName(), size); m_html->SetFonts(font.GetFaceName(), font.GetFaceName(), size);
m_html->SetBorders(2); m_html->SetBorders(2);
const wxString copyright_str = _(L("Copyright")); const std::string copyright_str = _utf8(L("Copyright"));
// TRN "Slic3r _is licensed under the_ License" // TRN "Slic3r _is licensed under the_ License"
const wxString is_lecensed_str = _(L("is licensed under the")); const std::string is_lecensed_str = _utf8(L("is licensed under the"));
const wxString license_str = _(L("GNU Affero General Public License, version 3")); const std::string license_str = _utf8(L("GNU Affero General Public License, version 3"));
const wxString based_on_str = _(L("PrusaSlicer is based on Slic3r by Alessandro Ranellucci and the RepRap community.")); const std::string based_on_str = _utf8(L("PrusaSlicer is based on Slic3r by Alessandro Ranellucci and the RepRap community."));
const wxString contributors_str = _(L("Contributions by Henrik Brix Andersen, Nicolas Dandrimont, Mark Hindess, Petr Ledvina, Joseph Lenox, Y. Sapir, Mike Sheldrake, Vojtech Bubnik and numerous others.")); const std::string contributors_str = _utf8(L("Contributions by Henrik Brix Andersen, Nicolas Dandrimont, Mark Hindess, Petr Ledvina, Joseph Lenox, Y. Sapir, Mike Sheldrake, Vojtech Bubnik and numerous others."));
const auto text = wxString::Format( const auto text = wxString::FromUTF8(
(boost::format(
"<html>" "<html>"
"<body bgcolor= %s link= %s>" "<body bgcolor= %1% link= %2%>"
"<font color=%s>" "<font color=%3%>"
"%s &copy; 2016-2019 Prusa Research. <br />" "%4% &copy; 2016-2019 Prusa Research. <br />"
"%s &copy; 2011-2018 Alessandro Ranellucci. <br />" "%5% &copy; 2011-2018 Alessandro Ranellucci. <br />"
"<a href=\"http://slic3r.org/\">Slic3r</a> %s " "<a href=\"http://slic3r.org/\">Slic3r</a> %6% "
"<a href=\"http://www.gnu.org/licenses/agpl-3.0.html\">%s</a>." "<a href=\"http://www.gnu.org/licenses/agpl-3.0.html\">%7%</a>."
"<br /><br />" "<br /><br />"
"%s" "%8%"
"<br /><br />" "<br /><br />"
"%s" "%9%"
"</font>" "</font>"
"</body>" "</body>"
"</html>", bgr_clr_str, text_clr_str, text_clr_str, "</html>") % bgr_clr_str % text_clr_str % text_clr_str
copyright_str, copyright_str, % copyright_str % copyright_str
is_lecensed_str, % is_lecensed_str
license_str, % license_str
based_on_str, % based_on_str
contributors_str); % contributors_str).str());
m_html->SetPage(text); m_html->SetPage(text);
vsizer->Add(m_html, 1, wxEXPAND | wxBOTTOM, 10); vsizer->Add(m_html, 1, wxEXPAND | wxBOTTOM, 10);
m_html->Bind(wxEVT_HTML_LINK_CLICKED, &AboutDialog::onLinkClicked, this); m_html->Bind(wxEVT_HTML_LINK_CLICKED, &AboutDialog::onLinkClicked, this);

View File

@ -219,9 +219,9 @@ void BackgroundSlicingProcess::thread_proc()
// Canceled, this is all right. // Canceled, this is all right.
assert(m_print->canceled()); assert(m_print->canceled());
} catch (const std::bad_alloc& ex) { } catch (const std::bad_alloc& ex) {
wxString errmsg = wxString::Format(_(L("%s has encountered an error. It was likely caused by running out of memory. " wxString errmsg = wxString::FromUTF8((boost::format(_utf8(L("%s has encountered an error. It was likely caused by running out of memory. "
"If you are sure you have enough RAM on your system, this may also be a bug and we would " "If you are sure you have enough RAM on your system, this may also be a bug and we would "
"be glad if you reported it.")), SLIC3R_APP_NAME); "be glad if you reported it."))) % SLIC3R_APP_NAME).str());
error = std::string(errmsg.ToUTF8()) + "\n\n" + std::string(ex.what()); error = std::string(errmsg.ToUTF8()) + "\n\n" + std::string(ex.what());
} catch (std::exception &ex) { } catch (std::exception &ex) {
error = ex.what(); error = ex.what();

View File

@ -215,14 +215,14 @@ void BonjourDialog::on_reply(BonjourReplyEvent &e)
void BonjourDialog::on_timer(wxTimerEvent &) void BonjourDialog::on_timer(wxTimerEvent &)
{ {
const auto search_str = _(L("Searching for devices")); const auto search_str = _utf8(L("Searching for devices"));
if (timer_state > 0) { if (timer_state > 0) {
const std::string dots(timer_state, '.'); const std::string dots(timer_state, '.');
label->SetLabel(wxString::Format("%s %s", search_str, dots)); label->SetLabel(wxString::FromUTF8((boost::format("%1% %2%") % search_str % dots).str()));
timer_state = (timer_state) % 3 + 1; timer_state = (timer_state) % 3 + 1;
} else { } else {
label->SetLabel(wxString::Format("%s: %s", search_str, _(L("Finished"))+".")); label->SetLabel(wxString::FromUTF8((boost::format("%1%: %2%") % search_str % (_utf8(L("Finished"))+".")).str()));
timer->Stop(); timer->Stop();
} }
} }

View File

@ -72,7 +72,7 @@ static wxString generate_html_row(const Config::Snapshot &snapshot, bool row_eve
} }
if (! compatible) { if (! compatible) {
text += "<p align=\"right\">" + wxString::Format(_(L("Incompatible with this %s")), SLIC3R_APP_NAME) + "</p>"; text += "<p align=\"right\">" + wxString::FromUTF8((boost::format(_utf8(L("Incompatible with this %s"))) % SLIC3R_APP_NAME).str()) + "</p>";
} }
else if (! snapshot_active) else if (! snapshot_active)
text += "<p align=\"right\"><a href=\"" + snapshot.id + "\">" + _(L("Activate")) + "</a></p>"; text += "<p align=\"right\"><a href=\"" + snapshot.id + "\">" + _(L("Activate")) + "</a></p>";

View File

@ -215,7 +215,7 @@ PrinterPicker::PrinterPicker(wxWindow *parent, const VendorProfile &vendor, wxSt
const auto &variant = model.variants[i]; const auto &variant = model.variants[i];
const auto label = model.technology == ptFFF const auto label = model.technology == ptFFF
? wxString::Format("%s %s %s", variant.name, _(L("mm")), _(L("nozzle"))) ? from_u8((boost::format("%1% %2% %3%") % variant.name % _utf8(L("mm")) % _utf8(L("nozzle"))).str())
: from_u8(model.name); : from_u8(model.name);
if (i == 1) { if (i == 1) {
@ -422,17 +422,17 @@ void ConfigWizardPage::append_spacer(int space)
// Wizard pages // Wizard pages
PageWelcome::PageWelcome(ConfigWizard *parent) PageWelcome::PageWelcome(ConfigWizard *parent)
: ConfigWizardPage(parent, wxString::Format( : ConfigWizardPage(parent, wxString::FromUTF8((boost::format(
#ifdef __APPLE__ #ifdef __APPLE__
_(L("Welcome to the %s Configuration Assistant")) _utf8(L("Welcome to the %s Configuration Assistant"))
#else #else
_(L("Welcome to the %s Configuration Wizard")) _utf8(L("Welcome to the %s Configuration Wizard"))
#endif #endif
, SLIC3R_APP_NAME), _(L("Welcome"))) ) % SLIC3R_APP_NAME).str()), _(L("Welcome")))
, welcome_text(append_text(wxString::Format( , welcome_text(append_text(wxString::FromUTF8((boost::format(
_(L("Hello, welcome to %s! This %s helps you with the initial configuration; just a few settings and you will be ready to print.")), _utf8(L("Hello, welcome to %s! This %s helps you with the initial configuration; just a few settings and you will be ready to print.")))
SLIC3R_APP_NAME, % SLIC3R_APP_NAME
_(ConfigWizard::name())) % _utf8(ConfigWizard::name())).str())
)) ))
, cbox_reset(append( , cbox_reset(append(
new wxCheckBox(this, wxID_ANY, _(L("Remove user profiles - install from scratch (a snapshot will be taken beforehand)"))) new wxCheckBox(this, wxID_ANY, _(L("Remove user profiles - install from scratch (a snapshot will be taken beforehand)")))
@ -478,7 +478,7 @@ PagePrinters::PagePrinters(ConfigWizard *parent,
continue; continue;
} }
const auto picker_title = family.empty() ? wxString() : wxString::Format(_(L("%s Family")), family); const auto picker_title = family.empty() ? wxString() : wxString::FromUTF8((boost::format(_utf8(L("%s Family"))) % family).str());
auto *picker = new PrinterPicker(this, vendor, picker_title, MAX_COLS, *appconfig, filter); auto *picker = new PrinterPicker(this, vendor, picker_title, MAX_COLS, *appconfig, filter);
picker->Bind(EVT_PRINTER_PICK, [this, appconfig](const PrinterPickerEvent &evt) { picker->Bind(EVT_PRINTER_PICK, [this, appconfig](const PrinterPickerEvent &evt) {

View File

@ -530,7 +530,7 @@ wxString Control::get_label(int tick) const
const wxString str = m_values.empty() ? const wxString str = m_values.empty() ?
wxNumberFormatter::ToString(m_label_koef*value, 2, wxNumberFormatter::Style_None) : wxNumberFormatter::ToString(m_label_koef*value, 2, wxNumberFormatter::Style_None) :
wxNumberFormatter::ToString(m_values[value], 2, wxNumberFormatter::Style_None); wxNumberFormatter::ToString(m_values[value], 2, wxNumberFormatter::Style_None);
return wxString::Format("%s\n(%d)", str, m_values.empty() ? value : value+1); return from_u8((boost::format("%1%\n(%2%)") % str % (m_values.empty() ? value : value+1)).str());
} }
void Control::draw_tick_text(wxDC& dc, const wxPoint& pos, int tick, bool right_side/*=true*/) const void Control::draw_tick_text(wxDC& dc, const wxPoint& pos, int tick, bool right_side/*=true*/) const
@ -952,8 +952,8 @@ wxString Control::get_tooltip(int tick/*=-1*/)
return _(L("Discard all custom changes")); return _(L("Discard all custom changes"));
if (m_focus == fiCogIcon) if (m_focus == fiCogIcon)
return m_mode == t_mode::MultiAsSingle ? return m_mode == t_mode::MultiAsSingle ?
wxString::Format(_(L("Jump to height %s or " wxString::FromUTF8((boost::format(_utf8(L("Jump to height %s or "
"Set extruder sequence for the entire print")), " (Shift + G)\n") : "Set extruder sequence for the entire print"))) % " (Shift + G)\n").str()) :
_(L("Jump to height")) + " (Shift + G)"; _(L("Jump to height")) + " (Shift + G)";
if (m_focus == fiColorBand) if (m_focus == fiColorBand)
return m_mode != t_mode::SingleExtruder ? "" : return m_mode != t_mode::SingleExtruder ? "" :