]> git.lyx.org Git - lyx.git/blob - src/client/messages.C
Another compile fix. I don't understand why it worked for me.
[lyx.git] / src / client / messages.C
1 /* \file messages.C
2  * This file is part of LyX, the document processor.
3  * Licence details can be found in the file COPYING.
4  *
5  * \author Lars Gullik Bjønnes
6  *
7  * Full author contact details are available in file CREDITS.
8  */
9
10 #include <config.h>
11
12 #include "messages.h"
13 #include "debug.h"
14 #include "support/filetools.h"
15 #include "support/package.h"
16
17 #include <boost/current_function.hpp>
18
19 #include <cerrno>
20
21
22 namespace lyx {
23
24 using lyx::support::package;
25 using std::endl;
26 using std::string;
27
28
29 #ifdef ENABLE_NLS
30
31
32 #if 0
33
34 -#include <locale>
35
36 // This version of the Pimpl utilizes the message capability of
37 // libstdc++ that is distributed with GNU G++.
38 class Messages::Pimpl {
39 public:
40         typedef std::messages<char>::catalog catalog;
41
42         Pimpl(string const & l)
43                 : lang_(l),
44                   loc_gl(lang_.c_str()),
45                   mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
46         {
47                 //lyxerr << "Messages: language(" << l
48                 //       << ") in dir(" << dir << ")" << std::endl;
49
50                 cat_gl = mssg_gl.open(PACKAGE, loc_gl,
51                                       package().locale_dir().c_str());
52
53         }
54
55         ~Pimpl()
56         {
57                 mssg_gl.close(cat_gl);
58         }
59
60         string const get(string const & msg) const
61         {
62                 return mssg_gl.get(cat_gl, 0, 0, msg);
63         }
64 private:
65         ///
66         string lang_;
67         ///
68         std::locale loc_gl;
69         ///
70         std::messages<char> const & mssg_gl;
71         ///
72         catalog cat_gl;
73 };
74 #else
75
76 #ifdef HAVE_LOCALE_H
77 #  include <locale.h>
78 #endif
79
80 #  if HAVE_GETTEXT
81 #    include <libintl.h>      // use the header already in the system *EK*
82 #  else
83 #    include "../intl/libintl.h"
84 #  endif
85
86 // This is a more traditional variant.
87 class Messages::Pimpl {
88 public:
89         Pimpl(string const & l)
90                 : lang_(l)
91         {
92                 //lyxerr << "Messages: language(" << l
93                 //       << ") in dir(" << dir << ")" << std::endl;
94
95         }
96
97         ~Pimpl() {}
98
99         docstring const get(string const & m) const
100         {
101                 if (m.empty())
102                         return from_ascii(m);
103
104                 char * o = setlocale(LC_ALL, 0);
105                 string old;
106                 if (o)
107                         old = o;
108                 char * n = setlocale(LC_ALL, lang_.c_str());
109                 if (!n)
110                         // If we are unable to honour the request we just
111                         // return what we got in.
112                         return from_ascii(m);
113                 errno = 0;
114                 char const * c = bindtextdomain(PACKAGE, package().locale_dir().c_str());
115                 int e = errno;
116                 if (e) {
117                         lyxerr[Debug::DEBUG]
118                                 << BOOST_CURRENT_FUNCTION << '\n'
119                                 << "Error code: " << errno << '\n'
120                                 << "Lang, mess: " << lang_ << " " << m << '\n'
121                                 << "Directory : " << package().locale_dir() << '\n'
122                                 << "Rtn value : " << c << endl;
123                 }
124
125 #ifdef WORDS_BIGENDIAN
126                 static const char * codeset = "UCS-4BE";
127 #else
128                 static const char * codeset = "UCS-4LE";
129 #endif
130                 if (!bind_textdomain_codeset(PACKAGE, codeset)) {
131                         lyxerr[Debug::DEBUG]
132                                 << BOOST_CURRENT_FUNCTION << '\n'
133                                 << "Error code: " << errno << '\n'
134                                 << "Codeset   : " << codeset << '\n'
135                                 << endl;
136                 }
137
138                 textdomain(PACKAGE);
139
140                 char const * tmp = m.c_str();
141                 char const * msg = gettext(tmp);
142                 docstring translated;
143                 if (!msg) {
144                         lyxerr << "Undefined result from gettext" << endl;
145                         translated = from_ascii(tmp);
146                 } else if (msg == tmp) {
147                         //lyxerr << "Same as entered returned" << endl;
148                         translated = from_ascii(tmp);
149                 } else {
150                         lyxerr[Debug::DEBUG] << "We got a translation" << endl;
151                         char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
152                         translated = ucs4;
153                 }
154                 setlocale(LC_ALL, old.c_str());
155                 return translated;
156         }
157 private:
158         ///
159         string lang_;
160 };
161 #endif
162
163 #else // ENABLE_NLS
164 // This is the dummy variant.
165 class Messages::Pimpl {
166 public:
167         Pimpl(string const &) {}
168
169         ~Pimpl() {}
170
171         docstring const get(string const & m) const
172         {
173                 return from_ascii(m);
174         }
175 };
176 #endif
177
178
179 Messages::Messages()
180         : pimpl_(new Pimpl(""))
181 {}
182
183
184 Messages::Messages(string const & l)
185         : pimpl_(new Pimpl(l))
186 {}
187
188
189 // We need this for the sake of scoped_ptr
190 Messages::~Messages()
191 {}
192
193
194 docstring const Messages::get(string const & msg) const
195 {
196         return pimpl_->get(msg);
197 }
198
199
200 } // namespace lyx