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/debug.h"
14 #include "support/filetools.h"
15 #include "support/Package.h"
16 #include "support/unicode.h"
22 using namespace lyx::support;
33 // This version of the Pimpl utilizes the message capability of
34 // libstdc++ that is distributed with GNU G++.
35 class Messages::Pimpl {
37 typedef messages<char>::catalog catalog;
39 Pimpl(string const & l)
41 loc_gl(lang_.c_str()),
42 mssg_gl(use_facet<messages<char> >(loc_gl))
44 //lyxerr << "Messages: language(" << l
45 // << ") in dir(" << dir << ")" << endl;
47 string const locale_dir = package().locale_dir().toFilesystemEncoding();
48 cat_gl = mssg_gl.open(PACKAGE, loc_gl, locale_dir.c_str());
54 mssg_gl.close(cat_gl);
57 string const get(string const & msg) const
59 return mssg_gl.get(cat_gl, 0, 0, msg);
67 messages<char> const & mssg_gl;
78 # include <libintl.h> // use the header already in the system *EK*
80 # include "intl/libintl.h"
83 // This is a more traditional variant.
84 class Messages::Pimpl {
86 Pimpl(string const & l)
89 //lyxerr << "Messages: language(" << l
90 // << ") in dir(" << dir << ")" << endl;
96 docstring const get(string const & m) const
101 char * o = setlocale(LC_ALL, 0);
105 char * n = setlocale(LC_ALL, lang_.c_str());
107 // If we are unable to honour the request we just
108 // return what we got in.
109 return from_ascii(m);
111 string const locale_dir = package().locale_dir().toFilesystemEncoding();
112 char const * c = bindtextdomain(PACKAGE, locale_dir.c_str());
115 LYXERR(Debug::DEBUG, "Messages::get()" << '\n'
116 << "Error code: " << errno << '\n'
117 << "Lang, mess: " << lang_ << " " << m << '\n'
118 << "Directory : " << package().locale_dir().absFileName() << '\n'
119 << "Rtn value : " << c);
122 if (!bind_textdomain_codeset(PACKAGE, ucs4_codeset)) {
123 LYXERR(Debug::DEBUG, "Messages::get()" << '\n'
124 << "Error code: " << errno << '\n'
125 << "Codeset : " << ucs4_codeset << '\n');
130 char const * tmp = m.c_str();
131 char const * msg = gettext(tmp);
132 docstring translated;
134 lyxerr << "Undefined result from gettext" << endl;
135 translated = from_ascii(tmp);
136 } else if (msg == tmp) {
137 //lyxerr << "Same as entered returned" << endl;
138 translated = from_ascii(tmp);
140 LYXERR(Debug::DEBUG, "We got a translation");
141 char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
144 setlocale(LC_ALL, old.c_str());
154 // This is the dummy variant.
155 class Messages::Pimpl {
157 Pimpl(string const &) {}
161 docstring const get(string const & m) const
163 return from_ascii(m);
170 : pimpl_(new Pimpl(""))
174 Messages::Messages(string const & l)
175 : pimpl_(new Pimpl(l))
179 // We need this for the sake of scoped_ptr
180 Messages::~Messages()
184 docstring const Messages::get(string const & msg) const
186 return pimpl_->get(msg);