2003-04-23 20:44:53 +00:00
|
|
|
|
/* \file messages.C
|
2003-04-23 18:47:21 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-04-23 18:47:21 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "messages.h"
|
|
|
|
|
#include "debug.h"
|
2003-04-27 22:11:45 +00:00
|
|
|
|
#include "support/filetools.h"
|
2003-07-28 11:43:40 +00:00
|
|
|
|
#include "support/path_defines.h"
|
2003-04-23 18:47:21 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
using namespace lyx::support;
|
|
|
|
|
|
2003-04-23 18:47:21 +00:00
|
|
|
|
|
2003-04-24 22:09:46 +00:00
|
|
|
|
#ifdef ENABLE_NLS
|
2003-04-23 18:47:21 +00:00
|
|
|
|
|
2003-04-27 22:11:45 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
string const & getLocaleDir()
|
|
|
|
|
{
|
|
|
|
|
static string locale_dir;
|
|
|
|
|
|
|
|
|
|
if (locale_dir.empty()) {
|
|
|
|
|
locale_dir = GetEnvPath("LYX_LOCALEDIR");
|
|
|
|
|
if (locale_dir.empty())
|
2003-07-28 11:43:40 +00:00
|
|
|
|
locale_dir = lyx_localedir();
|
2003-04-27 22:11:45 +00:00
|
|
|
|
}
|
|
|
|
|
return locale_dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
|
2003-04-24 22:09:46 +00:00
|
|
|
|
#if 0
|
2003-04-23 18:47:21 +00:00
|
|
|
|
|
2003-04-24 22:09:46 +00:00
|
|
|
|
#include <locale>
|
|
|
|
|
|
|
|
|
|
// This version of the Pimpl utilizes the message capability of
|
2003-04-28 01:52:18 +00:00
|
|
|
|
// libstdc++ that is distributed with GNU G++.
|
2003-04-24 22:09:46 +00:00
|
|
|
|
class Messages::Pimpl {
|
|
|
|
|
public:
|
|
|
|
|
typedef std::messages<char>::catalog catalog;
|
|
|
|
|
|
2003-04-27 22:11:45 +00:00
|
|
|
|
Pimpl(string const & l)
|
|
|
|
|
: lang_(l),
|
2003-04-24 22:09:46 +00:00
|
|
|
|
loc_gl(lang_.c_str()),
|
|
|
|
|
mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
|
|
|
|
|
{
|
|
|
|
|
//lyxerr << "Messages: language(" << l
|
|
|
|
|
// << ") in dir(" << dir << ")" << std::endl;
|
|
|
|
|
|
2003-04-27 22:11:45 +00:00
|
|
|
|
cat_gl = mssg_gl.open(PACKAGE, loc_gl, getLocaleDir().c_str());
|
2003-04-24 22:09:46 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~Pimpl()
|
|
|
|
|
{
|
|
|
|
|
mssg_gl.close(cat_gl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string const get(string const & msg) const
|
|
|
|
|
{
|
|
|
|
|
return mssg_gl.get(cat_gl, 0, 0, msg);
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
///
|
|
|
|
|
string lang_;
|
|
|
|
|
///
|
|
|
|
|
std::locale loc_gl;
|
|
|
|
|
///
|
|
|
|
|
std::messages<char> const & mssg_gl;
|
|
|
|
|
///
|
|
|
|
|
catalog cat_gl;
|
|
|
|
|
};
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
|
# include <locale.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# if HAVE_GETTEXT
|
|
|
|
|
# include <libintl.h> // use the header already in the system *EK*
|
|
|
|
|
# else
|
|
|
|
|
# include "../intl/libintl.h"
|
|
|
|
|
# endif
|
2003-04-23 18:47:21 +00:00
|
|
|
|
|
2003-04-24 22:09:46 +00:00
|
|
|
|
// This is a more traditional variant.
|
|
|
|
|
class Messages::Pimpl {
|
|
|
|
|
public:
|
2003-04-27 22:11:45 +00:00
|
|
|
|
Pimpl(string const & l)
|
|
|
|
|
: lang_(l)
|
2003-04-24 22:09:46 +00:00
|
|
|
|
{
|
|
|
|
|
//lyxerr << "Messages: language(" << l
|
|
|
|
|
// << ") in dir(" << dir << ")" << std::endl;
|
2003-04-23 18:47:21 +00:00
|
|
|
|
|
2003-04-27 22:11:45 +00:00
|
|
|
|
bindtextdomain(PACKAGE, getLocaleDir().c_str());
|
2003-04-24 22:09:46 +00:00
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~Pimpl() {}
|
|
|
|
|
|
|
|
|
|
string const get(string const & m) const
|
|
|
|
|
{
|
2003-06-10 14:39:45 +00:00
|
|
|
|
if (m.empty())
|
|
|
|
|
return m;
|
|
|
|
|
|
2003-04-24 22:09:46 +00:00
|
|
|
|
char * old = strdup(setlocale(LC_ALL, 0));
|
2003-04-25 01:54:04 +00:00
|
|
|
|
char * n = setlocale(LC_ALL, lang_.c_str());
|
2003-04-24 22:09:46 +00:00
|
|
|
|
const char* msg = gettext(m.c_str());
|
|
|
|
|
setlocale(LC_ALL, old);
|
|
|
|
|
free(old);
|
2003-04-25 01:54:04 +00:00
|
|
|
|
// If we are unable to honour the request we just
|
|
|
|
|
// return what we got in.
|
|
|
|
|
return (!n ? m : string(msg));
|
2003-04-24 22:09:46 +00:00
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
///
|
|
|
|
|
string lang_;
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#else // ENABLE_NLS
|
|
|
|
|
// This is the dummy variant.
|
|
|
|
|
class Messages::Pimpl {
|
|
|
|
|
public:
|
2003-04-27 22:11:45 +00:00
|
|
|
|
Pimpl(string const &) {}
|
2003-04-24 22:09:46 +00:00
|
|
|
|
|
|
|
|
|
~Pimpl() {}
|
|
|
|
|
|
|
|
|
|
string const get(string const & m) const
|
|
|
|
|
{
|
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-04-27 22:11:45 +00:00
|
|
|
|
|
|
|
|
|
Messages::Messages()
|
|
|
|
|
: pimpl_(new Pimpl(""))
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Messages::Messages(string const & l)
|
|
|
|
|
: pimpl_(new Pimpl(l))
|
2003-04-24 22:09:46 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-04-24 23:46:40 +00:00
|
|
|
|
// We need this for the sake of scoped_ptr
|
2003-04-23 18:47:21 +00:00
|
|
|
|
Messages::~Messages()
|
2003-04-24 22:09:46 +00:00
|
|
|
|
{}
|
2003-04-23 18:47:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const Messages::get(string const & msg) const
|
|
|
|
|
{
|
2003-04-24 22:09:46 +00:00
|
|
|
|
return pimpl_->get(msg);
|
2003-04-23 18:47:21 +00:00
|
|
|
|
}
|