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;
31 // This version of the Pimpl utilizes the message capability of
32 // libstdc++ that is distributed with GNU G++.
33 class Messages::Pimpl {
35 typedef std::messages<char>::catalog catalog;
37 Pimpl(string const & l)
39 loc_gl(lang_.c_str()),
40 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
42 //lyxerr << "Messages: language(" << l
43 // << ") in dir(" << dir << ")" << std::endl;
45 cat_gl = mssg_gl.open(PACKAGE, loc_gl,
46 package().locale_dir().c_str());
52 mssg_gl.close(cat_gl);
55 string const get(string const & msg) const
57 return mssg_gl.get(cat_gl, 0, 0, msg);
65 std::messages<char> const & mssg_gl;
76 # include <libintl.h> // use the header already in the system *EK*
78 # include "../intl/libintl.h"
81 // This is a more traditional variant.
82 class Messages::Pimpl {
84 Pimpl(string const & l)
87 //lyxerr << "Messages: language(" << l
88 // << ") in dir(" << dir << ")" << std::endl;
94 docstring const get(string const & m) const
99 char * o = setlocale(LC_ALL, 0);
103 char * n = setlocale(LC_ALL, lang_.c_str());
105 // If we are unable to honour the request we just
106 // return what we got in.
107 return from_ascii(m);
109 char const * c = bindtextdomain(PACKAGE, package().locale_dir().c_str());
113 << BOOST_CURRENT_FUNCTION << '\n'
114 << "Error code: " << errno << '\n'
115 << "Lang, mess: " << lang_ << " " << m << '\n'
116 << "Directory : " << package().locale_dir() << '\n'
117 << "Rtn value : " << c << endl;
120 #ifdef WORDS_BIGENDIAN
121 static const char * codeset = "UCS-4BE";
123 static const char * codeset = "UCS-4LE";
125 if (!bind_textdomain_codeset(PACKAGE, codeset)) {
127 << BOOST_CURRENT_FUNCTION << '\n'
128 << "Error code: " << errno << '\n'
129 << "Codeset : " << codeset << '\n'
135 char const * tmp = m.c_str();
136 char const * msg = gettext(tmp);
137 docstring translated;
139 lyxerr << "Undefined result from gettext" << endl;
140 translated = from_ascii(tmp);
141 } else if (msg == tmp) {
142 //lyxerr << "Same as entered returned" << endl;
143 translated = from_ascii(tmp);
145 lyxerr[Debug::DEBUG] << "We got a translation" << endl;
146 char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
149 setlocale(LC_ALL, old.c_str());
159 // This is the dummy variant.
160 class Messages::Pimpl {
162 Pimpl(string const &) {}
166 docstring const get(string const & m) const
175 : pimpl_(new Pimpl(""))
179 Messages::Messages(string const & l)
180 : pimpl_(new Pimpl(l))
184 // We need this for the sake of scoped_ptr
185 Messages::~Messages()
189 docstring const Messages::get(string const & msg) const
191 return pimpl_->get(msg);