]> git.lyx.org Git - lyx.git/blob - src/client/messages.C
cleanup some debug messages
[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 "support/filetools.h"
14 #include "support/package.h"
15
16 using lyx::support::package;
17 using std::string;
18
19
20 #ifdef ENABLE_NLS
21
22
23 #if 0
24
25 -#include <locale>
26
27 // This version of the Pimpl utilizes the message capability of
28 // libstdc++ that is distributed with GNU G++.
29 class Messages::Pimpl {
30 public:
31         typedef std::messages<char>::catalog catalog;
32
33         Pimpl(string const & l)
34                 : lang_(l),
35                   loc_gl(lang_.c_str()),
36                   mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
37         {
38                 //lyxerr << "Messages: language(" << l
39                 //       << ") in dir(" << dir << ")" << std::endl;
40
41                 cat_gl = mssg_gl.open(PACKAGE, loc_gl,
42                                       package().locale_dir().c_str());
43
44         }
45
46         ~Pimpl()
47         {
48                 mssg_gl.close(cat_gl);
49         }
50
51         string const get(string const & msg) const
52         {
53                 return mssg_gl.get(cat_gl, 0, 0, msg);
54         }
55 private:
56         ///
57         string lang_;
58         ///
59         std::locale loc_gl;
60         ///
61         std::messages<char> const & mssg_gl;
62         ///
63         catalog cat_gl;
64 };
65 #else
66
67 #ifdef HAVE_LOCALE_H
68 #  include <locale.h>
69 #endif
70
71 #  if HAVE_GETTEXT
72 #    include <libintl.h>      // use the header already in the system *EK*
73 #  else
74 #    include "../intl/libintl.h"
75 #  endif
76
77 // This is a more traditional variant.
78 class Messages::Pimpl {
79 public:
80         Pimpl(string const & l)
81                 : lang_(l)
82         {
83                 //lyxerr << "Messages: language(" << l
84                 //       << ") in dir(" << dir << ")" << std::endl;
85
86         }
87
88         ~Pimpl() {}
89
90         string const get(string const & m) const
91         {
92                 if (m.empty())
93                         return m;
94
95                 char * old = strdup(setlocale(LC_ALL, 0));
96                 char * n = setlocale(LC_ALL, lang_.c_str());
97                 bindtextdomain(PACKAGE, package().locale_dir().c_str());
98                 textdomain(PACKAGE);
99                 const char* msg = gettext(m.c_str());
100                 setlocale(LC_ALL, old);
101                 free(old);
102                 // If we are unable to honour the request we just
103                 // return what we got in.
104                 return (!n ? m : string(msg));
105         }
106 private:
107         ///
108         string lang_;
109 };
110 #endif
111
112 #else // ENABLE_NLS
113 // This is the dummy variant.
114 class Messages::Pimpl {
115 public:
116         Pimpl(string const &) {}
117
118         ~Pimpl() {}
119
120         string const get(string const & m) const
121         {
122                 return m;
123         }
124 };
125 #endif
126
127
128 Messages::Messages()
129         : pimpl_(new Pimpl(""))
130 {}
131
132
133 Messages::Messages(string const & l)
134         : pimpl_(new Pimpl(l))
135 {}
136
137
138 // We need this for the sake of scoped_ptr
139 Messages::~Messages()
140 {}
141
142
143 string const Messages::get(string const & msg) const
144 {
145         return pimpl_->get(msg);
146 }