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.
14 #include "support/filetools.h"
15 #include "support/package.h"
17 #include <boost/current_function.hpp>
24 using lyx::support::package;
36 // This version of the Pimpl utilizes the message capability of
37 // libstdc++ that is distributed with GNU G++.
38 class Messages::Pimpl {
40 typedef std::messages<char>::catalog catalog;
42 Pimpl(string const & l)
44 loc_gl(lang_.c_str()),
45 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
47 //lyxerr << "Messages: language(" << l
48 // << ") in dir(" << dir << ")" << std::endl;
50 cat_gl = mssg_gl.open(PACKAGE, loc_gl,
51 package().locale_dir().c_str());
57 mssg_gl.close(cat_gl);
60 string const get(string const & msg) const
62 return mssg_gl.get(cat_gl, 0, 0, msg);
70 std::messages<char> const & mssg_gl;
81 # include <libintl.h> // use the header already in the system *EK*
83 # include "../intl/libintl.h"
86 // This is a more traditional variant.
87 class Messages::Pimpl {
89 Pimpl(string const & l)
92 //lyxerr << "Messages: language(" << l
93 // << ") in dir(" << dir << ")" << std::endl;
99 docstring const get(string const & m) const
102 return from_ascii(m);
104 char * o = setlocale(LC_ALL, 0);
108 char * n = setlocale(LC_ALL, lang_.c_str());
110 // If we are unable to honour the request we just
111 // return what we got in.
112 return from_ascii(m);
114 char const * c = bindtextdomain(PACKAGE, package().locale_dir().c_str());
118 << BOOST_CURRENT_FUNCTION << '\n'
119 << "Error code: " << errno << '\n'
120 << "Lang, mess: " << lang_ << " " << m << '\n'
121 << "Directory : " << package().locale_dir() << '\n'
122 << "Rtn value : " << c << endl;
125 #ifdef WORDS_BIGENDIAN
126 static const char * codeset = "UCS-4BE";
128 static const char * codeset = "UCS-4LE";
130 if (!bind_textdomain_codeset(PACKAGE, codeset)) {
132 << BOOST_CURRENT_FUNCTION << '\n'
133 << "Error code: " << errno << '\n'
134 << "Codeset : " << codeset << '\n'
140 char const * tmp = m.c_str();
141 char const * msg = gettext(tmp);
142 docstring translated;
144 lyxerr << "Undefined result from gettext" << endl;
145 translated = from_ascii(tmp);
146 } else if (msg == tmp) {
147 //lyxerr << "Same as entered returned" << endl;
148 translated = from_ascii(tmp);
150 lyxerr[Debug::DEBUG] << "We got a translation" << endl;
151 char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
154 setlocale(LC_ALL, old.c_str());
164 // This is the dummy variant.
165 class Messages::Pimpl {
167 Pimpl(string const &) {}
171 docstring const get(string const & m) const
173 return from_ascii(m);
180 : pimpl_(new Pimpl(""))
184 Messages::Messages(string const & l)
185 : pimpl_(new Pimpl(l))
189 // We need this for the sake of scoped_ptr
190 Messages::~Messages()
194 docstring const Messages::get(string const & msg) const
196 return pimpl_->get(msg);