]> git.saurik.com Git - wxWidgets.git/blob - include/wx/intl.h
Some cleanup.
[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 #if wxUSE_INTL
23
24 // ============================================================================
25 // global decls
26 // ============================================================================
27
28 // ----------------------------------------------------------------------------
29 // macros
30 // ----------------------------------------------------------------------------
31
32 // gettext() style macro (notice that xgettext should be invoked with "-k_"
33 // option to extract the strings inside _() from the sources)
34 #ifndef WXINTL_NO_GETTEXT_MACRO
35 #define _(str) wxGetTranslation(_T(str))
36 #endif
37
38 // another one which just marks the strings for extraction, but doesn't
39 // perform the translation (use -kwxTRANSLATE with xgettext!)
40 #define wxTRANSLATE(str) _T(str)
41
42 // ----------------------------------------------------------------------------
43 // forward decls
44 // ----------------------------------------------------------------------------
45 class WXDLLEXPORT wxLocale;
46 class WXDLLEXPORT wxMsgCatalog;
47
48 // ============================================================================
49 // locale support
50 // ============================================================================
51
52 // ----------------------------------------------------------------------------
53 // wxLocale: encapsulates all language dependent settings, including current
54 // message catalogs, date, time and currency formats (TODO) &c
55 // ----------------------------------------------------------------------------
56 class WXDLLEXPORT wxLocale
57 {
58 public:
59 // ctor & dtor
60 // -----------
61
62 // call Init() if you use this ctor
63 wxLocale();
64 // the ctor has a side effect of changing current locale
65 wxLocale(const wxChar *szName, // name (for messages)
66 const wxChar *szShort = (const wxChar *) NULL, // dir prefix (for msg files)
67 const wxChar *szLocale = (const wxChar *) NULL, // locale (for setlocale)
68 bool bLoadDefault = TRUE, // preload wxstd.mo?
69 bool bConvertEncoding = FALSE) // convert Win<->Unix if neccessary?
70 { Init(szName, szShort, szLocale, bLoadDefault, bConvertEncoding); }
71 // the same as a function (returns TRUE on success)
72 bool Init(const wxChar *szName,
73 const wxChar *szShort = (const wxChar *) NULL,
74 const wxChar *szLocale = (const wxChar *) NULL,
75 bool bLoadDefault = TRUE,
76 bool bConvertEncoding = FALSE);
77 // restores old locale
78 ~wxLocale();
79
80 // returns locale name
81 const wxChar *GetLocale() const { return m_strLocale; }
82
83 // add a prefix to the catalog lookup path: the message catalog files will be
84 // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
85 // (in this order).
86 //
87 // This only applies to subsequent invocations of AddCatalog()!
88 static void AddCatalogLookupPathPrefix(const wxString& prefix);
89
90 // add a catalog: it's searched for in standard places (current directory
91 // first, system one after), but the you may prepend additional directories to
92 // the search path with AddCatalogLookupPathPrefix().
93 //
94 // The loaded catalog will be used for message lookup by GetString().
95 //
96 // Returns 'true' if it was successfully loaded
97 bool AddCatalog(const wxChar *szDomain);
98
99 // check if the given catalog is loaded
100 bool IsLoaded(const wxChar *szDomain) const;
101
102 // retrieve the translation for a string in all loaded domains unless
103 // the szDomain parameter is specified (and then only this domain is
104 // searched)
105 //
106 // return original string if translation is not available
107 // (in this case an error message is generated the first time
108 // a string is not found; use wxLogNull to suppress it)
109 //
110 // domains are searched in the last to first order, i.e. catalogs
111 // added later override those added before.
112 const wxMB2WXbuf GetString(const wxChar *szOrigString,
113 const wxChar *szDomain = (const wxChar *) NULL) const;
114
115 // Returns the current short name for the locale
116 const wxString& GetName() const { return m_strShort; }
117
118 private:
119 // find catalog by name in a linked list, return NULL if !found
120 wxMsgCatalog *FindCatalog(const wxChar *szDomain) const;
121
122 wxString m_strLocale, // this locale name
123 m_strShort; // short name for the locale
124
125 const wxChar *m_pszOldLocale; // previous locale from setlocale()
126 wxLocale *m_pOldLocale; // previous wxLocale
127
128 wxMsgCatalog *m_pMsgCat; // pointer to linked list of catalogs
129
130 bool m_bConvertEncoding;
131 };
132
133 // ----------------------------------------------------------------------------
134 // global functions
135 // ----------------------------------------------------------------------------
136
137 // get the current locale object (note that it may be NULL!)
138 extern WXDLLEXPORT wxLocale* wxGetLocale();
139
140 // get the translation of the string in the current locale
141 inline const wxMB2WXbuf wxGetTranslation(const wxChar *sz)
142 {
143 wxLocale *pLoc = wxGetLocale();
144 if (pLoc)
145 return pLoc->GetString(sz);
146 else
147 return (const wxMB2WXbuf)sz;
148 }
149
150 #else // !wxUSE_INTL
151
152 // the macros should still be defined - otherwise compilation would fail
153
154 #if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(_)
155 #define _(str) (str)
156 #endif
157
158 #define wxTRANSLATE(str) _T(str)
159
160 inline const wxChar *wxGetTranslation(const wxChar *sz) { return sz; }
161
162 #endif // wxUSE_INTL/!wxUSE_INTL
163
164 // define this one just in case it occurs somewhere (instead of preferred
165 // wxTRANSLATE) too
166 #if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(gettext_noop)
167 #define gettext_noop(str) _T(str)
168 #endif
169
170 #endif
171 // _WX_INTLH__