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"
25 using support::package;
34 // This version of the Pimpl utilizes the message capability of
35 // libstdc++ that is distributed with GNU G++.
36 class Messages::Pimpl {
38 typedef std::messages<char>::catalog catalog;
40 Pimpl(string const & l)
42 loc_gl(lang_.c_str()),
43 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
45 //lyxerr << "Messages: language(" << l
46 // << ") in dir(" << dir << ")" << std::endl;
48 string const locale_dir = package().locale_dir().toFilesystemEncoding();
49 cat_gl = mssg_gl.open(PACKAGE, loc_gl, locale_dir.c_str());
55 mssg_gl.close(cat_gl);
58 string const get(string const & msg) const
60 return mssg_gl.get(cat_gl, 0, 0, msg);
68 std::messages<char> const & mssg_gl;
79 # include <libintl.h> // use the header already in the system *EK*
81 # include "../intl/libintl.h"
84 // This is a more traditional variant.
85 class Messages::Pimpl {
87 Pimpl(string const & l)
90 //lyxerr << "Messages: language(" << l
91 // << ") in dir(" << dir << ")" << std::endl;
97 docstring const get(string const & m) const
100 return from_ascii(m);
102 char * o = setlocale(LC_ALL, 0);
106 char * n = setlocale(LC_ALL, lang_.c_str());
108 // If we are unable to honour the request we just
109 // return what we got in.
110 return from_ascii(m);
112 string const locale_dir = package().locale_dir().toFilesystemEncoding();
113 char const * c = bindtextdomain(PACKAGE, locale_dir.c_str());
116 LYXERR(Debug::DEBUG, "Messages::get()" << '\n'
117 << "Error code: " << errno << '\n'
118 << "Lang, mess: " << lang_ << " " << m << '\n'
119 << "Directory : " << package().locale_dir().absFilename() << '\n'
120 << "Rtn value : " << c);
123 if (!bind_textdomain_codeset(PACKAGE, ucs4_codeset)) {
124 LYXERR(Debug::DEBUG, "Messages::get()" << '\n'
125 << "Error code: " << errno << '\n'
126 << "Codeset : " << ucs4_codeset << '\n');
131 char const * tmp = m.c_str();
132 char const * msg = gettext(tmp);
133 docstring translated;
135 lyxerr << "Undefined result from gettext" << endl;
136 translated = from_ascii(tmp);
137 } else if (msg == tmp) {
138 //lyxerr << "Same as entered returned" << endl;
139 translated = from_ascii(tmp);
141 LYXERR(Debug::DEBUG, "We got a translation");
142 char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
145 setlocale(LC_ALL, old.c_str());
155 // This is the dummy variant.
156 class Messages::Pimpl {
158 Pimpl(string const &) {}
162 docstring const get(string const & m) const
164 return from_ascii(m);
171 : pimpl_(new Pimpl(""))
175 Messages::Messages(string const & l)
176 : pimpl_(new Pimpl(l))
180 // We need this for the sake of scoped_ptr
181 Messages::~Messages()
185 docstring const Messages::get(string const & msg) const
187 return pimpl_->get(msg);