Save language preset.
* Added global variable g_local_dir to get "localization" directory. * Chage/Set language works correctly now. * Probably, fixed work on Linux
This commit is contained in:
parent
d18a200b0f
commit
badeb2f64c
@ -43,6 +43,7 @@ use FindBin;
|
|||||||
# Let the XS module know where the GUI resources reside.
|
# Let the XS module know where the GUI resources reside.
|
||||||
set_resources_dir(decode_path($FindBin::Bin) . (($^O eq 'darwin') ? '/../Resources' : '/resources'));
|
set_resources_dir(decode_path($FindBin::Bin) . (($^O eq 'darwin') ? '/../Resources' : '/resources'));
|
||||||
set_var_dir(resources_dir() . "/icons");
|
set_var_dir(resources_dir() . "/icons");
|
||||||
|
set_local_dir(resources_dir() . "/localization/");
|
||||||
|
|
||||||
use Moo 1.003001;
|
use Moo 1.003001;
|
||||||
|
|
||||||
|
@ -150,7 +150,6 @@ sub OnInit {
|
|||||||
|
|
||||||
sub recreate_GUI{
|
sub recreate_GUI{
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
print "Inside recreate_GUI \n";
|
|
||||||
my $topwindow = $self->GetTopWindow();
|
my $topwindow = $self->GetTopWindow();
|
||||||
$self->{mainframe} = my $frame = Slic3r::GUI::MainFrame->new(
|
$self->{mainframe} = my $frame = Slic3r::GUI::MainFrame->new(
|
||||||
# If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden.
|
# If set, the "Controller" tab for the control of the printer over serial line and the serial port settings are hidden.
|
||||||
|
@ -19,8 +19,11 @@ std::string var(const std::string &file_name);
|
|||||||
void set_resources_dir(const std::string &path);
|
void set_resources_dir(const std::string &path);
|
||||||
// Return a full path to the resources directory.
|
// Return a full path to the resources directory.
|
||||||
const std::string& resources_dir();
|
const std::string& resources_dir();
|
||||||
|
|
||||||
|
// Set a path with GUI localization files.
|
||||||
|
void set_local_dir(const std::string &path);
|
||||||
// Return a full path to the localization directory.
|
// Return a full path to the localization directory.
|
||||||
std::string localization_dir();
|
const std::string& localization_dir();
|
||||||
|
|
||||||
// Set a path with preset files.
|
// Set a path with preset files.
|
||||||
void set_data_dir(const std::string &path);
|
void set_data_dir(const std::string &path);
|
||||||
|
@ -103,9 +103,16 @@ const std::string& resources_dir()
|
|||||||
return g_resources_dir;
|
return g_resources_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string localization_dir()
|
static std::string g_local_dir;
|
||||||
|
|
||||||
|
void set_local_dir(const std::string &dir)
|
||||||
{
|
{
|
||||||
return resources_dir() + "\\localization\\";
|
g_local_dir = dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& localization_dir()
|
||||||
|
{
|
||||||
|
return g_local_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string g_data_dir;
|
static std::string g_data_dir;
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
#include "Tab.hpp"
|
#include "Tab.hpp"
|
||||||
#include "TabIface.hpp"
|
#include "TabIface.hpp"
|
||||||
#include "AppConfig.hpp"
|
#include "AppConfig.hpp"
|
||||||
//#include <wx/config.h>
|
#include <wx/config.h>
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
@ -168,8 +168,7 @@ wxNotebook *g_wxTabPanel = nullptr;
|
|||||||
|
|
||||||
std::vector<Tab *> g_tabs_list;
|
std::vector<Tab *> g_tabs_list;
|
||||||
|
|
||||||
wxLocale* m_Locale;
|
wxLocale* g_wxLocale;
|
||||||
std::string m_local_dir;
|
|
||||||
|
|
||||||
void set_wxapp(wxApp *app)
|
void set_wxapp(wxApp *app)
|
||||||
{
|
{
|
||||||
@ -211,17 +210,27 @@ bool select_language(wxArrayString & names,
|
|||||||
{
|
{
|
||||||
wxCHECK_MSG(names.Count() == identifiers.Count(), false,
|
wxCHECK_MSG(names.Count() == identifiers.Count(), false,
|
||||||
_L("Array of language names and identifiers should have the same size."));
|
_L("Array of language names and identifiers should have the same size."));
|
||||||
long index = wxGetSingleChoiceIndex(_L("Select the language"),
|
int init_selection = 0;
|
||||||
_L("Language"), names);
|
long current_language = g_wxLocale ? g_wxLocale->GetLanguage() : wxLANGUAGE_UNKNOWN;
|
||||||
|
for (auto lang : identifiers){
|
||||||
|
if (lang == current_language)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
++init_selection;
|
||||||
|
}
|
||||||
|
if (init_selection == identifiers.size())
|
||||||
|
init_selection = 0;
|
||||||
|
long index = wxGetSingleChoiceIndex(_L("Select the language"), _L("Language"),
|
||||||
|
names, init_selection);
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
m_Locale = new wxLocale;
|
g_wxLocale = new wxLocale;
|
||||||
m_Locale->Init(identifiers[index]);
|
g_wxLocale->Init(identifiers[index]);
|
||||||
m_Locale->AddCatalogLookupPathPrefix(wxPathOnly(m_local_dir));
|
g_wxLocale->AddCatalogLookupPathPrefix(wxPathOnly(localization_dir()));
|
||||||
wxLogTrace(wxTraceMask(),
|
wxLogTrace(wxTraceMask(),
|
||||||
_L("Slic3rPE: Path Prefix = \"%s\""),
|
_L("Slic3rPE: Path Prefix = \"%s\""),
|
||||||
wxPathOnly(m_local_dir).GetData());
|
wxPathOnly(localization_dir()).GetData());
|
||||||
m_Locale->AddCatalog(g_wxApp->GetAppName());
|
g_wxLocale->AddCatalog(g_wxApp->GetAppName());
|
||||||
wxLogTrace(wxTraceMask(),
|
wxLogTrace(wxTraceMask(),
|
||||||
_L("Slic3rPE: Catalog Name = \"%s\""),
|
_L("Slic3rPE: Catalog Name = \"%s\""),
|
||||||
g_wxApp->GetAppName().GetData());
|
g_wxApp->GetAppName().GetData());
|
||||||
@ -232,44 +241,41 @@ bool select_language(wxArrayString & names,
|
|||||||
|
|
||||||
bool load_language()
|
bool load_language()
|
||||||
{
|
{
|
||||||
// wxConfig config(g_wxApp->GetAppName());
|
wxConfig config(g_wxApp->GetAppName());
|
||||||
long language;
|
long language;
|
||||||
// if (!config.Read(wxT("wxTranslation_Language"),
|
if (!config.Read(wxT("wxTranslation_Language"),
|
||||||
// &language, wxLANGUAGE_UNKNOWN))
|
&language, wxLANGUAGE_UNKNOWN))
|
||||||
{
|
{
|
||||||
language = wxLANGUAGE_ENGLISH_US;// wxLANGUAGE_UKRAINIAN;// wxLANGUAGE_UNKNOWN;
|
language = wxLANGUAGE_UNKNOWN;
|
||||||
}
|
}
|
||||||
if (language == wxLANGUAGE_UNKNOWN) return false;
|
if (language == wxLANGUAGE_UNKNOWN)
|
||||||
wxArrayString names;
|
return false;
|
||||||
wxArrayLong identifiers;
|
wxArrayString names;
|
||||||
|
wxArrayLong identifiers;
|
||||||
get_installed_languages(names, identifiers);
|
get_installed_languages(names, identifiers);
|
||||||
for (size_t i = 0; i < identifiers.Count(); i++)
|
for (size_t i = 0; i < identifiers.Count(); i++)
|
||||||
{
|
{
|
||||||
if (identifiers[i] == language)
|
if (identifiers[i] == language)
|
||||||
{
|
{
|
||||||
m_Locale = new wxLocale;
|
g_wxLocale = new wxLocale;
|
||||||
m_Locale->Init(identifiers[i]);
|
g_wxLocale->Init(identifiers[i]);
|
||||||
m_Locale->AddCatalogLookupPathPrefix(wxPathOnly(m_local_dir));
|
g_wxLocale->AddCatalogLookupPathPrefix(wxPathOnly(localization_dir()));
|
||||||
m_Locale->AddCatalog(g_wxApp->GetAppName());
|
g_wxLocale->AddCatalog(g_wxApp->GetAppName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_language(bool bReset)
|
void save_language()
|
||||||
{
|
{
|
||||||
// wxConfig config(g_wxApp->GetAppName());
|
wxConfig config(g_wxApp->GetAppName());
|
||||||
long language = wxLANGUAGE_UNKNOWN;
|
long language = wxLANGUAGE_UNKNOWN;
|
||||||
if (!bReset)
|
if (g_wxLocale) {
|
||||||
{
|
language = g_wxLocale->GetLanguage();
|
||||||
if (m_Locale)
|
|
||||||
{
|
|
||||||
language = m_Locale->GetLanguage();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// config.Write(wxT("wxTranslation_Language"), language);
|
config.Write(wxT("wxTranslation_Language"), language);
|
||||||
// config.Flush();
|
config.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_installed_languages(wxArrayString & names,
|
void get_installed_languages(wxArrayString & names,
|
||||||
@ -277,9 +283,8 @@ void get_installed_languages(wxArrayString & names,
|
|||||||
{
|
{
|
||||||
names.Clear();
|
names.Clear();
|
||||||
identifiers.Clear();
|
identifiers.Clear();
|
||||||
m_local_dir = localization_dir();
|
|
||||||
|
|
||||||
wxDir dir(wxPathOnly(m_local_dir));
|
wxDir dir(wxPathOnly(localization_dir()));
|
||||||
wxString filename;
|
wxString filename;
|
||||||
const wxLanguageInfo * langinfo;
|
const wxLanguageInfo * langinfo;
|
||||||
wxString name = wxLocale::GetLanguageName(wxLANGUAGE_DEFAULT);
|
wxString name = wxLocale::GetLanguageName(wxLANGUAGE_DEFAULT);
|
||||||
@ -319,6 +324,7 @@ void add_debug_menu(wxMenuBar *menu, int event_language_change)
|
|||||||
wxArrayLong identifiers;
|
wxArrayLong identifiers;
|
||||||
get_installed_languages(names, identifiers);
|
get_installed_languages(names, identifiers);
|
||||||
if (select_language(names, identifiers)){
|
if (select_language(names, identifiers)){
|
||||||
|
save_language();
|
||||||
show_info(g_wxTabPanel, "Application will be restarted", "Attention!");
|
show_info(g_wxTabPanel, "Application will be restarted", "Attention!");
|
||||||
if (event_language_change > 0) {
|
if (event_language_change > 0) {
|
||||||
wxCommandEvent event(event_language_change);
|
wxCommandEvent event(event_language_change);
|
||||||
|
@ -77,7 +77,7 @@ void show_info(wxWindow* parent, wxString message, wxString title);
|
|||||||
// load language saved at application config
|
// load language saved at application config
|
||||||
bool load_language();
|
bool load_language();
|
||||||
// save language at application config
|
// save language at application config
|
||||||
void save_language(bool bReset);
|
void save_language();
|
||||||
// get list of installed languages
|
// get list of installed languages
|
||||||
void get_installed_languages(wxArrayString & names, wxArrayLong & identifiers);
|
void get_installed_languages(wxArrayString & names, wxArrayLong & identifiers);
|
||||||
// select language from the list of installed languages
|
// select language from the list of installed languages
|
||||||
|
@ -54,6 +54,12 @@ set_var_dir(dir)
|
|||||||
CODE:
|
CODE:
|
||||||
Slic3r::set_var_dir(dir);
|
Slic3r::set_var_dir(dir);
|
||||||
|
|
||||||
|
void
|
||||||
|
set_local_dir(dir)
|
||||||
|
char *dir;
|
||||||
|
CODE:
|
||||||
|
Slic3r::set_local_dir(dir);
|
||||||
|
|
||||||
char*
|
char*
|
||||||
var_dir()
|
var_dir()
|
||||||
CODE:
|
CODE:
|
||||||
|
Loading…
Reference in New Issue
Block a user