String localization implemented (missing some strings)

This commit is contained in:
Grégory Soutadé 2010-07-07 21:04:38 +02:00
parent f6c64d5448
commit 63ca3a9c22
12 changed files with 145 additions and 31 deletions

BIN
ressources/icons/France.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -245,3 +245,9 @@ void KissCount::KillMe()
_user = NULL;
_wxUI->ChangeUser();
}
void KissCount::SetLanguage(wxLanguage language)
{
_db->SetLanguage(_user, language);
_user->_preferences[wxT("language")] = wxString::Format(wxT("%d"), language) ;
}

View File

@ -45,6 +45,8 @@ class KissCount
void GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo);
void KillMe();
void SetLanguage(wxLanguage language);
private:
wxUI* _wxUI;
Database* _db;

View File

@ -882,3 +882,31 @@ void Database::KillMe(User* user)
req = wxT("DELETE FROM user WHERE id='") + user->_id + wxT("'");
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 ;
}
}

View File

@ -47,6 +47,8 @@ class Database
void ChangeName(User* user, const wxString& name);
void NewUser(const wxString& name);
void SetLanguage(User* user, wxLanguage language);
void KillMe(User* user);
private:
wxSQLite3Database _db;

View File

@ -92,7 +92,7 @@ wxLanguage User::GetLanguage()
long val;
if (res == wxT(""))
return wxLANGUAGE_ENGLISH_UK ;
return wxLANGUAGE_ENGLISH ;
res.ToLong(&val);

View File

@ -196,12 +196,11 @@ void PreferencesPanel::InitCategories(User* user)
void PreferencesPanel::InitLanguage(User* user)
{
int i, select=0;
wxLanguage pref = user->GetLanguage();
for (i=0; i<NB_SUPPORTED_LANGUAGES; i++)
{
_language->Append(languages[i].name, wxBitmap(languages[i].icon));
if (languages[i].language == pref)
if (languages[i].language == _wxUI->_language)
select = i;
}
@ -478,7 +477,15 @@ void PreferencesPanel::OnChangePassword(wxCommandEvent& event)
void PreferencesPanel::OnLanguageChange(wxCommandEvent& event)
{
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)

View 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}
};

View 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

View File

@ -22,19 +22,6 @@ wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxS
// CreateStatusBar();
// 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);
_hbox->Add(buttons);
@ -49,6 +36,8 @@ wxUI::~wxUI()
bool wxUI::SetLanguage(long language)
{
bool res = true;
if (_locale) delete _locale;
_locale = NULL;
@ -63,16 +52,39 @@ bool wxUI::SetLanguage(long language)
_locale->AddCatalog(wxT("french"));
_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;
_locale = new wxLocale( wxLANGUAGE_ENGLISH );
return false;
_locale = new wxLocale();
#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()
@ -93,6 +105,8 @@ void wxUI::ChangeUser()
void wxUI::LoadUser()
{
User* user = _kiss->GetUser();
if (_curPanel)
{
_hbox->Detach(_curPanel);
@ -105,6 +119,9 @@ void wxUI::LoadUser()
if (_preferencesPanel)
delete _preferencesPanel;
if (user->_preferences[wxT("language")] != wxT(""))
SetLanguage(user->GetLanguage());
_preferencesPanel = new PreferencesPanel(_kiss, this);
_accountPanel = new AccountPanel(_kiss, this);
@ -113,7 +130,8 @@ void wxUI::LoadUser()
void wxUI::ShowPanel(wxPanel* panel)
{
int month, year;
int month, year, account=0, preferences=0;
wxShowEvent event;
if (!panel) return;
@ -123,13 +141,39 @@ void wxUI::ShowPanel(wxPanel* panel)
_curPanel->Hide();
}
if (panel == _accountPanel && _needReload)
if (_needReload)
{
if (panel == _accountPanel)
{
account = 1;
month = _accountPanel->_curMonth;
year = _accountPanel->_curYear;
}
if (panel == _preferencesPanel)
{
preferences = 1;
}
delete _accountPanel;
panel = _accountPanel = new AccountPanel(_kiss, this);
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;
}

View File

@ -33,8 +33,11 @@ class wxUI: public wxFrame
void KillMe();
void ShowPanel(wxPanel* panel);
void NeedReload();
wxLanguage _language;
private:
KissCount *_kiss;
wxBoxSizer *_hbox;
@ -43,8 +46,6 @@ class wxUI: public wxFrame
wxPanel *_curPanel;
wxLocale *_locale;
bool _needReload;
void ShowPanel(wxPanel* panel);
};
#endif