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"
20 using lyx::support::package;
32 // This version of the Pimpl utilizes the message capability of
33 // libstdc++ that is distributed with GNU G++.
34 class Messages::Pimpl {
36 typedef std::messages<char>::catalog catalog;
38 Pimpl(string const & l)
40 loc_gl(lang_.c_str()),
41 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
43 //lyxerr << "Messages: language(" << l
44 // << ") in dir(" << dir << ")" << std::endl;
46 cat_gl = mssg_gl.open(PACKAGE, loc_gl,
47 package().locale_dir().c_str());
53 mssg_gl.close(cat_gl);
56 string const get(string const & msg) const
58 return mssg_gl.get(cat_gl, 0, 0, msg);
66 std::messages<char> const & mssg_gl;
77 # include <libintl.h> // use the header already in the system *EK*
79 # include "../intl/libintl.h"
82 // This is a more traditional variant.
83 class Messages::Pimpl {
85 Pimpl(string const & l)
88 //lyxerr << "Messages: language(" << l
89 // << ") in dir(" << dir << ")" << std::endl;
95 docstring const get(string const & m) const
100 char * o = setlocale(LC_ALL, 0);
104 char * n = setlocale(LC_ALL, lang_.c_str());
106 // If we are unable to honour the request we just
107 // return what we got in.
108 return from_ascii(m);
110 char const * c = bindtextdomain(PACKAGE, package().locale_dir().c_str());
114 << BOOST_CURRENT_FUNCTION << '\n'
115 << "Error code: " << errno << '\n'
116 << "Lang, mess: " << lang_ << " " << m << '\n'
117 << "Directory : " << package().locale_dir() << '\n'
118 << "Rtn value : " << c << endl;
121 #ifdef WORDS_BIGENDIAN
122 static const char * codeset = "UCS-4BE";
124 static const char * codeset = "UCS-4LE";
126 if (!bind_textdomain_codeset(PACKAGE, codeset)) {
128 << BOOST_CURRENT_FUNCTION << '\n'
129 << "Error code: " << errno << '\n'
130 << "Codeset : " << codeset << '\n'
136 char const * tmp = m.c_str();
137 char const * msg = gettext(tmp);
138 docstring translated;
140 lyxerr << "Undefined result from gettext" << endl;
141 translated = from_ascii(tmp);
142 } else if (msg == tmp) {
143 //lyxerr << "Same as entered returned" << endl;
144 translated = from_ascii(tmp);
146 lyxerr[Debug::DEBUG] << "We got a translation" << endl;
147 char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
150 setlocale(LC_ALL, old.c_str());
160 // This is the dummy variant.
161 class Messages::Pimpl {
163 Pimpl(string const &) {}
167 docstring const get(string const & m) const
176 : pimpl_(new Pimpl(""))
180 Messages::Messages(string const & l)
181 : pimpl_(new Pimpl(l))
185 // We need this for the sake of scoped_ptr
186 Messages::~Messages()
190 docstring const Messages::get(string const & msg) const
192 return pimpl_->get(msg);