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());
120 << BOOST_CURRENT_FUNCTION << '\n'
121 << "Error code: " << errno << '\n'
122 << "Lang, mess: " << lang_ << " " << m << '\n'
123 << "Directory : " << package().locale_dir().absFilename() << '\n'
124 << "Rtn value : " << c << endl;
127 if (!bind_textdomain_codeset(PACKAGE, ucs4_codeset)) {
129 << BOOST_CURRENT_FUNCTION << '\n'
130 << "Error code: " << errno << '\n'
131 << "Codeset : " << ucs4_codeset << '\n'
137 char const * tmp = m.c_str();
138 char const * msg = gettext(tmp);
139 docstring translated;
141 lyxerr << "Undefined result from gettext" << endl;
142 translated = from_ascii(tmp);
143 } else if (msg == tmp) {
144 //lyxerr << "Same as entered returned" << endl;
145 translated = from_ascii(tmp);
147 LYXERR(Debug::DEBUG) << "We got a translation" << endl;
148 char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
151 setlocale(LC_ALL, old.c_str());
161 // This is the dummy variant.
162 class Messages::Pimpl {
164 Pimpl(string const &) {}
168 docstring const get(string const & m) const
170 return from_ascii(m);
177 : pimpl_(new Pimpl(""))
181 Messages::Messages(string const & l)
182 : pimpl_(new Pimpl(l))
186 // We need this for the sake of scoped_ptr
187 Messages::~Messages()
191 docstring const Messages::get(string const & msg) const
193 return pimpl_->get(msg);