]> git.saurik.com Git - wxWidgets.git/blame - include/wx/intl.h
GTK 1.0 compilation (not tested)
[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
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
7b36d720 33 #define _(str) wxGetTranslation(_T(str))
687d7337 34#endif
c801d85f
KB
35
36// ----------------------------------------------------------------------------
37// forward decls
38// ----------------------------------------------------------------------------
39class WXDLLEXPORT wxLocale;
40class 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// ----------------------------------------------------------------------------
50class WXDLLEXPORT wxLocale
51{
52public:
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
7b36d720
OK
59 wxLocale(const wxChar *szName, // name (for messages)
60 const wxChar *szShort = (const wxChar *) NULL, // dir prefix (for msg files)
61 const wxChar *szLocale = (const wxChar *) NULL, // locale (for setlocale)
84c18814
VZ
62 bool bLoadDefault = TRUE) // preload wxstd.mo?
63 { Init(szName, szShort, szLocale, bLoadDefault); }
64 // the same as a function (returns TRUE on success)
7b36d720
OK
65 bool Init(const wxChar *szName,
66 const wxChar *szShort = (const wxChar *) NULL,
67 const wxChar *szLocale = (const wxChar *) NULL,
84c18814
VZ
68 bool bLoadDefault = TRUE);
69 // restores old locale
70 ~wxLocale();
71
72 // returns locale name
7b36d720 73 const wxChar *GetLocale() const { return m_strLocale; }
84c18814
VZ
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
7b36d720 89 bool AddCatalog(const wxChar *szDomain);
84c18814
VZ
90
91 // check if the given catalog is loaded
7b36d720 92 bool IsLoaded(const wxChar *szDomain) const;
84c18814
VZ
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.
7b36d720
OK
104 const wxMB2WXbuf GetString(const wxChar *szOrigString,
105 const wxChar *szDomain = (const wxChar *) NULL) const;
84c18814
VZ
106
107 // Returns the current short name for the locale
108 const wxString& GetName() const { return m_strShort; }
109
110private:
111 // find catalog by name in a linked list, return NULL if !found
7b36d720 112 wxMsgCatalog *FindCatalog(const wxChar *szDomain) const;
84c18814
VZ
113
114 wxString m_strLocale, // this locale name
115 m_strShort; // short name for the locale
116
7b36d720 117 const wxChar *m_pszOldLocale; // previous locale from setlocale()
84c18814
VZ
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!)
128extern WXDLLEXPORT wxLocale* wxGetLocale();
129
130// get the translation of the string in the current locale
7b36d720 131inline const wxMB2WXbuf wxGetTranslation(const wxChar *sz)
9d8046f6 132{
84c18814 133 wxLocale *pLoc = wxGetLocale();
06c545a7
OK
134 if (pLoc)
135 return pLoc->GetString(sz);
136 else
137 return (const wxMB2WXbuf)sz;
9d8046f6
VZ
138}
139
c801d85f 140#endif
84c18814 141 // _WX_INTLH__