]> git.lyx.org Git - lyx.git/blobdiff - src/messages.C
get rid of broken_header.h and some unneeded tests
[lyx.git] / src / messages.C
index a8e5576a120ef52eb4442d1cfaffe4915d78c474..1877ae2f0b23ca72e096248f2ca04f1e9604fe3e 100644 (file)
@@ -4,40 +4,29 @@
  *
  * \author Lars Gullik Bjønnes
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
 #include "messages.h"
-#include "debug.h"
 #include "support/filetools.h"
 #include "support/path_defines.h"
 
-using namespace lyx::support;
+#include <boost/regex.hpp>
 
+using lyx::support::GetEnvPath;
+using lyx::support::lyx_localedir;
 
-#ifdef ENABLE_NLS
-
-namespace {
+using std::string;
 
-string const & getLocaleDir()
-{
-       static string locale_dir;
 
-       if (locale_dir.empty()) {
-               locale_dir = GetEnvPath("LYX_LOCALEDIR");
-               if (locale_dir.empty())
-                       locale_dir = lyx_localedir();
-       }
-       return locale_dir;
-}
+#ifdef ENABLE_NLS
 
-} // anon namespace
 
 #if 0
 
-#include <locale>
+-#include <locale>
 
 // This version of the Pimpl utilizes the message capability of
 // libstdc++ that is distributed with GNU G++.
@@ -53,7 +42,7 @@ public:
                //lyxerr << "Messages: language(" << l
                //       << ") in dir(" << dir << ")" << std::endl;
 
-               cat_gl = mssg_gl.open(PACKAGE, loc_gl, getLocaleDir().c_str());
+               cat_gl = mssg_gl.open(PACKAGE, loc_gl, lyx_localedir().c_str());
 
        }
 
@@ -97,8 +86,6 @@ public:
                //lyxerr << "Messages: language(" << l
                //       << ") in dir(" << dir << ")" << std::endl;
 
-             bindtextdomain(PACKAGE, getLocaleDir().c_str());
-             textdomain(PACKAGE);
        }
 
        ~Pimpl() {}
@@ -110,12 +97,27 @@ public:
 
                char * old = strdup(setlocale(LC_ALL, 0));
                char * n = setlocale(LC_ALL, lang_.c_str());
+               bindtextdomain(PACKAGE, lyx_localedir().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:
        ///