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"
16 #include "support/unicode.h"
18 #include <boost/current_function.hpp>
25 using lyx::support::package;
37 // This version of the Pimpl utilizes the message capability of
38 // libstdc++ that is distributed with GNU G++.
39 class Messages::Pimpl {
41 typedef std::messages<char>::catalog catalog;
43 Pimpl(string const & l)
45 loc_gl(lang_.c_str()),
46 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
48 //lyxerr << "Messages: language(" << l
49 // << ") in dir(" << dir << ")" << std::endl;
51 string const locale_dir = package().locale_dir().toFilesystemEncoding();
52 cat_gl = mssg_gl.open(PACKAGE, loc_gl, locale_dir.c_str());
58 mssg_gl.close(cat_gl);
61 string const get(string const & msg) const
63 return mssg_gl.get(cat_gl, 0, 0, msg);
71 std::messages<char> const & mssg_gl;
82 # include <libintl.h> // use the header already in the system *EK*
84 # include "../intl/libintl.h"
87 // This is a more traditional variant.
88 class Messages::Pimpl {
90 Pimpl(string const & l)
93 //lyxerr << "Messages: language(" << l
94 // << ") in dir(" << dir << ")" << std::endl;
100 docstring const get(string const & m) const
103 return from_ascii(m);
105 char * o = setlocale(LC_ALL, 0);
109 char * n = setlocale(LC_ALL, lang_.c_str());
111 // If we are unable to honour the request we just
112 // return what we got in.
113 return from_ascii(m);
115 string const locale_dir = package().locale_dir().toFilesystemEncoding();
116 char const * c = bindtextdomain(PACKAGE, locale_dir.c_str());
119 LYXERR(Debug::DEBUG, BOOST_CURRENT_FUNCTION << '\n'
120 << "Error code: " << errno << '\n'
121 << "Lang, mess: " << lang_ << " " << m << '\n'
122 << "Directory : " << package().locale_dir().absFilename() << '\n'
123 << "Rtn value : " << c);
126 if (!bind_textdomain_codeset(PACKAGE, ucs4_codeset)) {
127 LYXERR(Debug::DEBUG, BOOST_CURRENT_FUNCTION << '\n'
128 << "Error code: " << errno << '\n'
129 << "Codeset : " << ucs4_codeset << '\n');
134 char const * tmp = m.c_str();
135 char const * msg = gettext(tmp);
136 docstring translated;
138 lyxerr << "Undefined result from gettext" << endl;
139 translated = from_ascii(tmp);
140 } else if (msg == tmp) {
141 //lyxerr << "Same as entered returned" << endl;
142 translated = from_ascii(tmp);
144 LYXERR(Debug::DEBUG, "We got a translation");
145 char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
148 setlocale(LC_ALL, old.c_str());
158 // This is the dummy variant.
159 class Messages::Pimpl {
161 Pimpl(string const &) {}
165 docstring const get(string const & m) const
167 return from_ascii(m);
174 : pimpl_(new Pimpl(""))
178 Messages::Messages(string const & l)
179 : pimpl_(new Pimpl(l))
183 // We need this for the sake of scoped_ptr
184 Messages::~Messages()
188 docstring const Messages::get(string const & msg) const
190 return pimpl_->get(msg);