diff --git a/aegisub/src/aegisublocale.cpp b/aegisub/src/aegisublocale.cpp index 42fb2a5f7..da5c6e0b8 100644 --- a/aegisub/src/aegisublocale.cpp +++ b/aegisub/src/aegisublocale.cpp @@ -34,9 +34,6 @@ /// @ingroup utility /// - -/////////// -// Headers #include "config.h" #ifndef AGI_PRE @@ -52,34 +49,17 @@ #include "aegisublocale.h" #include "standard_paths.h" -/// @brief Constructor -/// -AegisubLocale::AegisubLocale () { - locale = NULL; - curCode = -1; -} - - -/// @brief DOCME -/// AegisubLocale::~AegisubLocale() { - delete locale; } - -/// @brief Initialize -/// @param language -/// void AegisubLocale::Init(int language) { - if (language == -1) language = wxLANGUAGE_ENGLISH; - if (locale) delete locale; + if (language == -1) + language = wxLANGUAGE_ENGLISH; - if (!wxLocale::IsAvailable(language)) { + if (!wxLocale::IsAvailable(language)) language = wxLANGUAGE_UNKNOWN; - } - curCode = language; - locale = new wxLocale(language); + locale.reset(new wxLocale(language)); #ifdef __WINDOWS__ locale->AddCatalogLookupPathPrefix(StandardPaths::DecodePath("?data/locale/")); @@ -93,52 +73,52 @@ void AegisubLocale::Init(int language) { setlocale(LC_CTYPE, "C"); } - - -/// @brief Pick a language -/// @return -/// int AegisubLocale::PickLanguage() { - // Get list wxArrayInt langs = GetAvailableLanguages(); // Check if english is in it, else add it if (langs.Index(wxLANGUAGE_ENGLISH) == wxNOT_FOUND) { - langs.Insert(wxLANGUAGE_ENGLISH,0); + langs.Insert(wxLANGUAGE_ENGLISH, 0); } // Check if user local language is available, if so, make it first int user = wxLocale::GetSystemLanguage(); if (langs.Index(user) != wxNOT_FOUND) { langs.Remove(user); - langs.Insert(user,0); - } - - // Generate names - wxArrayString langNames; - for (size_t i=0;iGetLanguage()) + return -1; + return langs[picked]; + } + + return -1; } - - -/// @brief Get list of available languages -/// wxArrayInt AegisubLocale::GetAvailableLanguages() { wxArrayInt final; #ifdef __WINDOWS__ - wxString temp1; - // Open directory wxString folder = StandardPaths::DecodePath("?data/locale/"); wxDir dir; @@ -146,19 +126,17 @@ wxArrayInt AegisubLocale::GetAvailableLanguages() { if (!dir.Open(folder)) return final; // Enumerate folders - for (bool cont = dir.GetFirst(&temp1,"",wxDIR_DIRS);cont;cont = dir.GetNext(&temp1)) { + wxString temp1; + for (bool cont = dir.GetFirst(&temp1, "", wxDIR_DIRS); cont; cont = dir.GetNext(&temp1)) { // Check if .so exists inside folder - wxFileName file(folder + temp1 + "/aegisub.mo"); - if (file.FileExists()) { + if (wxFileName::FileExists(folder + temp1 + "/aegisub.mo")) { const wxLanguageInfo *lang = wxLocale::FindLanguageInfo(temp1); if (lang) { final.Add(lang->Language); } } } - #else - const char* langs[] = { "ca", "cs", diff --git a/aegisub/src/aegisublocale.h b/aegisub/src/aegisublocale.h index fc2a3f23e..fc8c2cecd 100644 --- a/aegisub/src/aegisublocale.h +++ b/aegisub/src/aegisublocale.h @@ -34,33 +34,20 @@ /// @ingroup utility /// +#include - - -////////////// -// Prototypes class wxLocale; - - /// DOCME /// @class AegisubLocale /// @brief DOCME /// /// DOCME class AegisubLocale { -private: - - /// DOCME - wxLocale *locale; + agi::scoped_ptr locale; wxArrayInt GetAvailableLanguages(); public: - - /// DOCME - int curCode; - - AegisubLocale(); ~AegisubLocale(); void Init(int language); int PickLanguage(); diff --git a/aegisub/src/command/app.cpp b/aegisub/src/command/app.cpp index 23bc82c7f..9c4940b47 100644 --- a/aegisub/src/command/app.cpp +++ b/aegisub/src/command/app.cpp @@ -185,15 +185,14 @@ struct app_language : public Command { void operator()(agi::Context *c) { // Get language - int old = wxGetApp().locale.curCode; int newCode = wxGetApp().locale.PickLanguage(); // Is OK? - if (newCode != -1 && newCode != old) { + if (newCode != -1) { // Set code OPT_SET("App/Locale")->SetInt(newCode); // Ask to restart program - int result = wxMessageBox("Aegisub needs to be restarted so that the new language can be applied. Restart now?","Restart Aegisub?",wxICON_QUESTION | wxYES_NO); + int result = wxMessageBox("Aegisub needs to be restarted so that the new language can be applied. Restart now?", "Restart Aegisub?", wxICON_QUESTION | wxYES_NO); if (result == wxYES) { // Restart Aegisub if (wxGetApp().frame->Close()) {