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"
|
2003-04-27 22:11:45 +00:00
|
|
|
|
#include "support/filetools.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
|
#include "support/package.h"
|
2003-04-23 18:47:21 +00:00
|
|
|
|
|
2004-10-19 09:11:02 +00:00
|
|
|
|
#include <boost/regex.hpp>
|
|
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
|
using lyx::support::package;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
|
|
|
|
|
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
|
|
|
|
|
2003-04-24 22:09:46 +00:00
|
|
|
|
#if 0
|
2003-04-23 18:47:21 +00:00
|
|
|
|
|
2003-09-05 16:31:30 +00:00
|
|
|
|
-#include <locale>
|
2003-04-24 22:09:46 +00:00
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
|
cat_gl = mssg_gl.open(PACKAGE, loc_gl, package().locale_dir().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-24 22:09:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~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());
|
2005-01-10 19:17:43 +00:00
|
|
|
|
bindtextdomain(PACKAGE, package().locale_dir().c_str());
|
2004-06-08 14:06:11 +00:00
|
|
|
|
textdomain(PACKAGE);
|
2003-04-24 22:09:46 +00:00
|
|
|
|
const char* msg = gettext(m.c_str());
|
2004-10-19 09:11:02 +00:00
|
|
|
|
// Some english words have different translations, depending
|
|
|
|
|
// on context. In these cases the original string is
|
|
|
|
|
// augmented by context information (e.g.
|
|
|
|
|
// "To:[[as in 'From page x to page y']]" and
|
|
|
|
|
// "To:[[as in 'From format x to format y']]".
|
|
|
|
|
// This means that we need to filter out everything in
|
|
|
|
|
// double square brackets at the end of the string,
|
|
|
|
|
// otherwise the user sees bogus messages.
|
2003-04-25 01:54:04 +00:00
|
|
|
|
// If we are unable to honour the request we just
|
|
|
|
|
// return what we got in.
|
2004-10-19 09:11:02 +00:00
|
|
|
|
string translated(n ? msg : m);
|
|
|
|
|
static boost::regex const reg("^([^\\[]*)\\[\\[[^\\]]*\\]\\]$");
|
|
|
|
|
boost::smatch sub;
|
|
|
|
|
if (regex_match(translated, sub, reg))
|
|
|
|
|
translated = sub.str(1);
|
|
|
|
|
setlocale(LC_ALL, old);
|
|
|
|
|
free(old);
|
|
|
|
|
return translated;
|
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
|
|
|
|
}
|