]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/intl.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Internationalization and localisation for wxWindows
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "intl.h"
20 #include "wx/string.h"
22 // ============================================================================
24 // ============================================================================
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 // gettext() style macro (notice that xgettext should be invoked with "-k_"
31 // option to extract the strings inside _() from the sources)
32 #ifndef WXINTL_NO_GETTEXT_MACRO
33 #define _(str) wxGetTranslation(str)
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
39 class WXDLLEXPORT wxLocale
;
40 class WXDLLEXPORT wxMsgCatalog
;
42 // ============================================================================
44 // ============================================================================
46 // ----------------------------------------------------------------------------
47 // wxLocale: encapsulates all language dependent settings, including current
48 // message catalogs, date, time and currency formats (TODO) &c
49 // ----------------------------------------------------------------------------
50 class WXDLLEXPORT wxLocale
56 // call Init() if you use this ctor
58 // the ctor has a side effect of changing current locale
59 wxLocale(const char *szName
, // name (for messages)
60 const char *szShort
= (const char *) NULL
, // dir prefix (for msg files)
61 const char *szLocale
= (const char *) NULL
, // locale (for setlocale)
62 bool bLoadDefault
= TRUE
) // preload wxstd.mo?
63 { Init(szName
, szShort
, szLocale
, bLoadDefault
); }
64 // the same as a function (returns TRUE on success)
65 bool Init(const char *szName
,
66 const char *szShort
= (const char *) NULL
,
67 const char *szLocale
= (const char *) NULL
,
68 bool bLoadDefault
= TRUE
);
69 // restores old locale
72 // returns locale name
73 const char *GetLocale() const { return m_strLocale
; }
75 // add a prefix to the catalog lookup path: the message catalog files will be
76 // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
79 // This only applies to subsequent invocations of AddCatalog()!
80 static void AddCatalogLookupPathPrefix(const wxString
& prefix
);
82 // add a catalog: it's searched for in standard places (current directory
83 // first, system one after), but the you may prepend additional directories to
84 // the search path with AddCatalogLookupPathPrefix().
86 // The loaded catalog will be used for message lookup by GetString().
88 // Returns 'true' if it was successfully loaded
89 bool AddCatalog(const char *szDomain
);
91 // check if the given catalog is loaded
92 bool IsLoaded(const char *szDomain
) const;
94 // retrieve the translation for a string in all loaded domains unless
95 // the szDomain parameter is specified (and then only this domain is
98 // return original string if translation is not available
99 // (in this case an error message is generated the first time
100 // a string is not found; use wxLogNull to suppress it)
102 // domains are searched in the last to first order, i.e. catalogs
103 // added later override those added before.
104 const char *GetString(const char *szOrigString
,
105 const char *szDomain
= (const char *) NULL
) const;
107 // Returns the current short name for the locale
108 const wxString
& GetName() const { return m_strShort
; }
111 // find catalog by name in a linked list, return NULL if !found
112 wxMsgCatalog
*FindCatalog(const char *szDomain
) const;
114 wxString m_strLocale
, // this locale name
115 m_strShort
; // short name for the locale
117 const char *m_pszOldLocale
; // previous locale from setlocale()
118 wxLocale
*m_pOldLocale
; // previous wxLocale
120 wxMsgCatalog
*m_pMsgCat
; // pointer to linked list of catalogs
123 // ----------------------------------------------------------------------------
125 // ----------------------------------------------------------------------------
127 // get the current locale object (note that it may be NULL!)
128 extern WXDLLEXPORT wxLocale
* wxGetLocale();
130 // get the translation of the string in the current locale
131 inline const char *wxGetTranslation(const char *sz
)
133 wxLocale
*pLoc
= wxGetLocale();
134 return pLoc
? pLoc
->GetString(sz
) : sz
;