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 #include <boost/regex.hpp>
18 using lyx::support::GetEnvPath;
19 using lyx::support::lyx_localedir;
31 // This version of the Pimpl utilizes the message capability of
32 // libstdc++ that is distributed with GNU G++.
33 class Messages::Pimpl {
35 typedef std::messages<char>::catalog catalog;
37 Pimpl(string const & l)
39 loc_gl(lang_.c_str()),
40 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
42 //lyxerr << "Messages: language(" << l
43 // << ") in dir(" << dir << ")" << std::endl;
45 cat_gl = mssg_gl.open(PACKAGE, loc_gl, lyx_localedir().c_str());
51 mssg_gl.close(cat_gl);
54 string const get(string const & msg) const
56 return mssg_gl.get(cat_gl, 0, 0, msg);
64 std::messages<char> const & mssg_gl;
75 # include <libintl.h> // use the header already in the system *EK*
77 # include "../intl/libintl.h"
80 // This is a more traditional variant.
81 class Messages::Pimpl {
83 Pimpl(string const & l)
86 //lyxerr << "Messages: language(" << l
87 // << ") in dir(" << dir << ")" << std::endl;
93 string const get(string const & m) const
98 char * old = strdup(setlocale(LC_ALL, 0));
99 char * n = setlocale(LC_ALL, lang_.c_str());
100 bindtextdomain(PACKAGE, lyx_localedir().c_str());
102 const char* msg = gettext(m.c_str());
103 // Some english words have different translations, depending
104 // on context. In these cases the original string is
105 // augmented by context information (e.g.
106 // "To:[[as in 'From page x to page y']]" and
107 // "To:[[as in 'From format x to format y']]".
108 // This means that we need to filter out everything in
109 // double square brackets at the end of the string,
110 // otherwise the user sees bogus messages.
111 // If we are unable to honour the request we just
112 // return what we got in.
113 string translated(n ? msg : m);
114 static boost::regex const reg("^([^\\[]*)\\[\\[[^\\]]*\\]\\]$");
116 if (regex_match(translated, sub, reg))
117 translated = sub.str(1);
118 setlocale(LC_ALL, old);
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);