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"
16 using namespace lyx::support;
23 string const & getLocaleDir()
25 static string locale_dir;
27 if (locale_dir.empty()) {
28 locale_dir = GetEnvPath("LYX_LOCALEDIR");
29 if (locale_dir.empty())
30 locale_dir = LOCALEDIR;
41 // This version of the Pimpl utilizes the message capability of
42 // libstdc++ that is distributed with GNU G++.
43 class Messages::Pimpl {
45 typedef std::messages<char>::catalog catalog;
47 Pimpl(string const & l)
49 loc_gl(lang_.c_str()),
50 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
52 //lyxerr << "Messages: language(" << l
53 // << ") in dir(" << dir << ")" << std::endl;
55 cat_gl = mssg_gl.open(PACKAGE, loc_gl, getLocaleDir().c_str());
61 mssg_gl.close(cat_gl);
64 string const get(string const & msg) const
66 return mssg_gl.get(cat_gl, 0, 0, msg);
74 std::messages<char> const & mssg_gl;
85 # include <libintl.h> // use the header already in the system *EK*
87 # include "../intl/libintl.h"
90 // This is a more traditional variant.
91 class Messages::Pimpl {
93 Pimpl(string const & l)
96 //lyxerr << "Messages: language(" << l
97 // << ") in dir(" << dir << ")" << std::endl;
99 bindtextdomain(PACKAGE, getLocaleDir().c_str());
105 string const get(string const & m) const
110 char * old = strdup(setlocale(LC_ALL, 0));
111 char * n = setlocale(LC_ALL, lang_.c_str());
112 const char* msg = gettext(m.c_str());
113 setlocale(LC_ALL, old);
115 // If we are unable to honour the request we just
116 // return what we got in.
117 return (!n ? m : string(msg));
126 // This is the dummy variant.
127 class Messages::Pimpl {
129 Pimpl(string const &) {}
133 string const get(string const & m) const
142 : pimpl_(new Pimpl(""))
146 Messages::Messages(string const & l)
147 : pimpl_(new Pimpl(l))
151 // We need this for the sake of scoped_ptr
152 Messages::~Messages()
156 string const Messages::get(string const & msg) const
158 return pimpl_->get(msg);