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