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"
19 using lyx::support::package;
30 // This version of the Pimpl utilizes the message capability of
31 // libstdc++ that is distributed with GNU G++.
32 class Messages::Pimpl {
34 typedef std::messages<char>::catalog catalog;
36 Pimpl(string const & l)
38 loc_gl(lang_.c_str()),
39 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
41 //lyxerr << "Messages: language(" << l
42 // << ") in dir(" << dir << ")" << std::endl;
44 cat_gl = mssg_gl.open(PACKAGE, loc_gl,
45 package().locale_dir().c_str());
51 mssg_gl.close(cat_gl);
54 string const get(string const & msg) const
56 return mssg_gl.get(cat_gl, 0, 0, msg);
64 std::messages<char> const & mssg_gl;
75 # include <libintl.h> // use the header already in the system *EK*
77 # include "../intl/libintl.h"
80 // This is a more traditional variant.
81 class Messages::Pimpl {
83 Pimpl(string const & l)
86 //lyxerr << "Messages: language(" << l
87 // << ") in dir(" << dir << ")" << std::endl;
93 string const get(string const & m) const
98 char * old = strdup(setlocale(LC_ALL, 0));
99 char * n = setlocale(LC_ALL, lang_.c_str());
100 bindtextdomain(PACKAGE, package().locale_dir().c_str());
102 const char* msg = gettext(m.c_str());
103 setlocale(LC_ALL, old);
105 // If we are unable to honour the request we just
106 // return what we got in.
107 return (!n ? m : string(msg));
116 // This is the dummy variant.
117 class Messages::Pimpl {
119 Pimpl(string const &) {}
123 string const get(string const & m) const
132 : pimpl_(new Pimpl(""))
136 Messages::Messages(string const & l)
137 : pimpl_(new Pimpl(l))
141 // We need this for the sake of scoped_ptr
142 Messages::~Messages()
146 string const Messages::get(string const & msg) const
148 return pimpl_->get(msg);