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/package.h"
16 #include <boost/regex.hpp>
18 using lyx::support::package;
30 // This version of the Pimpl utilizes the message capability of
31 // libstdc++ that is distributed with GNU G++.
32 class Messages::Pimpl {
34 typedef std::messages<char>::catalog catalog;
36 Pimpl(string const & l)
38 loc_gl(lang_.c_str()),
39 mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
41 //lyxerr << "Messages: language(" << l
42 // << ") in dir(" << dir << ")" << std::endl;
44 cat_gl = mssg_gl.open(PACKAGE, loc_gl, package().locale_dir().c_str());
50 mssg_gl.close(cat_gl);
53 string const get(string const & msg) const
55 return mssg_gl.get(cat_gl, 0, 0, msg);
63 std::messages<char> const & mssg_gl;
74 # include <libintl.h> // use the header already in the system *EK*
76 # include "../intl/libintl.h"
79 // This is a more traditional variant.
80 class Messages::Pimpl {
82 Pimpl(string const & l)
85 //lyxerr << "Messages: language(" << l
86 // << ") in dir(" << dir << ")" << std::endl;
92 string const get(string const & m) const
97 char * old = strdup(setlocale(LC_ALL, 0));
98 char * n = setlocale(LC_ALL, lang_.c_str());
99 bindtextdomain(PACKAGE, package().locale_dir().c_str());
101 const char* msg = gettext(m.c_str());
102 // Some english words have different translations, depending
103 // on context. In these cases the original string is
104 // augmented by context information (e.g.
105 // "To:[[as in 'From page x to page y']]" and
106 // "To:[[as in 'From format x to format y']]".
107 // This means that we need to filter out everything in
108 // double square brackets at the end of the string,
109 // otherwise the user sees bogus messages.
110 // If we are unable to honour the request we just
111 // return what we got in.
112 string translated(n ? msg : m);
113 static boost::regex const reg("^([^\\[]*)\\[\\[[^\\]]*\\]\\]$");
115 if (regex_match(translated, sub, reg))
116 translated = sub.str(1);
117 setlocale(LC_ALL, old);
128 // This is the dummy variant.
129 class Messages::Pimpl {
131 Pimpl(string const &) {}
135 string const get(string const & m) const
144 : pimpl_(new Pimpl(""))
148 Messages::Messages(string const & l)
149 : pimpl_(new Pimpl(l))
153 // We need this for the sake of scoped_ptr
154 Messages::~Messages()
158 string const Messages::get(string const & msg) const
160 return pimpl_->get(msg);