]> git.lyx.org Git - lyx.git/blobdiff - src/messages.C
fix crash when collapsing ert with cursor inside
[lyx.git] / src / messages.C
index d1aa3f52217c77a1bf95f0b17ca5c69bf9dd223e..d523af76262f059b4da67a05c4cb241d8e0dc51d 100644 (file)
 
 #include "messages.h"
 #include "support/filetools.h"
-#include "support/path_defines.h"
+#include "support/package.h"
 
-using lyx::support::GetEnvPath;
-using lyx::support::lyx_localedir;
+#include <boost/regex.hpp>
+
+using lyx::support::package;
 
 using std::string;
 
@@ -40,7 +41,7 @@ public:
                //lyxerr << "Messages: language(" << l
                //       << ") in dir(" << dir << ")" << std::endl;
 
-               cat_gl = mssg_gl.open(PACKAGE, loc_gl, lyx_localedir().c_str());
+               cat_gl = mssg_gl.open(PACKAGE, loc_gl, package().locale_dir().c_str());
 
        }
 
@@ -95,14 +96,27 @@ public:
 
                char * old = strdup(setlocale(LC_ALL, 0));
                char * n = setlocale(LC_ALL, lang_.c_str());
-               bindtextdomain(PACKAGE, lyx_localedir().c_str());
+               bindtextdomain(PACKAGE, package().locale_dir().c_str());
                textdomain(PACKAGE);
                const char* msg = gettext(m.c_str());
-               setlocale(LC_ALL, old);
-               free(old);
+               // Some english words have different translations, depending
+               // on context. In these cases the original string is
+               // augmented by context information (e.g.
+               // "To:[[as in 'From page x to page y']]" and
+               // "To:[[as in 'From format x to format y']]".
+               // This means that we need to filter out everything in
+               // double square brackets at the end of the string,
+               // otherwise the user sees bogus messages.
                // If we are unable to honour the request we just
                // return what we got in.
-               return (!n ? m : string(msg));
+               string translated(n ? msg : m);
+               static boost::regex const reg("^([^\\[]*)\\[\\[[^\\]]*\\]\\]$");
+               boost::smatch sub;
+               if (regex_match(translated, sub, reg))
+                       translated = sub.str(1);
+               setlocale(LC_ALL, old);
+               free(old);
+               return translated;
        }
 private:
        ///