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