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