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