1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: intl.h
|
|
|
|
// Purpose: Internationalization and localisation for wxWindows
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 29/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
1999-02-15 18:09:33 -05:00
|
|
|
// Licence: wxWindows license
|
1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef __INTLH__
|
|
|
|
#define __INTLH__
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
1999-02-15 18:09:33 -05:00
|
|
|
#pragma interface "intl.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
#include "wx/string.h"
|
|
|
|
|
1999-06-01 11:32:12 -04:00
|
|
|
#if wxUSE_INTL
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// ============================================================================
|
|
|
|
// global decls
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// macros
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1999-02-15 18:09:33 -05:00
|
|
|
// gettext() style macro (notice that xgettext should be invoked with "-k_"
|
|
|
|
// option to extract the strings inside _() from the sources)
|
1999-01-09 13:00:30 -05:00
|
|
|
#ifndef WXINTL_NO_GETTEXT_MACRO
|
1999-12-22 16:09:32 -05:00
|
|
|
#define _(str) wxGetTranslation(_T(str))
|
1999-01-09 13:00:30 -05:00
|
|
|
#endif
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-11-04 15:40:41 -05:00
|
|
|
// another one which just marks the strings for extraction, but doesn't
|
|
|
|
// perform the translation (use -kwxTRANSLATE with xgettext!)
|
1999-12-22 16:09:32 -05:00
|
|
|
#define wxTRANSLATE(str) _T(str)
|
1999-11-04 15:40:41 -05:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// forward decls
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
class WXDLLEXPORT wxLocale;
|
|
|
|
class WXDLLEXPORT wxMsgCatalog;
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// locale support
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxLocale: encapsulates all language dependent settings, including current
|
1999-02-15 18:09:33 -05:00
|
|
|
// message catalogs, date, time and currency formats (TODO) &c
|
1998-05-20 10:01:55 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
class WXDLLEXPORT wxLocale
|
|
|
|
{
|
|
|
|
public:
|
1999-02-15 18:09:33 -05:00
|
|
|
// ctor & dtor
|
|
|
|
// -----------
|
|
|
|
|
|
|
|
// call Init() if you use this ctor
|
|
|
|
wxLocale();
|
|
|
|
// the ctor has a side effect of changing current locale
|
1999-04-12 17:58:42 -04:00
|
|
|
wxLocale(const wxChar *szName, // name (for messages)
|
|
|
|
const wxChar *szShort = (const wxChar *) NULL, // dir prefix (for msg files)
|
|
|
|
const wxChar *szLocale = (const wxChar *) NULL, // locale (for setlocale)
|
1999-02-15 18:09:33 -05:00
|
|
|
bool bLoadDefault = TRUE) // preload wxstd.mo?
|
|
|
|
{ Init(szName, szShort, szLocale, bLoadDefault); }
|
|
|
|
// the same as a function (returns TRUE on success)
|
1999-04-12 17:58:42 -04:00
|
|
|
bool Init(const wxChar *szName,
|
|
|
|
const wxChar *szShort = (const wxChar *) NULL,
|
|
|
|
const wxChar *szLocale = (const wxChar *) NULL,
|
1999-02-15 18:09:33 -05:00
|
|
|
bool bLoadDefault = TRUE);
|
|
|
|
// restores old locale
|
|
|
|
~wxLocale();
|
|
|
|
|
|
|
|
// returns locale name
|
1999-04-12 17:58:42 -04:00
|
|
|
const wxChar *GetLocale() const { return m_strLocale; }
|
1999-02-15 18:09:33 -05:00
|
|
|
|
|
|
|
// add a prefix to the catalog lookup path: the message catalog files will be
|
|
|
|
// looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
|
|
|
|
// (in this order).
|
|
|
|
//
|
|
|
|
// This only applies to subsequent invocations of AddCatalog()!
|
|
|
|
static void AddCatalogLookupPathPrefix(const wxString& prefix);
|
|
|
|
|
|
|
|
// add a catalog: it's searched for in standard places (current directory
|
|
|
|
// first, system one after), but the you may prepend additional directories to
|
|
|
|
// the search path with AddCatalogLookupPathPrefix().
|
|
|
|
//
|
|
|
|
// The loaded catalog will be used for message lookup by GetString().
|
|
|
|
//
|
|
|
|
// Returns 'true' if it was successfully loaded
|
1999-04-12 17:58:42 -04:00
|
|
|
bool AddCatalog(const wxChar *szDomain);
|
1999-02-15 18:09:33 -05:00
|
|
|
|
|
|
|
// check if the given catalog is loaded
|
1999-04-12 17:58:42 -04:00
|
|
|
bool IsLoaded(const wxChar *szDomain) const;
|
1999-02-15 18:09:33 -05:00
|
|
|
|
|
|
|
// retrieve the translation for a string in all loaded domains unless
|
|
|
|
// the szDomain parameter is specified (and then only this domain is
|
|
|
|
// searched)
|
|
|
|
//
|
|
|
|
// return original string if translation is not available
|
|
|
|
// (in this case an error message is generated the first time
|
|
|
|
// a string is not found; use wxLogNull to suppress it)
|
|
|
|
//
|
|
|
|
// domains are searched in the last to first order, i.e. catalogs
|
|
|
|
// added later override those added before.
|
1999-04-12 17:58:42 -04:00
|
|
|
const wxMB2WXbuf GetString(const wxChar *szOrigString,
|
|
|
|
const wxChar *szDomain = (const wxChar *) NULL) const;
|
1999-02-15 18:09:33 -05:00
|
|
|
|
|
|
|
// Returns the current short name for the locale
|
|
|
|
const wxString& GetName() const { return m_strShort; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// find catalog by name in a linked list, return NULL if !found
|
1999-04-12 17:58:42 -04:00
|
|
|
wxMsgCatalog *FindCatalog(const wxChar *szDomain) const;
|
1999-02-15 18:09:33 -05:00
|
|
|
|
|
|
|
wxString m_strLocale, // this locale name
|
|
|
|
m_strShort; // short name for the locale
|
|
|
|
|
1999-04-12 17:58:42 -04:00
|
|
|
const wxChar *m_pszOldLocale; // previous locale from setlocale()
|
1999-02-15 18:09:33 -05:00
|
|
|
wxLocale *m_pOldLocale; // previous wxLocale
|
|
|
|
|
|
|
|
wxMsgCatalog *m_pMsgCat; // pointer to linked list of catalogs
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
1998-05-26 11:08:50 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
1998-07-17 16:52:40 -04:00
|
|
|
// global functions
|
1998-05-26 11:08:50 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1999-02-15 18:09:33 -05:00
|
|
|
// get the current locale object (note that it may be NULL!)
|
|
|
|
extern WXDLLEXPORT wxLocale* wxGetLocale();
|
|
|
|
|
|
|
|
// get the translation of the string in the current locale
|
1999-04-12 17:58:42 -04:00
|
|
|
inline const wxMB2WXbuf wxGetTranslation(const wxChar *sz)
|
1998-05-26 11:08:50 -04:00
|
|
|
{
|
1999-02-15 18:09:33 -05:00
|
|
|
wxLocale *pLoc = wxGetLocale();
|
1999-04-19 13:48:28 -04:00
|
|
|
if (pLoc)
|
|
|
|
return pLoc->GetString(sz);
|
|
|
|
else
|
|
|
|
return (const wxMB2WXbuf)sz;
|
1998-05-26 11:08:50 -04:00
|
|
|
}
|
|
|
|
|
1999-06-01 11:32:12 -04:00
|
|
|
#else // !wxUSE_INTL
|
|
|
|
|
1999-12-22 16:09:32 -05:00
|
|
|
// the macros should still be defined - otherwise compilation would fail
|
|
|
|
|
|
|
|
#if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(_)
|
1999-06-01 11:32:12 -04:00
|
|
|
#define _(str) (str)
|
|
|
|
#endif
|
|
|
|
|
1999-12-22 16:09:32 -05:00
|
|
|
#define wxTRANSLATE(str) _T(str)
|
|
|
|
|
1999-06-01 11:32:12 -04:00
|
|
|
inline const wxChar *wxGetTranslation(const wxChar *sz) { return sz; }
|
|
|
|
|
|
|
|
#endif // wxUSE_INTL/!wxUSE_INTL
|
|
|
|
|
1999-12-22 16:09:32 -05:00
|
|
|
// define this one just in case it occurs somewhere (instead of preferred
|
|
|
|
// wxTRANSLATE) too
|
|
|
|
#if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(gettext_noop)
|
|
|
|
#define gettext_noop(str) _T(str)
|
|
|
|
#endif
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
1999-02-15 18:09:33 -05:00
|
|
|
// _WX_INTLH__
|