]> git.saurik.com Git - wxWidgets.git/blob - include/wx/intl.h
1) some size_t replaced with uint - does it now compile under Alpha??
[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 // simple types
28 // ----------------------------------------------------------------------------
29
30 // # adjust if necessary
31 typedef unsigned char uint8;
32 typedef unsigned long uint32;
33
34 // ----------------------------------------------------------------------------
35 // macros
36 // ----------------------------------------------------------------------------
37
38 // gettext() style macro
39 #define _(str) wxGetTranslation(str)
40
41 // ----------------------------------------------------------------------------
42 // forward decls
43 // ----------------------------------------------------------------------------
44 class WXDLLEXPORT wxLocale;
45 class WXDLLEXPORT wxMsgCatalog;
46
47 // ----------------------------------------------------------------------------
48 // global functions
49 // ----------------------------------------------------------------------------
50 extern wxLocale* WXDLLEXPORT wxGetLocale();
51 inline const char* wxGetTranslation(const char *sz);
52
53 // ============================================================================
54 // locale support
55 // ============================================================================
56
57 // ----------------------------------------------------------------------------
58 // wxLocale: encapsulates all language dependent settings, including current
59 // message catalogs, date, time and currency formats (#### to do) &c
60 // ----------------------------------------------------------------------------
61 class WXDLLEXPORT wxLocale
62 {
63 public:
64 // ctor & dtor
65 // the ctor has a side effect of changing current locale
66 wxLocale(const char *szName, // name (for messages)
67 const char *szShort = NULL, // dir prefix (for msg files)
68 const char *szLocale = NULL, // locale (for setlocale)
69 bool bLoadDefault = TRUE); // preload wxstd.mo?
70 // restores old locale
71 ~wxLocale();
72
73 // returns locale name
74 const char *GetLocale() const { return m_strLocale; }
75
76 // add a catalog: it's searched for in standard places (current directory
77 // first, system one after). It will be used for message lookup by
78 // GetString().
79 //
80 // Returns 'true' if it was successfully loaded
81 bool AddCatalog(const char *szDomain);
82
83 // check if the given catalog is loaded
84 bool IsLoaded(const char *szDomain) const;
85
86 // retrieve the translation for a string in all loaded domains unless
87 // the szDomain parameter is specified (and then only this domain is
88 // searched)
89 //
90 // return original string if translation is not available
91 // (in this case an error message is generated the first time
92 // a string is not found; use wxLogNull to suppress it)
93 //
94 // domains are searched in the last to first order, i.e. catalogs
95 // added later override those added before.
96 const char *GetString(const char *szOrigString,
97 const char *szDomain = NULL) const;
98
99 private:
100 // find catalog by name in a linked list, return NULL if !found
101 wxMsgCatalog *FindCatalog(const char *szDomain) const;
102
103 wxString m_strLocale, // this locale name
104 m_strShort; // short name for the locale
105
106 const char *m_pszOldLocale; // previous locale from setlocale()
107 wxLocale *m_pOldLocale; // previous wxLocale
108
109 wxMsgCatalog *m_pMsgCat; // pointer to linked list of catalogs
110 };
111
112 // ----------------------------------------------------------------------------
113 // inline functions
114 // ----------------------------------------------------------------------------
115
116 // get the translation of the string in the current locale
117 inline const char *wxGetTranslation(const char *sz)
118 {
119 wxLocale *pLoc = wxGetLocale();
120 return pLoc == NULL ? sz : pLoc->GetString(sz);
121 }
122
123 // ============================================================================
124 // optional features
125 // ============================================================================
126
127 // ----------------------------------------------------------------------------
128 // wxTString: automatically translates strings to current language
129 // ----------------------------------------------------------------------------
130
131 // this feature should be enabled by defining WX_USE_AUTOTRANS, if it's not
132 // done no automatic translation is performed
133 #if USE_AUTOTRANS
134 class WXDLLEXPORT wxTString
135 {
136 public:
137 // NB: different ctors do different things!
138 // does translation
139 wxTString(const char *sz) : m_pcsz(wxGetTranslation(sz)) { }
140 // no translation
141 wxTString(const wxString& s) : m_pcsz(s) { }
142
143 // NB: no copy ctor, it must be a POD so that we can pass it
144 // to vararg functions (and it's not needed anyhow)
145
146 // implicit conversion
147 operator const char *() const { return m_pcsz; }
148
149 private:
150 const char *m_pcsz;
151 };
152 #else //!USE_AUTOTRANS
153 #define wxTString wxString
154 #endif //USE_AUTOTRANS
155
156 #define TRANSSTRING_DEFINED
157
158 #endif
159 // __INTLH__