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"
22 using lyx::support::package;
34 // This version of the Pimpl utilizes the message capability of
35 // libstdc++ that is distributed with GNU G++.
36 class Messages::Pimpl {
38 typedef std::messages<char>::catalog catalog;
40 Pimpl(string const & l)
42 loc_gl(lang_.c_str()),
43 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
45 //lyxerr << "Messages: language(" << l
46 // << ") in dir(" << dir << ")" << std::endl;
48 cat_gl = mssg_gl.open(PACKAGE, loc_gl,
49 package().locale_dir().c_str());
55 mssg_gl.close(cat_gl);
58 string const get(string const & msg) const
60 return mssg_gl.get(cat_gl, 0, 0, msg);
68 std::messages<char> const & mssg_gl;
79 # include <libintl.h> // use the header already in the system *EK*
81 # include "../intl/libintl.h"
84 // This is a more traditional variant.
85 class Messages::Pimpl {
87 Pimpl(string const & l)
90 //lyxerr << "Messages: language(" << l
91 // << ") in dir(" << dir << ")" << std::endl;
97 docstring const get(string const & m) const
100 return from_ascii(m);
102 char * o = setlocale(LC_ALL, 0);
106 char * n = setlocale(LC_ALL, lang_.c_str());
108 // If we are unable to honour the request we just
109 // return what we got in.
110 return from_ascii(m);
112 char const * c = bindtextdomain(PACKAGE, package().locale_dir().c_str());
116 << BOOST_CURRENT_FUNCTION << '\n'
117 << "Error code: " << errno << '\n'
118 << "Lang, mess: " << lang_ << " " << m << '\n'
119 << "Directory : " << package().locale_dir() << '\n'
120 << "Rtn value : " << c << endl;
123 #ifdef WORDS_BIGENDIAN
124 static const char * codeset = "UCS-4BE";
126 static const char * codeset = "UCS-4LE";
128 if (!bind_textdomain_codeset(PACKAGE, codeset)) {
130 << BOOST_CURRENT_FUNCTION << '\n'
131 << "Error code: " << errno << '\n'
132 << "Codeset : " << codeset << '\n'
138 char const * tmp = m.c_str();
139 char const * msg = gettext(tmp);
140 docstring translated;
142 lyxerr << "Undefined result from gettext" << endl;
143 translated = from_ascii(tmp);
144 } else if (msg == tmp) {
145 //lyxerr << "Same as entered returned" << endl;
146 translated = from_ascii(tmp);
148 lyxerr[Debug::DEBUG] << "We got a translation" << endl;
149 char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
152 setlocale(LC_ALL, old.c_str());
162 // This is the dummy variant.
163 class Messages::Pimpl {
165 Pimpl(string const &) {}
169 docstring const get(string const & m) const
178 : pimpl_(new Pimpl(""))
182 Messages::Messages(string const & l)
183 : pimpl_(new Pimpl(l))
187 // We need this for the sake of scoped_ptr
188 Messages::~Messages()
192 docstring const Messages::get(string const & msg) const
194 return pimpl_->get(msg);