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