Basic localization of the ImGUI texts.
This commit is contained in:
parent
644794233f
commit
1797273fac
3 changed files with 37 additions and 2 deletions
|
@ -412,6 +412,7 @@ bool GUI_App::select_language( wxArrayString & names,
|
||||||
//FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only.
|
//FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only.
|
||||||
wxSetlocale(LC_NUMERIC, "C");
|
wxSetlocale(LC_NUMERIC, "C");
|
||||||
Preset::update_suffix_modified();
|
Preset::update_suffix_modified();
|
||||||
|
m_imgui->set_language(m_wxLocale->GetCanonicalName().ToUTF8().data());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -440,6 +441,7 @@ bool GUI_App::load_language()
|
||||||
//FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only.
|
//FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only.
|
||||||
wxSetlocale(LC_NUMERIC, "C");
|
wxSetlocale(LC_NUMERIC, "C");
|
||||||
Preset::update_suffix_modified();
|
Preset::update_suffix_modified();
|
||||||
|
m_imgui->set_language(m_wxLocale->GetCanonicalName().ToUTF8().data());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,8 @@ namespace GUI {
|
||||||
|
|
||||||
|
|
||||||
ImGuiWrapper::ImGuiWrapper()
|
ImGuiWrapper::ImGuiWrapper()
|
||||||
: m_font_texture(0)
|
: m_glyph_ranges(nullptr)
|
||||||
|
, m_font_texture(0)
|
||||||
, m_style_scaling(1.0)
|
, m_style_scaling(1.0)
|
||||||
, m_mouse_buttons(0)
|
, m_mouse_buttons(0)
|
||||||
, m_disabled(false)
|
, m_disabled(false)
|
||||||
|
@ -49,6 +50,35 @@ bool ImGuiWrapper::init()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImGuiWrapper::set_language(const std::string &language)
|
||||||
|
{
|
||||||
|
const ImWchar *ranges = nullptr;
|
||||||
|
size_t idx = language.find('_');
|
||||||
|
std::string lang = (idx == std::string::npos) ? language : language.substr(0, idx);
|
||||||
|
static const ImWchar ranges_latin2[] =
|
||||||
|
{
|
||||||
|
0x0020, 0x00FF, // Basic Latin + Latin Supplement
|
||||||
|
0x0100, 0x017F, // Latin Extended-A
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
if (lang == "cs" || lang == "pl") {
|
||||||
|
ranges = ranges_latin2;
|
||||||
|
} else if (lang == "ru" || lang == "uk") {
|
||||||
|
ranges = ImGui::GetIO().Fonts->GetGlyphRangesCyrillic();
|
||||||
|
} else if (lang == "jp") {
|
||||||
|
ranges = ImGui::GetIO().Fonts->GetGlyphRangesJapanese();
|
||||||
|
} else if (lang == "kr") {
|
||||||
|
ranges = ImGui::GetIO().Fonts->GetGlyphRangesKorean();
|
||||||
|
} else if (lang == "zh") {
|
||||||
|
ranges = ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ranges != m_glyph_ranges) {
|
||||||
|
m_glyph_ranges = ranges;
|
||||||
|
init_default_font(m_style_scaling);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ImGuiWrapper::set_display_size(float w, float h)
|
void ImGuiWrapper::set_display_size(float w, float h)
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
@ -210,7 +240,7 @@ void ImGuiWrapper::init_default_font(float scaling)
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.Fonts->Clear();
|
io.Fonts->Clear();
|
||||||
ImFont* font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/NotoSans-Regular.ttf").c_str(), font_size * scaling);
|
ImFont* font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/NotoSans-Regular.ttf").c_str(), font_size * scaling, nullptr, m_glyph_ranges);
|
||||||
if (font == nullptr) {
|
if (font == nullptr) {
|
||||||
font = io.Fonts->AddFontDefault();
|
font = io.Fonts->AddFontDefault();
|
||||||
if (font == nullptr) {
|
if (font == nullptr) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ class ImGuiWrapper
|
||||||
typedef std::map<std::string, ImFont*> FontsMap;
|
typedef std::map<std::string, ImFont*> FontsMap;
|
||||||
|
|
||||||
FontsMap m_fonts;
|
FontsMap m_fonts;
|
||||||
|
const ImWchar *m_glyph_ranges;
|
||||||
unsigned m_font_texture;
|
unsigned m_font_texture;
|
||||||
float m_style_scaling;
|
float m_style_scaling;
|
||||||
unsigned m_mouse_buttons;
|
unsigned m_mouse_buttons;
|
||||||
|
@ -32,6 +33,7 @@ public:
|
||||||
bool init();
|
bool init();
|
||||||
void read_glsl_version();
|
void read_glsl_version();
|
||||||
|
|
||||||
|
void set_language(const std::string &language);
|
||||||
void set_display_size(float w, float h);
|
void set_display_size(float w, float h);
|
||||||
void set_style_scaling(float scaling);
|
void set_style_scaling(float scaling);
|
||||||
bool update_mouse_data(wxMouseEvent &evt);
|
bool update_mouse_data(wxMouseEvent &evt);
|
||||||
|
@ -59,6 +61,7 @@ public:
|
||||||
bool want_keyboard() const;
|
bool want_keyboard() const;
|
||||||
bool want_text_input() const;
|
bool want_text_input() const;
|
||||||
bool want_any_input() const;
|
bool want_any_input() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init_default_font(float scaling);
|
void init_default_font(float scaling);
|
||||||
void create_device_objects();
|
void create_device_objects();
|
||||||
|
|
Loading…
Reference in a new issue