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