FIX: use current_language_code_safe() for valid language

Change-Id: I480730055588aa76bd40f35e6c4bcbe9833c330d
This commit is contained in:
chunmao.guo 2023-08-11 15:22:45 +08:00 committed by Lane.Wei
parent af534509b3
commit 5eba42b565
6 changed files with 8 additions and 23 deletions

View File

@ -351,8 +351,6 @@ void OG_CustomCtrl::OnMotion(wxMouseEvent& event)
wxString tooltip;
std::string markdowntip;
wxString language = wxGetApp().app_config->get("language");
// BBS: markdown tip
CtrlLine* focusedLine = nullptr;
// BBS

View File

@ -43,7 +43,7 @@ const std::vector<std::string> license_list = {
ProjectPanel::ProjectPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style) : wxPanel(parent, id, pos, size, style)
{
m_project_home_url = wxString::Format("file://%s/web/model/index.html", from_u8(resources_dir()));
std::string strlang = wxGetApp().app_config->get("language");
wxString strlang = wxGetApp().current_language_code_safe();
if (strlang != "")
m_project_home_url = wxString::Format("file://%s/web/model/index.html?lang=%s", from_u8(resources_dir()), strlang);

View File

@ -437,7 +437,7 @@ static std::string generate_system_info_json()
);
#endif // __WXGTK__
data_node.put("SystemLanguage", sys_language);
data_node.put("TranslationLanguage: ", wxGetApp().app_config->get("language"));
data_node.put("TranslationLanguage: ", wxGetApp().current_language_code_safe());
pt::ptree hw_node;

View File

@ -171,8 +171,8 @@ wxString GuideFrame::SetStartPage(GuidePage startpage, bool load)
TargetUrl = from_u8((boost::filesystem::path(resources_dir()) / "web/guide/21/index.html").make_preferred().string());
}
std::string strlang = wxGetApp().app_config->get("language");
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(", strlang=%1%")%strlang;
wxString strlang = wxGetApp().current_language_code_safe();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(", strlang=%1%") % into_u8(strlang);
if (strlang != "")
TargetUrl = wxString::Format("%s?lang=%s", w2s(TargetUrl), strlang);

View File

@ -37,25 +37,12 @@ BEGIN_EVENT_TABLE(ZUserLogin, wxDialog)
EVT_TIMER(NETWORK_OFFLINE_TIMER_ID, ZUserLogin::OnTimer)
END_EVENT_TABLE()
string &replace_str(string &str, const string &to_replaced, const string &newchars)
{
for (string::size_type pos(0); pos != string::npos; pos += newchars.length()) {
pos = str.find(to_replaced, pos);
if (pos != string::npos)
str.replace(pos, to_replaced.length(), newchars);
else
break;
}
return str;
}
int ZUserLogin::web_sequence_id = 20000;
ZUserLogin::ZUserLogin() : wxDialog((wxWindow *) (wxGetApp().mainframe), wxID_ANY, "BambuStudio")
{
SetBackgroundColour(*wxWHITE);
// Url
AppConfig * config = wxGetApp().app_config;
NetworkAgent* agent = wxGetApp().getAgent();
if (!agent) {
std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str();
@ -92,9 +79,9 @@ ZUserLogin::ZUserLogin() : wxDialog((wxWindow *) (wxGetApp().mainframe), wxID_AN
TargetUrl = host_url + "/sign-in";
m_networkOk = false;
std::string strlang = config->get("language");
wxString strlang = wxGetApp().current_language_code_safe();
if (strlang != "") {
replace_str(strlang, "_", "-");
strlang.Replace("_", "-");
TargetUrl = host_url + "/" + strlang + "/sign-in";
}

View File

@ -33,7 +33,7 @@ WebViewPanel::WebViewPanel(wxWindow *parent)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
{
wxString url = wxString::Format("file://%s/web/homepage/index.html", from_u8(resources_dir()));
std::string strlang = wxGetApp().app_config->get("language");
wxString strlang = wxGetApp().current_language_code_safe();
if (strlang != "")
url = wxString::Format("file://%s/web/homepage/index.html?lang=%s", from_u8(resources_dir()), strlang);
@ -505,7 +505,7 @@ int WebViewPanel::get_model_mall_detail_url(std::string *url, std::string id)
{
// https://makerhub-qa.bambu-lab.com/en/models/2077
std::string h = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code());
auto l = wxGetApp().app_config->get("language");
auto l = wxGetApp().current_language_code_safe();
if (auto n = l.find('_'); n != std::string::npos)
l = l.substr(0, n);
*url = (boost::format("%1%%2%/models/%3%") % h % l % id).str();