String localization implemented (missing some strings)
This commit is contained in:
parent
f6c64d5448
commit
63ca3a9c22
BIN
ressources/icons/France.png
Normal file
BIN
ressources/icons/France.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 637 B |
BIN
ressources/icons/United Kingdom.png
Normal file
BIN
ressources/icons/United Kingdom.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
|
@ -245,3 +245,9 @@ void KissCount::KillMe()
|
||||||
_user = NULL;
|
_user = NULL;
|
||||||
_wxUI->ChangeUser();
|
_wxUI->ChangeUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KissCount::SetLanguage(wxLanguage language)
|
||||||
|
{
|
||||||
|
_db->SetLanguage(_user, language);
|
||||||
|
_user->_preferences[wxT("language")] = wxString::Format(wxT("%d"), language) ;
|
||||||
|
}
|
||||||
|
|
|
@ -45,6 +45,8 @@ class KissCount
|
||||||
|
|
||||||
void GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo);
|
void GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo);
|
||||||
void KillMe();
|
void KillMe();
|
||||||
|
|
||||||
|
void SetLanguage(wxLanguage language);
|
||||||
private:
|
private:
|
||||||
wxUI* _wxUI;
|
wxUI* _wxUI;
|
||||||
Database* _db;
|
Database* _db;
|
||||||
|
|
|
@ -882,3 +882,31 @@ void Database::KillMe(User* user)
|
||||||
req = wxT("DELETE FROM user WHERE id='") + user->_id + wxT("'");
|
req = wxT("DELETE FROM user WHERE id='") + user->_id + wxT("'");
|
||||||
EXECUTE_SQL_UPDATE(req, );
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Database::SetLanguage(User* user, wxLanguage language)
|
||||||
|
{
|
||||||
|
wxString req;
|
||||||
|
req = wxT("UPDATE preference SET ") ;
|
||||||
|
req += wxT("name='language'");
|
||||||
|
req += wxT(", value='") + wxString::Format(wxT("%d"), language) + wxT("'");
|
||||||
|
req += wxT(" WHERE user='") + user->_id + wxT("'");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_db.ExecuteUpdate(req))
|
||||||
|
{
|
||||||
|
req = wxT("INSERT INTO preference ('user', 'name', 'value') VALUES ('") ;
|
||||||
|
req += user->_id + wxT("'");
|
||||||
|
req += wxT(" ,'language'");
|
||||||
|
req += wxT(" ,'") + wxString::Format(wxT("%d"), language) + wxT("'");
|
||||||
|
req += wxT(")");
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (wxSQLite3Exception e)
|
||||||
|
{
|
||||||
|
std::cerr << req.mb_str() << "\n" ;
|
||||||
|
std::cerr << e.GetMessage().mb_str() << "\n" ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -47,6 +47,8 @@ class Database
|
||||||
void ChangeName(User* user, const wxString& name);
|
void ChangeName(User* user, const wxString& name);
|
||||||
void NewUser(const wxString& name);
|
void NewUser(const wxString& name);
|
||||||
|
|
||||||
|
void SetLanguage(User* user, wxLanguage language);
|
||||||
|
|
||||||
void KillMe(User* user);
|
void KillMe(User* user);
|
||||||
private:
|
private:
|
||||||
wxSQLite3Database _db;
|
wxSQLite3Database _db;
|
||||||
|
|
|
@ -92,7 +92,7 @@ wxLanguage User::GetLanguage()
|
||||||
long val;
|
long val;
|
||||||
|
|
||||||
if (res == wxT(""))
|
if (res == wxT(""))
|
||||||
return wxLANGUAGE_ENGLISH_UK ;
|
return wxLANGUAGE_ENGLISH ;
|
||||||
|
|
||||||
res.ToLong(&val);
|
res.ToLong(&val);
|
||||||
|
|
||||||
|
|
|
@ -196,12 +196,11 @@ void PreferencesPanel::InitCategories(User* user)
|
||||||
void PreferencesPanel::InitLanguage(User* user)
|
void PreferencesPanel::InitLanguage(User* user)
|
||||||
{
|
{
|
||||||
int i, select=0;
|
int i, select=0;
|
||||||
wxLanguage pref = user->GetLanguage();
|
|
||||||
|
|
||||||
for (i=0; i<NB_SUPPORTED_LANGUAGES; i++)
|
for (i=0; i<NB_SUPPORTED_LANGUAGES; i++)
|
||||||
{
|
{
|
||||||
_language->Append(languages[i].name, wxBitmap(languages[i].icon));
|
_language->Append(languages[i].name, wxBitmap(languages[i].icon));
|
||||||
if (languages[i].language == pref)
|
if (languages[i].language == _wxUI->_language)
|
||||||
select = i;
|
select = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,7 +477,15 @@ void PreferencesPanel::OnChangePassword(wxCommandEvent& event)
|
||||||
void PreferencesPanel::OnLanguageChange(wxCommandEvent& event)
|
void PreferencesPanel::OnLanguageChange(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
wxLanguage language = languages[_language->GetSelection()].language;
|
wxLanguage language = languages[_language->GetSelection()].language;
|
||||||
_wxUI->SetLanguage(language);
|
if (_wxUI->SetLanguage(language) || language == wxLANGUAGE_ENGLISH)
|
||||||
|
{
|
||||||
|
_wxUI->NeedReload();
|
||||||
|
_kiss->SetLanguage(language);
|
||||||
|
wxMessageBox(_("Language successfully changed, please go to another panel"), _("KissCount"), wxICON_INFORMATION | wxOK);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
wxMessageBox(_("Language not changed"), _("KissCount"), wxICON_ERROR | wxOK);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreferencesPanel::OnShow(wxShowEvent& event)
|
void PreferencesPanel::OnShow(wxShowEvent& event)
|
||||||
|
|
7
src/view/SupportedLanguages.cpp
Normal file
7
src/view/SupportedLanguages.cpp
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#include "SupportedLanguages.h"
|
||||||
|
|
||||||
|
language languages[NB_SUPPORTED_LANGUAGES] = {
|
||||||
|
{ wxT("English"), wxT(ICONS_PATH "/United Kingdom.png"), wxLANGUAGE_ENGLISH},
|
||||||
|
{ wxT("Français"), wxT(ICONS_PATH "/France.png"), wxLANGUAGE_FRENCH}
|
||||||
|
};
|
||||||
|
|
17
src/view/SupportedLanguages.h
Normal file
17
src/view/SupportedLanguages.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef SUPPORTEDLANGUAGES_H
|
||||||
|
#define SUPPORTEDLANGUAGES_H
|
||||||
|
|
||||||
|
#include <wx/wx.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
wxString name;
|
||||||
|
wxString icon;
|
||||||
|
wxLanguage language;
|
||||||
|
} language ;
|
||||||
|
|
||||||
|
#define NB_SUPPORTED_LANGUAGES 2
|
||||||
|
#define ICONS_PATH "./ressources/icons"
|
||||||
|
|
||||||
|
extern language languages[NB_SUPPORTED_LANGUAGES];
|
||||||
|
|
||||||
|
#endif
|
|
@ -22,19 +22,6 @@ wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxS
|
||||||
// CreateStatusBar();
|
// CreateStatusBar();
|
||||||
// SetStatusText( wxT("Welcome to wxWidgets!") );
|
// SetStatusText( wxT("Welcome to wxWidgets!") );
|
||||||
|
|
||||||
months[0] = _("january");
|
|
||||||
months[1] = _("february");
|
|
||||||
months[2] = _("march");
|
|
||||||
months[3] = _("april");
|
|
||||||
months[4] = _("may");
|
|
||||||
months[5] = _("june");
|
|
||||||
months[6] = _("july");
|
|
||||||
months[7] = _("august");
|
|
||||||
months[8] = _("september");
|
|
||||||
months[9] = _("october");
|
|
||||||
months[10] = _("november");
|
|
||||||
months[11] = _("december") ;
|
|
||||||
|
|
||||||
SetSizer(_hbox);
|
SetSizer(_hbox);
|
||||||
|
|
||||||
_hbox->Add(buttons);
|
_hbox->Add(buttons);
|
||||||
|
@ -49,6 +36,8 @@ wxUI::~wxUI()
|
||||||
|
|
||||||
bool wxUI::SetLanguage(long language)
|
bool wxUI::SetLanguage(long language)
|
||||||
{
|
{
|
||||||
|
bool res = true;
|
||||||
|
|
||||||
if (_locale) delete _locale;
|
if (_locale) delete _locale;
|
||||||
_locale = NULL;
|
_locale = NULL;
|
||||||
|
|
||||||
|
@ -63,16 +52,39 @@ bool wxUI::SetLanguage(long language)
|
||||||
|
|
||||||
_locale->AddCatalog(wxT("french"));
|
_locale->AddCatalog(wxT("french"));
|
||||||
_locale->AddCatalog(wxT("kisscount"));
|
_locale->AddCatalog(wxT("kisscount"));
|
||||||
|
|
||||||
|
_language = (wxLanguage) language;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((_locale == NULL || !_locale->IsOk()) && wxLocale::IsAvailable(wxLANGUAGE_ENGLISH))
|
if (_locale == NULL || !_locale->IsOk())
|
||||||
{
|
{
|
||||||
if (_locale) delete _locale;
|
if (_locale) delete _locale;
|
||||||
_locale = new wxLocale( wxLANGUAGE_ENGLISH );
|
_locale = new wxLocale();
|
||||||
return false;
|
|
||||||
|
#ifdef __WXGTK__
|
||||||
|
_locale->AddCatalogLookupPathPrefix(wxT("./ressources/po"));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_locale->AddCatalog(wxT("kisscount"));
|
||||||
|
|
||||||
|
_language = wxLANGUAGE_ENGLISH;
|
||||||
|
res = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
months[0] = _("january");
|
||||||
|
months[1] = _("february");
|
||||||
|
months[2] = _("march");
|
||||||
|
months[3] = _("april");
|
||||||
|
months[4] = _("may");
|
||||||
|
months[5] = _("june");
|
||||||
|
months[6] = _("july");
|
||||||
|
months[7] = _("august");
|
||||||
|
months[8] = _("september");
|
||||||
|
months[9] = _("october");
|
||||||
|
months[10] = _("november");
|
||||||
|
months[11] = _("december") ;
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxUI::ShowAccount()
|
void wxUI::ShowAccount()
|
||||||
|
@ -93,6 +105,8 @@ void wxUI::ChangeUser()
|
||||||
|
|
||||||
void wxUI::LoadUser()
|
void wxUI::LoadUser()
|
||||||
{
|
{
|
||||||
|
User* user = _kiss->GetUser();
|
||||||
|
|
||||||
if (_curPanel)
|
if (_curPanel)
|
||||||
{
|
{
|
||||||
_hbox->Detach(_curPanel);
|
_hbox->Detach(_curPanel);
|
||||||
|
@ -105,6 +119,9 @@ void wxUI::LoadUser()
|
||||||
if (_preferencesPanel)
|
if (_preferencesPanel)
|
||||||
delete _preferencesPanel;
|
delete _preferencesPanel;
|
||||||
|
|
||||||
|
if (user->_preferences[wxT("language")] != wxT(""))
|
||||||
|
SetLanguage(user->GetLanguage());
|
||||||
|
|
||||||
_preferencesPanel = new PreferencesPanel(_kiss, this);
|
_preferencesPanel = new PreferencesPanel(_kiss, this);
|
||||||
_accountPanel = new AccountPanel(_kiss, this);
|
_accountPanel = new AccountPanel(_kiss, this);
|
||||||
|
|
||||||
|
@ -113,7 +130,8 @@ void wxUI::LoadUser()
|
||||||
|
|
||||||
void wxUI::ShowPanel(wxPanel* panel)
|
void wxUI::ShowPanel(wxPanel* panel)
|
||||||
{
|
{
|
||||||
int month, year;
|
int month, year, account=0, preferences=0;
|
||||||
|
wxShowEvent event;
|
||||||
|
|
||||||
if (!panel) return;
|
if (!panel) return;
|
||||||
|
|
||||||
|
@ -122,14 +140,40 @@ void wxUI::ShowPanel(wxPanel* panel)
|
||||||
_hbox->Detach(_curPanel);
|
_hbox->Detach(_curPanel);
|
||||||
_curPanel->Hide();
|
_curPanel->Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (panel == _accountPanel && _needReload)
|
if (_needReload)
|
||||||
{
|
{
|
||||||
month = _accountPanel->_curMonth;
|
if (panel == _accountPanel)
|
||||||
year = _accountPanel->_curYear;
|
{
|
||||||
delete _accountPanel;
|
account = 1;
|
||||||
panel = _accountPanel = new AccountPanel(_kiss, this);
|
month = _accountPanel->_curMonth;
|
||||||
_accountPanel->ShowMonth(month, year);
|
year = _accountPanel->_curYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (panel == _preferencesPanel)
|
||||||
|
{
|
||||||
|
preferences = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete _accountPanel;
|
||||||
|
delete _preferencesPanel;
|
||||||
|
|
||||||
|
_accountPanel = new AccountPanel(_kiss, this);
|
||||||
|
if (year != -1)
|
||||||
|
_accountPanel->ShowMonth(month, year);
|
||||||
|
_preferencesPanel = new PreferencesPanel(_kiss, this);
|
||||||
|
|
||||||
|
if (account)
|
||||||
|
{
|
||||||
|
_accountPanel->OnShow(event);
|
||||||
|
panel = _accountPanel;
|
||||||
|
}
|
||||||
|
if (preferences)
|
||||||
|
{
|
||||||
|
_preferencesPanel->OnShow(event);
|
||||||
|
panel = _preferencesPanel;
|
||||||
|
}
|
||||||
|
|
||||||
_needReload = false;
|
_needReload = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,11 @@ class wxUI: public wxFrame
|
||||||
|
|
||||||
void KillMe();
|
void KillMe();
|
||||||
|
|
||||||
|
void ShowPanel(wxPanel* panel);
|
||||||
void NeedReload();
|
void NeedReload();
|
||||||
|
|
||||||
|
wxLanguage _language;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KissCount *_kiss;
|
KissCount *_kiss;
|
||||||
wxBoxSizer *_hbox;
|
wxBoxSizer *_hbox;
|
||||||
|
@ -43,8 +46,6 @@ class wxUI: public wxFrame
|
||||||
wxPanel *_curPanel;
|
wxPanel *_curPanel;
|
||||||
wxLocale *_locale;
|
wxLocale *_locale;
|
||||||
bool _needReload;
|
bool _needReload;
|
||||||
|
|
||||||
void ShowPanel(wxPanel* panel);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user