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.
13 #include "support/filetools.h"
14 #include "support/path_defines.h"
16 using lyx::support::GetEnvPath;
17 using lyx::support::lyx_localedir;
26 string const & getLocaleDir()
28 static string locale_dir;
30 if (locale_dir.empty()) {
31 locale_dir = GetEnvPath("LYX_LOCALEDIR");
32 if (locale_dir.empty())
33 locale_dir = lyx_localedir();
44 // This version of the Pimpl utilizes the message capability of
45 // libstdc++ that is distributed with GNU G++.
46 class Messages::Pimpl {
48 typedef std::messages<char>::catalog catalog;
50 Pimpl(string const & l)
52 loc_gl(lang_.c_str()),
53 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
55 //lyxerr << "Messages: language(" << l
56 // << ") in dir(" << dir << ")" << std::endl;
58 cat_gl = mssg_gl.open(PACKAGE, loc_gl, getLocaleDir().c_str());
64 mssg_gl.close(cat_gl);
67 string const get(string const & msg) const
69 return mssg_gl.get(cat_gl, 0, 0, msg);
77 std::messages<char> const & mssg_gl;
88 # include <libintl.h> // use the header already in the system *EK*
90 # include "../intl/libintl.h"
93 // This is a more traditional variant.
94 class Messages::Pimpl {
96 Pimpl(string const & l)
99 //lyxerr << "Messages: language(" << l
100 // << ") in dir(" << dir << ")" << std::endl;
102 bindtextdomain(PACKAGE, getLocaleDir().c_str());
108 string const get(string const & m) const
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);
118 // If we are unable to honour the request we just
119 // return what we got in.
120 return (!n ? m : string(msg));
129 // This is the dummy variant.
130 class Messages::Pimpl {
132 Pimpl(string const &) {}
136 string const get(string const & m) const
145 : pimpl_(new Pimpl(""))
149 Messages::Messages(string const & l)
150 : pimpl_(new Pimpl(l))
154 // We need this for the sake of scoped_ptr
155 Messages::~Messages()
159 string const Messages::get(string const & msg) const
161 return pimpl_->get(msg);