Don't use StandardPaths before OnInit is called

AegisubLocale is created extremely early in the application
initialization, and using StandardPaths in its constructor resulted in
?user being set to an incorrect value as the app name hadn't been set
yet.
This commit is contained in:
Thomas Goyne 2012-10-04 12:58:01 -07:00
parent 662cf01493
commit 7343392823
2 changed files with 12 additions and 6 deletions

View file

@ -56,13 +56,17 @@
#define AEGISUB_CATALOG "aegisub" #define AEGISUB_CATALOG "aegisub"
#endif #endif
AegisubLocale::AegisubLocale() { wxTranslations *AegisubLocale::GetTranslations() {
wxTranslations::Set(new wxTranslations); wxTranslations *translations = wxTranslations::Get();
wxFileTranslationsLoader::AddCatalogLookupPathPrefix(StandardPaths::DecodePath("?data/locale/")); if (!translations) {
wxTranslations::Set(translations = new wxTranslations);
wxFileTranslationsLoader::AddCatalogLookupPathPrefix(StandardPaths::DecodePath("?data/locale/"));
}
return translations;
} }
void AegisubLocale::Init(wxString const& language) { void AegisubLocale::Init(wxString const& language) {
wxTranslations *translations = wxTranslations::Get(); wxTranslations *translations = GetTranslations();
translations->SetLanguage(language); translations->SetLanguage(language);
translations->AddCatalog(AEGISUB_CATALOG); translations->AddCatalog(AEGISUB_CATALOG);
translations->AddStdCatalog(); translations->AddStdCatalog();
@ -73,7 +77,7 @@ void AegisubLocale::Init(wxString const& language) {
} }
wxString AegisubLocale::PickLanguage() { wxString AegisubLocale::PickLanguage() {
wxArrayString langs = wxTranslations::Get()->GetAvailableTranslations(AEGISUB_CATALOG); wxArrayString langs = GetTranslations()->GetAvailableTranslations(AEGISUB_CATALOG);
langs.insert(langs.begin(), "en_US"); langs.insert(langs.begin(), "en_US");
// Check if user local language is available, if so, make it first // Check if user local language is available, if so, make it first

View file

@ -34,6 +34,8 @@
/// @ingroup utility /// @ingroup utility
/// ///
class wxTranslations;
/// DOCME /// DOCME
/// @class AegisubLocale /// @class AegisubLocale
/// @brief DOCME /// @brief DOCME
@ -41,8 +43,8 @@
/// DOCME /// DOCME
class AegisubLocale { class AegisubLocale {
wxString active_language; wxString active_language;
wxTranslations *GetTranslations();
public: public:
AegisubLocale();
void Init(wxString const& language); void Init(wxString const& language);
wxString PickLanguage(); wxString PickLanguage();
}; };