X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/611bed35118d838abdec90a23a90e492a6cc75d1..e118367990e341b7ba8e5f02295d7aa8def23d5b:/include/wx/translation.h diff --git a/include/wx/translation.h b/include/wx/translation.h index abd92a6d27..187caf366b 100644 --- a/include/wx/translation.h +++ b/include/wx/translation.h @@ -4,7 +4,6 @@ // Author: Vadim Zeitlin, Vaclav Slavik, // Michael N. Filippov // Created: 2010-04-23 -// RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin // (c) 2010 Vaclav Slavik // Licence: wxWindows licence @@ -48,6 +47,7 @@ // forward decls // ---------------------------------------------------------------------------- +class WXDLLIMPEXP_FWD_BASE wxArrayString; class WXDLLIMPEXP_FWD_BASE wxTranslationsLoader; class WXDLLIMPEXP_FWD_BASE wxLocale; @@ -61,6 +61,12 @@ wxDECLARE_SCOPED_PTR(wxPluralFormsCalculator, wxPluralFormsCalculatorPtr) class WXDLLIMPEXP_BASE wxMsgCatalog { public: + // Ctor is protected, because CreateFromXXX functions must be used, + // but destruction should be unrestricted +#if !wxUSE_UNICODE + ~wxMsgCatalog(); +#endif + // load the catalog from disk or from data; caller is responsible for // deleting them if not NULL static wxMsgCatalog *CreateFromFile(const wxString& filename, @@ -82,9 +88,6 @@ protected: , m_conv(NULL) #endif {} -#if !wxUSE_UNICODE - ~wxMsgCatalog(); -#endif private: // variable pointing to the next element in a linked list (or NULL) @@ -125,6 +128,14 @@ public: void SetLanguage(wxLanguage lang); void SetLanguage(const wxString& lang); + // get languages available for this app + wxArrayString GetAvailableTranslations(const wxString& domain) const; + + // find best translation language for given domain + wxString GetBestTranslation(const wxString& domain, wxLanguage msgIdLanguage); + wxString GetBestTranslation(const wxString& domain, + const wxString& msgIdLanguage = "en"); + // add standard wxWidgets catalog ("wxstd") bool AddStdCatalog(); @@ -142,12 +153,11 @@ public: bool IsLoaded(const wxString& domain) const; // access to translations - const wxString& GetString(const wxString& origString, - const wxString& domain = wxEmptyString) const; - const wxString& GetString(const wxString& origString, - const wxString& origString2, - unsigned n, - const wxString& domain = wxEmptyString) const; + const wxString *GetTranslatedString(const wxString& origString, + const wxString& domain = wxEmptyString) const; + const wxString *GetTranslatedString(const wxString& origString, + unsigned n, + const wxString& domain = wxEmptyString) const; wxString GetHeaderValue(const wxString& header, const wxString& domain = wxEmptyString) const; @@ -159,11 +169,7 @@ public: private: // perform loading of the catalog via m_loader - bool LoadCatalog(const wxString& domain, const wxString& lang); - - // find best translation for given domain - wxString ChooseLanguageForDomain(const wxString& domain, - const wxString& msgIdLang); + bool LoadCatalog(const wxString& domain, const wxString& lang, const wxString& msgIdLang); // find catalog by name in a linked list, return NULL if !found wxMsgCatalog *FindCatalog(const wxString& domain) const; @@ -189,6 +195,8 @@ public: virtual wxMsgCatalog *LoadCatalog(const wxString& domain, const wxString& lang) = 0; + + virtual wxArrayString GetAvailableTranslations(const wxString& domain) const = 0; }; @@ -201,6 +209,8 @@ public: virtual wxMsgCatalog *LoadCatalog(const wxString& domain, const wxString& lang); + + virtual wxArrayString GetAvailableTranslations(const wxString& domain) const; }; @@ -213,6 +223,8 @@ public: virtual wxMsgCatalog *LoadCatalog(const wxString& domain, const wxString& lang); + virtual wxArrayString GetAvailableTranslations(const wxString& domain) const; + protected: // returns resource type to use for translations virtual wxString GetResourceType() const { return "MOFILE"; } @@ -229,11 +241,13 @@ protected: // get the translation of the string in the current locale inline const wxString& wxGetTranslation(const wxString& str, - const wxString& domain = wxEmptyString) + const wxString& domain = wxString()) { wxTranslations *trans = wxTranslations::Get(); - if ( trans ) - return trans->GetString(str, domain); + const wxString *transStr = trans ? trans->GetTranslatedString(str, domain) + : NULL; + if ( transStr ) + return *transStr; else // NB: this function returns reference to a string, so we have to keep // a copy of it somewhere @@ -243,11 +257,13 @@ inline const wxString& wxGetTranslation(const wxString& str, inline const wxString& wxGetTranslation(const wxString& str1, const wxString& str2, unsigned n, - const wxString& domain = wxEmptyString) + const wxString& domain = wxString()) { wxTranslations *trans = wxTranslations::Get(); - if ( trans ) - return trans->GetString(str1, str2, n, domain); + const wxString *transStr = trans ? trans->GetTranslatedString(str1, n, domain) + : NULL; + if ( transStr ) + return *transStr; else // NB: this function returns reference to a string, so we have to keep // a copy of it somewhere