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"
21 string const & getLocaleDir()
23 static string locale_dir;
25 if (locale_dir.empty()) {
26 locale_dir = GetEnvPath("LYX_LOCALEDIR");
27 if (locale_dir.empty())
28 locale_dir = LOCALEDIR;
39 // This version of the Pimpl utilizes the message capability of
40 // libstdc++ that is distributed with GNU G++.
41 class Messages::Pimpl {
43 typedef std::messages<char>::catalog catalog;
45 Pimpl(string const & l)
47 loc_gl(lang_.c_str()),
48 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
50 //lyxerr << "Messages: language(" << l
51 // << ") in dir(" << dir << ")" << std::endl;
53 cat_gl = mssg_gl.open(PACKAGE, loc_gl, getLocaleDir().c_str());
59 mssg_gl.close(cat_gl);
62 string const get(string const & msg) const
64 return mssg_gl.get(cat_gl, 0, 0, msg);
72 std::messages<char> const & mssg_gl;
83 # include <libintl.h> // use the header already in the system *EK*
85 # include "../intl/libintl.h"
88 // This is a more traditional variant.
89 class Messages::Pimpl {
91 Pimpl(string const & l)
94 //lyxerr << "Messages: language(" << l
95 // << ") in dir(" << dir << ")" << std::endl;
97 bindtextdomain(PACKAGE, getLocaleDir().c_str());
103 string const get(string const & m) const
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);
110 // If we are unable to honour the request we just
111 // return what we got in.
112 return (!n ? m : string(msg));
121 // This is the dummy variant.
122 class Messages::Pimpl {
124 Pimpl(string const &) {}
128 string const get(string const & m) const
137 : pimpl_(new Pimpl(""))
141 Messages::Messages(string const & l)
142 : pimpl_(new Pimpl(l))
146 // We need this for the sake of scoped_ptr
147 Messages::~Messages()
151 string const Messages::get(string const & msg) const
153 return pimpl_->get(msg);