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"
23 using support::package;
36 // This version of the Pimpl utilizes the message capability of
37 // libstdc++ that is distributed with GNU G++.
38 class Messages::Pimpl {
40 typedef std::messages<char>::catalog catalog;
42 Pimpl(string const & l)
44 loc_gl(lang_.c_str()),
45 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
47 //lyxerr << "Messages: language(" << l
48 // << ") in dir(" << dir << ")" << std::endl;
50 string const locale_dir = package().locale_dir().toFilesystemEncoding();
51 cat_gl = mssg_gl.open(PACKAGE, loc_gl, locale_dir.c_str());
57 mssg_gl.close(cat_gl);
60 string const get(string const & msg) const
62 return mssg_gl.get(cat_gl, 0, 0, msg);
70 std::messages<char> const & mssg_gl;
81 # include <libintl.h> // use the header already in the system *EK*
83 # include "../intl/libintl.h"
86 // This is a more traditional variant.
87 class Messages::Pimpl {
89 Pimpl(string const & l)
92 //lyxerr << "Messages: language(" << l
93 // << ") in dir(" << dir << ")" << std::endl;
99 docstring const get(string const & m) const
102 return from_ascii(m);
104 char * o = setlocale(LC_ALL, 0);
108 char * n = setlocale(LC_ALL, lang_.c_str());
110 // If we are unable to honour the request we just
111 // return what we got in.
112 return from_ascii(m);
114 string const locale_dir = package().locale_dir().toFilesystemEncoding();
115 char const * c = bindtextdomain(PACKAGE, locale_dir.c_str());
118 LYXERR(Debug::DEBUG, "Messages::get()" << '\n'
119 << "Error code: " << errno << '\n'
120 << "Lang, mess: " << lang_ << " " << m << '\n'
121 << "Directory : " << package().locale_dir().absFilename() << '\n'
122 << "Rtn value : " << c);
125 if (!bind_textdomain_codeset(PACKAGE, ucs4_codeset)) {
126 LYXERR(Debug::DEBUG, "Messages::get()" << '\n'
127 << "Error code: " << errno << '\n'
128 << "Codeset : " << ucs4_codeset << '\n');
133 char const * tmp = m.c_str();
134 char const * msg = gettext(tmp);
135 docstring translated;
137 lyxerr << "Undefined result from gettext" << endl;
138 translated = from_ascii(tmp);
139 } else if (msg == tmp) {
140 //lyxerr << "Same as entered returned" << endl;
141 translated = from_ascii(tmp);
143 LYXERR(Debug::DEBUG, "We got a translation");
144 char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
147 setlocale(LC_ALL, old.c_str());
157 // This is the dummy variant.
158 class Messages::Pimpl {
160 Pimpl(string const &) {}
164 docstring const get(string const & m) const
166 return from_ascii(m);
173 : pimpl_(new Pimpl(""))
177 Messages::Messages(string const & l)
178 : pimpl_(new Pimpl(l))
182 // We need this for the sake of scoped_ptr
183 Messages::~Messages()
187 docstring const Messages::get(string const & msg) const
189 return pimpl_->get(msg);