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