From d9ed0de8abe3bdab88f5e75ceaf6ded22a6c80e7 Mon Sep 17 00:00:00 2001 From: Alexander Kojevnikov Date: Fri, 10 Aug 2012 10:59:01 -0700 Subject: [PATCH] Init locale --- src/spek-platform.cc | 2 +- src/spek-preferences.cc | 21 ++++++++++++++++++++- src/spek-preferences.hh | 3 +++ src/spek.cc | 11 ++++++++--- src/spek.vala | 4 ---- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/spek-platform.cc b/src/spek-platform.cc index cafd050..987a88d 100644 --- a/src/spek-platform.cc +++ b/src/spek-platform.cc @@ -29,7 +29,7 @@ wxString SpekPlatform::ConfigPath(const wxString& app_name) #ifdef OS_WIN wxFileName file_name(wxStandardPaths::Get().GetUserConfigDir()); #else - wxFileName file_name(wxGetHomeDir()); + wxFileName file_name(wxGetHomeDir(), wxEmptyString); file_name.AppendDir(wxT(".config")); #endif file_name.AppendDir(app_name); diff --git a/src/spek-preferences.cc b/src/spek-preferences.cc index cd9f0d5..559f0ea 100644 --- a/src/spek-preferences.cc +++ b/src/spek-preferences.cc @@ -28,7 +28,26 @@ SpekPreferences& SpekPreferences::Get() return instance; } -SpekPreferences::SpekPreferences() +void SpekPreferences::Init() +{ + if (this->locale) { + delete this->locale; + } + this->locale = new wxLocale(); + + int lang = wxLANGUAGE_DEFAULT; + wxString code = this->GetLanguage(); + if (!code.IsEmpty()) { + const wxLanguageInfo *info = wxLocale::FindLanguageInfo(code); + if (info) { + lang = info->Language; + } + } + this->locale->Init(lang); + this->locale->AddCatalog(wxT(GETTEXT_PACKAGE)); +} + +SpekPreferences::SpekPreferences() : locale(NULL) { wxString path = SpekPlatform::ConfigPath(wxT("spek")); this->config = new wxFileConfig( diff --git a/src/spek-preferences.hh b/src/spek-preferences.hh index 41c52f3..368bcf0 100644 --- a/src/spek-preferences.hh +++ b/src/spek-preferences.hh @@ -20,12 +20,14 @@ #define SPEK_PREFERENCES_HH_ #include +#include class SpekPreferences { public: static SpekPreferences& Get(); + void Init(); bool GetCheckUpdate(); void SetCheckUpdate(bool value); long GetLastUpdate(); @@ -38,6 +40,7 @@ private: SpekPreferences(const SpekPreferences&); void operator=(const SpekPreferences&); + wxLocale *locale; wxFileConfig *config; }; diff --git a/src/spek.cc b/src/spek.cc index 55bc9e6..6e0f281 100644 --- a/src/spek.cc +++ b/src/spek.cc @@ -1,6 +1,6 @@ -/* spek.vala +/* spek.cc * - * Copyright (C) 2010-2011 Alexander Kojevnikov + * Copyright (C) 2010-2012 Alexander Kojevnikov * * Spek is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,8 @@ #include #include +#include "spek-preferences.hh" + #include "spek-window.hh" class Spek: public wxApp @@ -33,6 +35,8 @@ IMPLEMENT_APP(Spek) bool Spek::OnInit() { + SpekPreferences::Get().Init(); + if (!wxApp::OnInit()) { return false; } @@ -46,7 +50,8 @@ bool Spek::OnInit() void Spek::OnInitCmdLine(wxCmdLineParser& parser) { wxCmdLineEntryDesc desc[] = {{ - wxCMD_LINE_SWITCH, wxT("h"), + wxCMD_LINE_SWITCH, + wxT("h"), wxT("help"), _("Show this help message"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP diff --git a/src/spek.vala b/src/spek.vala index 5b823c1..801594b 100644 --- a/src/spek.vala +++ b/src/spek.vala @@ -26,10 +26,6 @@ namespace Spek { Environment.set_variable ("LANGUAGE", Preferences.instance.language, true); } - Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Platform.locale_dir ()); - Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8"); - Intl.textdomain (Config.GETTEXT_PACKAGE); - Audio.init (); var file_name = files == null ? null : files[0]; if (file_name != null && file_name.has_prefix ("file://")) {