]>
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 | |
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; | |
a1530845 | 46 | extern WXDLLEXPORT_DATA(wxLocale *) g_pLocale; |
c801d85f KB |
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 (#### to do) &c | |
55 | // ---------------------------------------------------------------------------- | |
56 | class WXDLLEXPORT wxLocale | |
57 | { | |
58 | public: | |
59 | // ctor & dtor | |
60 | // the ctor has a side effect of changing current locale | |
a1530845 VZ |
61 | wxLocale(const char *szName, // name (for messages) |
62 | const char *szShort = NULL, // dir prefix (for msg files) | |
63 | const char *szLocale = NULL, // locale (for setlocale) | |
64 | bool bLoadDefault = TRUE); // preload wxstd.mo? | |
c801d85f KB |
65 | // restores old locale |
66 | ~wxLocale(); | |
67 | ||
68 | // returns locale name | |
69 | const char *GetLocale() const { return m_strLocale; } | |
70 | ||
71 | // add a catalog: it's searched for in standard places (current directory | |
72 | // first, system one after). It will be used for message lookup by | |
73 | // GetString(). | |
74 | // | |
75 | // Returns 'true' if it was successfully loaded | |
76 | bool AddCatalog(const char *szDomain); | |
77 | ||
78 | // check if the given catalog is loaded | |
79 | bool IsLoaded(const char *szDomain) const; | |
80 | ||
81 | // retrieve the translation for a string in all loaded domains unless | |
82 | // the szDomain parameter is specified (and then only this domain is | |
83 | // searched) | |
84 | // | |
85 | // return original string if translation is not available | |
86 | // (in this case an error message is generated the first time | |
87 | // a string is not found; use wxLogNull to suppress it) | |
88 | // | |
89 | // domains are searched in the last to first order, i.e. catalogs | |
90 | // added later override those added before. | |
91 | const char *GetString(const char *szOrigString, | |
92 | const char *szDomain = NULL) const; | |
93 | ||
94 | private: | |
95 | // find catalog by name in a linked list, return NULL if !found | |
96 | wxMsgCatalog *FindCatalog(const char *szDomain) const; | |
97 | ||
98 | wxString m_strLocale, // this locale name | |
99 | m_strShort; // short name for the locale | |
100 | ||
101 | const char *m_pszOldLocale; // previous locale from setlocale() | |
102 | wxLocale *m_pOldLocale; // previous wxLocale | |
103 | ||
104 | wxMsgCatalog *m_pMsgCat; // pointer to linked list of catalogs | |
105 | }; | |
106 | ||
9d8046f6 | 107 | // ---------------------------------------------------------------------------- |
a1530845 | 108 | // global functions |
9d8046f6 | 109 | // ---------------------------------------------------------------------------- |
a1530845 | 110 | inline WXDLLEXPORT wxLocale* wxGetLocale() { return g_pLocale; } |
9d8046f6 VZ |
111 | |
112 | // get the translation of the string in the current locale | |
a1530845 | 113 | inline WXDLLEXPORT const char *wxGetTranslation(const char *sz) |
9d8046f6 VZ |
114 | { |
115 | wxLocale *pLoc = wxGetLocale(); | |
116 | return pLoc == NULL ? sz : pLoc->GetString(sz); | |
117 | } | |
118 | ||
c801d85f KB |
119 | #endif |
120 | // __INTLH__ |