]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/intl.h
34072e0dbdbe5f53f7c9a9f50a8d2398df9083e6
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Internationalization and localisation for wxWindows
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "intl.h"
20 #include "wx/string.h"
24 // ============================================================================
26 // ============================================================================
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 // gettext() style macro (notice that xgettext should be invoked with "-k_"
33 // option to extract the strings inside _() from the sources)
34 #ifndef WXINTL_NO_GETTEXT_MACRO
35 #define _(str) wxGetTranslation(wxT(str))
38 // another one which just marks the strings for extraction, but doesn't
39 // perform the translation (use -kwxTRANSLATE with xgettext!)
40 #define wxTRANSLATE(str) (str)
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
45 class WXDLLEXPORT wxLocale
;
46 class WXDLLEXPORT wxMsgCatalog
;
48 // ============================================================================
50 // ============================================================================
52 // ----------------------------------------------------------------------------
53 // wxLocale: encapsulates all language dependent settings, including current
54 // message catalogs, date, time and currency formats (TODO) &c
55 // ----------------------------------------------------------------------------
56 class WXDLLEXPORT wxLocale
62 // call Init() if you use this ctor
64 // the ctor has a side effect of changing current locale
65 wxLocale(const wxChar
*szName
, // name (for messages)
66 const wxChar
*szShort
= (const wxChar
*) NULL
, // dir prefix (for msg files)
67 const wxChar
*szLocale
= (const wxChar
*) NULL
, // locale (for setlocale)
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 wxChar
*szName
,
72 const wxChar
*szShort
= (const wxChar
*) NULL
,
73 const wxChar
*szLocale
= (const wxChar
*) NULL
,
74 bool bLoadDefault
= TRUE
);
75 // restores old locale
78 // returns locale name
79 const wxChar
*GetLocale() const { return m_strLocale
; }
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
85 // This only applies to subsequent invocations of AddCatalog()!
86 static void AddCatalogLookupPathPrefix(const wxString
& prefix
);
88 // add a catalog: it's searched for in standard places (current directory
89 // first, system one after), but the you may prepend additional directories to
90 // the search path with AddCatalogLookupPathPrefix().
92 // The loaded catalog will be used for message lookup by GetString().
94 // Returns 'true' if it was successfully loaded
95 bool AddCatalog(const wxChar
*szDomain
);
97 // check if the given catalog is loaded
98 bool IsLoaded(const wxChar
*szDomain
) const;
100 // retrieve the translation for a string in all loaded domains unless
101 // the szDomain parameter is specified (and then only this domain is
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)
108 // domains are searched in the last to first order, i.e. catalogs
109 // added later override those added before.
110 const wxMB2WXbuf
GetString(const wxChar
*szOrigString
,
111 const wxChar
*szDomain
= (const wxChar
*) NULL
) const;
113 // Returns the current short name for the locale
114 const wxString
& GetName() const { return m_strShort
; }
117 // find catalog by name in a linked list, return NULL if !found
118 wxMsgCatalog
*FindCatalog(const wxChar
*szDomain
) const;
120 wxString m_strLocale
, // this locale name
121 m_strShort
; // short name for the locale
123 const wxChar
*m_pszOldLocale
; // previous locale from setlocale()
124 wxLocale
*m_pOldLocale
; // previous wxLocale
126 wxMsgCatalog
*m_pMsgCat
; // pointer to linked list of catalogs
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
133 // get the current locale object (note that it may be NULL!)
134 extern WXDLLEXPORT wxLocale
* wxGetLocale();
136 // get the translation of the string in the current locale
137 inline const wxMB2WXbuf
wxGetTranslation(const wxChar
*sz
)
139 wxLocale
*pLoc
= wxGetLocale();
141 return pLoc
->GetString(sz
);
143 return (const wxMB2WXbuf
)sz
;
148 #ifndef WXINTL_NO_GETTEXT_MACRO
152 inline const wxChar
*wxGetTranslation(const wxChar
*sz
) { return sz
; }
154 #endif // wxUSE_INTL/!wxUSE_INTL