]> git.saurik.com Git - wxWidgets.git/blob - include/wx/intl.h
Rewrote wxNotebook, incl. PAGE_CHANGING event
[wxWidgets.git] / include / wx / intl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: intl.h
3 // Purpose: Internationalization and localisation for wxWindows
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __INTLH__
13 #define __INTLH__
14
15 #ifdef __GNUG__
16 #pragma interface "intl.h"
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/string.h"
21
22 // ============================================================================
23 // global decls
24 // ============================================================================
25
26 // ----------------------------------------------------------------------------
27 // macros
28 // ----------------------------------------------------------------------------
29
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(_T(str))
34 #endif
35
36 // ----------------------------------------------------------------------------
37 // forward decls
38 // ----------------------------------------------------------------------------
39 class WXDLLEXPORT wxLocale;
40 class WXDLLEXPORT wxMsgCatalog;
41
42 // ============================================================================
43 // locale support
44 // ============================================================================
45
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
51 {
52 public:
53 // ctor & dtor
54 // -----------
55
56 // call Init() if you use this ctor
57 wxLocale();
58 // the ctor has a side effect of changing current locale
59 wxLocale(const wxChar *szName, // name (for messages)
60 const wxChar *szShort = (const wxChar *) NULL, // dir prefix (for msg files)
61 const wxChar *szLocale = (const wxChar *) 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 wxChar *szName,
66 const wxChar *szShort = (const wxChar *) NULL,
67 const wxChar *szLocale = (const wxChar *) NULL,
68 bool bLoadDefault = TRUE);
69 // restores old locale
70 ~wxLocale();
71
72 // returns locale name
73 const wxChar *GetLocale() const { return m_strLocale; }
74
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
77 // (in this order).
78 //
79 // This only applies to subsequent invocations of AddCatalog()!
80 static void AddCatalogLookupPathPrefix(const wxString& prefix);
81
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().
85 //
86 // The loaded catalog will be used for message lookup by GetString().
87 //
88 // Returns 'true' if it was successfully loaded
89 bool AddCatalog(const wxChar *szDomain);
90
91 // check if the given catalog is loaded
92 bool IsLoaded(const wxChar *szDomain) const;
93
94 // retrieve the translation for a string in all loaded domains unless
95 // the szDomain parameter is specified (and then only this domain is
96 // searched)
97 //
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)
101 //
102 // domains are searched in the last to first order, i.e. catalogs
103 // added later override those added before.
104 const wxMB2WXbuf GetString(const wxChar *szOrigString,
105 const wxChar *szDomain = (const wxChar *) NULL) const;
106
107 // Returns the current short name for the locale
108 const wxString& GetName() const { return m_strShort; }
109
110 private:
111 // find catalog by name in a linked list, return NULL if !found
112 wxMsgCatalog *FindCatalog(const wxChar *szDomain) const;
113
114 wxString m_strLocale, // this locale name
115 m_strShort; // short name for the locale
116
117 const wxChar *m_pszOldLocale; // previous locale from setlocale()
118 wxLocale *m_pOldLocale; // previous wxLocale
119
120 wxMsgCatalog *m_pMsgCat; // pointer to linked list of catalogs
121 };
122
123 // ----------------------------------------------------------------------------
124 // global functions
125 // ----------------------------------------------------------------------------
126
127 // get the current locale object (note that it may be NULL!)
128 extern WXDLLEXPORT wxLocale* wxGetLocale();
129
130 // get the translation of the string in the current locale
131 inline const wxMB2WXbuf wxGetTranslation(const wxChar *sz)
132 {
133 wxLocale *pLoc = wxGetLocale();
134 if (pLoc)
135 return pLoc->GetString(sz);
136 else
137 return (const wxMB2WXbuf)sz;
138 }
139
140 #endif
141 // _WX_INTLH__