2 * This file is part of LyX, the document processor.
3 * Licence details can be found in the file COPYING.
5 * \author Lars Gullik Bjønnes
7 * Full author contact details are available in file CREDITS.
13 #include "support/filetools.h"
14 #include "support/package.h"
16 using lyx::support::package;
27 // This version of the Pimpl utilizes the message capability of
28 // libstdc++ that is distributed with GNU G++.
29 class Messages::Pimpl {
31 typedef std::messages<char>::catalog catalog;
33 Pimpl(string const & l)
35 loc_gl(lang_.c_str()),
36 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
38 //lyxerr << "Messages: language(" << l
39 // << ") in dir(" << dir << ")" << std::endl;
41 cat_gl = mssg_gl.open(PACKAGE, loc_gl,
42 package().locale_dir().c_str());
48 mssg_gl.close(cat_gl);
51 string const get(string const & msg) const
53 return mssg_gl.get(cat_gl, 0, 0, msg);
61 std::messages<char> const & mssg_gl;
72 # include <libintl.h> // use the header already in the system *EK*
74 # include "../intl/libintl.h"
77 // This is a more traditional variant.
78 class Messages::Pimpl {
80 Pimpl(string const & l)
83 //lyxerr << "Messages: language(" << l
84 // << ") in dir(" << dir << ")" << std::endl;
90 string const get(string const & m) const
95 char * old = strdup(setlocale(LC_ALL, 0));
96 char * n = setlocale(LC_ALL, lang_.c_str());
97 bindtextdomain(PACKAGE, package().locale_dir().c_str());
99 const char* msg = gettext(m.c_str());
100 setlocale(LC_ALL, old);
102 // If we are unable to honour the request we just
103 // return what we got in.
104 return (!n ? m : string(msg));
113 // This is the dummy variant.
114 class Messages::Pimpl {
116 Pimpl(string const &) {}
120 string const get(string const & m) const
129 : pimpl_(new Pimpl(""))
133 Messages::Messages(string const & l)
134 : pimpl_(new Pimpl(l))
138 // We need this for the sake of scoped_ptr
139 Messages::~Messages()
143 string const Messages::get(string const & msg) const
145 return pimpl_->get(msg);