2 * This file is part of LyX, the document processor.
3 * Licence details can be found in the file COPYING.
5 * \author Lars Gullik Bjønnes
7 * Full author contact details are available in file CREDITS
14 #include "support/filetools.h"
15 #include "support/path_defines.h"
17 using namespace lyx::support;
24 string const & getLocaleDir()
26 static string locale_dir;
28 if (locale_dir.empty()) {
29 locale_dir = GetEnvPath("LYX_LOCALEDIR");
30 if (locale_dir.empty())
31 locale_dir = lyx_localedir();
42 // This version of the Pimpl utilizes the message capability of
43 // libstdc++ that is distributed with GNU G++.
44 class Messages::Pimpl {
46 typedef std::messages<char>::catalog catalog;
48 Pimpl(string const & l)
50 loc_gl(lang_.c_str()),
51 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
53 //lyxerr << "Messages: language(" << l
54 // << ") in dir(" << dir << ")" << std::endl;
56 cat_gl = mssg_gl.open(PACKAGE, loc_gl, getLocaleDir().c_str());
62 mssg_gl.close(cat_gl);
65 string const get(string const & msg) const
67 return mssg_gl.get(cat_gl, 0, 0, msg);
75 std::messages<char> const & mssg_gl;
86 # include <libintl.h> // use the header already in the system *EK*
88 # include "../intl/libintl.h"
91 // This is a more traditional variant.
92 class Messages::Pimpl {
94 Pimpl(string const & l)
97 //lyxerr << "Messages: language(" << l
98 // << ") in dir(" << dir << ")" << std::endl;
100 bindtextdomain(PACKAGE, getLocaleDir().c_str());
106 string const get(string const & m) const
111 char * old = strdup(setlocale(LC_ALL, 0));
112 char * n = setlocale(LC_ALL, lang_.c_str());
113 const char* msg = gettext(m.c_str());
114 setlocale(LC_ALL, old);
116 // If we are unable to honour the request we just
117 // return what we got in.
118 return (!n ? m : string(msg));
127 // This is the dummy variant.
128 class Messages::Pimpl {
130 Pimpl(string const &) {}
134 string const get(string const & m) const
143 : pimpl_(new Pimpl(""))
147 Messages::Messages(string const & l)
148 : pimpl_(new Pimpl(l))
152 // We need this for the sake of scoped_ptr
153 Messages::~Messages()
157 string const Messages::get(string const & msg) const
159 return pimpl_->get(msg);