]>
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> | |
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 | |
c86f1403 VZ |
31 | typedef unsigned char size_t8; |
32 | typedef unsigned long size_t32; | |
c801d85f KB |
33 | |
34 | // ---------------------------------------------------------------------------- | |
35 | // macros | |
36 | // ---------------------------------------------------------------------------- | |
37 | ||
38 | // gettext() style macro | |
687d7337 | 39 | #ifndef WXINTL_NO_GETTEXT_MACRO |
c801d85f | 40 | #define _(str) wxGetTranslation(str) |
687d7337 | 41 | #endif |
c801d85f KB |
42 | |
43 | // ---------------------------------------------------------------------------- | |
44 | // forward decls | |
45 | // ---------------------------------------------------------------------------- | |
46 | class WXDLLEXPORT wxLocale; | |
47 | class WXDLLEXPORT wxMsgCatalog; | |
a1530845 | 48 | extern WXDLLEXPORT_DATA(wxLocale *) g_pLocale; |
c801d85f KB |
49 | |
50 | // ============================================================================ | |
51 | // locale support | |
52 | // ============================================================================ | |
53 | ||
54 | // ---------------------------------------------------------------------------- | |
55 | // wxLocale: encapsulates all language dependent settings, including current | |
56 | // message catalogs, date, time and currency formats (#### to do) &c | |
57 | // ---------------------------------------------------------------------------- | |
58 | class WXDLLEXPORT wxLocale | |
59 | { | |
60 | public: | |
61 | // ctor & dtor | |
23fcecf7 VZ |
62 | // call Init() if you use this ctor |
63 | wxLocale(); | |
c801d85f | 64 | // the ctor has a side effect of changing current locale |
a1530845 | 65 | wxLocale(const char *szName, // name (for messages) |
c67daf87 UR |
66 | const char *szShort = (const char *) NULL, // dir prefix (for msg files) |
67 | const char *szLocale = (const char *) NULL, // locale (for setlocale) | |
23fcecf7 VZ |
68 | bool bLoadDefault = TRUE) // preload wxstd.mo? |
69 | { Init(szName, szShort, szLocale, bLoadDefault); } | |
70 | // the same as a function (returns TRUE on success) | |
71 | bool Init(const char *szName, | |
c67daf87 UR |
72 | const char *szShort = (const char *) NULL, |
73 | const char *szLocale = (const char *) NULL, | |
23fcecf7 | 74 | bool bLoadDefault = TRUE); |
c801d85f KB |
75 | // restores old locale |
76 | ~wxLocale(); | |
77 | ||
78 | // returns locale name | |
79 | const char *GetLocale() const { return m_strLocale; } | |
80 | ||
fd323a5e VZ |
81 | // add a prefix to the catalog lookup path: the message catalog files will be |
82 | // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix | |
83 | // (in this order). | |
84 | // | |
85 | // This only applies to subsequent invocations of AddCatalog()! | |
86 | static void AddCatalogLookupPathPrefix(const wxString& prefix); | |
87 | ||
c801d85f | 88 | // add a catalog: it's searched for in standard places (current directory |
fd323a5e VZ |
89 | // first, system one after), but the you may prepend additional directories to |
90 | // the search path with AddCatalogLookupPathPrefix(). | |
91 | // | |
92 | // The loaded catalog will be used for message lookup by GetString(). | |
c801d85f KB |
93 | // |
94 | // Returns 'true' if it was successfully loaded | |
95 | bool AddCatalog(const char *szDomain); | |
96 | ||
97 | // check if the given catalog is loaded | |
98 | bool IsLoaded(const char *szDomain) const; | |
99 | ||
100 | // retrieve the translation for a string in all loaded domains unless | |
101 | // the szDomain parameter is specified (and then only this domain is | |
102 | // searched) | |
103 | // | |
104 | // return original string if translation is not available | |
105 | // (in this case an error message is generated the first time | |
106 | // a string is not found; use wxLogNull to suppress it) | |
107 | // | |
108 | // domains are searched in the last to first order, i.e. catalogs | |
109 | // added later override those added before. | |
110 | const char *GetString(const char *szOrigString, | |
c67daf87 | 111 | const char *szDomain = (const char *) NULL) const; |
c801d85f | 112 | |
afcaf277 KB |
113 | // Returns the current short name for the locale |
114 | wxString const &GetName() const { return m_strShort; } | |
115 | private: | |
c801d85f KB |
116 | // find catalog by name in a linked list, return NULL if !found |
117 | wxMsgCatalog *FindCatalog(const char *szDomain) const; | |
118 | ||
119 | wxString m_strLocale, // this locale name | |
120 | m_strShort; // short name for the locale | |
121 | ||
122 | const char *m_pszOldLocale; // previous locale from setlocale() | |
123 | wxLocale *m_pOldLocale; // previous wxLocale | |
124 | ||
125 | wxMsgCatalog *m_pMsgCat; // pointer to linked list of catalogs | |
126 | }; | |
127 | ||
9d8046f6 | 128 | // ---------------------------------------------------------------------------- |
a1530845 | 129 | // global functions |
9d8046f6 | 130 | // ---------------------------------------------------------------------------- |
184b5d99 | 131 | WXDLLEXPORT wxLocale* wxGetLocale(); |
9d8046f6 VZ |
132 | |
133 | // get the translation of the string in the current locale | |
184b5d99 | 134 | inline const char *wxGetTranslation(const char *sz) |
9d8046f6 VZ |
135 | { |
136 | wxLocale *pLoc = wxGetLocale(); | |
c67daf87 | 137 | return pLoc == (wxLocale *) NULL ? sz : pLoc->GetString(sz); |
9d8046f6 VZ |
138 | } |
139 | ||
c801d85f | 140 | #endif |
34138703 | 141 | // _WX_INTLH__ |