]> git.lyx.org Git - lyx.git/blobdiff - src/Layout.cpp
Take into account file system case sensitivity when checking whether
[lyx.git] / src / Layout.cpp
index cbc1ab1899cf7b0186a4394849380399cc4aae68..d92345eed1ebb8e914e8672000c5094dbf089425 100644 (file)
 #include <config.h>
 
 #include "Layout.h"
+#include "Language.h"
 #include "TextClass.h"
 #include "Lexer.h"
 #include "Font.h"
 
+#include "support/Messages.h"
 #include "support/debug.h"
+#include "support/lassert.h"
 #include "support/lstrings.h"
 
+#include <boost/regex.hpp>
+
 using namespace std;
 using namespace lyx::support;
 
@@ -77,6 +82,8 @@ enum LayoutTags {
        LT_PARSKIP,
        //LT_PLAIN,
        LT_PREAMBLE,
+       LT_LANGPREAMBLE,
+       LT_BABELPREAMBLE,
        LT_REQUIRES,
        LT_RIGHTMARGIN,
        LT_SPACING,
@@ -132,6 +139,7 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
        LexerKeyword layoutTags[] = {
                { "align",          LT_ALIGN },
                { "alignpossible",  LT_ALIGNPOSSIBLE },
+               { "babelpreamble",  LT_BABELPREAMBLE },
                { "bottomsep",      LT_BOTTOMSEP },
                { "category",       LT_CATEGORY },
                { "commanddepth",   LT_COMMANDDEPTH },
@@ -158,6 +166,7 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                { "labelstringappendix", LT_LABELSTRING_APPENDIX },
                { "labeltag",       LT_LABELTAG },
                { "labeltype",      LT_LABELTYPE },
+               { "langpreamble",   LT_LANGPREAMBLE },
                { "latexname",      LT_LATEXNAME },
                { "latexparam",     LT_LATEXPARAM },
                { "latextype",      LT_LATEXTYPE },
@@ -196,7 +205,9 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                        lex.printError("Unknown layout tag `$$Token'");
                        error = true;
                        continue;
-               default: break;
+
+               default: 
+                       break;
                }
                switch (static_cast<LayoutTags>(le)) {
                case LT_END:            // end of structure
@@ -329,6 +340,14 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                        preamble_ = from_utf8(lex.getLongString("EndPreamble"));
                        break;
 
+               case LT_LANGPREAMBLE:
+                       langpreamble_ = from_utf8(lex.getLongString("EndLangPreamble"));
+                       break;
+
+               case LT_BABELPREAMBLE:
+                       babelpreamble_ = from_utf8(lex.getLongString("EndBabelPreamble"));
+                       break;
+
                case LT_LABELTYPE:
                        readLabelType(lex);
                        break;
@@ -404,7 +423,7 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                case LT_LABELSTRING:    // label string definition
                        // FIXME: this means LT_ENDLABELSTRING may only
                        // occur after LT_LABELSTRING
-                       lex >> labelstring_;    
+                       lex >> labelstring_;
                        labelstring_ = trim(labelstring_);
                        labelstring_appendix_ = labelstring_;
                        break;
@@ -763,6 +782,55 @@ docstring const & Layout::depends_on() const
 }
 
 
+namespace {
+
+docstring const i18npreamble(Language const * lang, docstring const & templ)
+{
+       if (templ.empty())
+               return templ;
+
+       string preamble = subst(to_utf8(templ), "$$lang", lang->babel());
+
+#ifdef TEX2LYX
+       // tex2lyx does not have getMessages()
+       LASSERT(false, /**/);
+#else
+       // FIXME UNICODE
+       // boost::regex is not unicode-safe.
+       // Should use QRegExp or (boost::u32regex, but that requires ICU)
+       static boost::regex const reg("_\\(([^\\)]+)\\)");
+       boost::smatch sub;
+       while (boost::regex_search(preamble, sub, reg)) {
+               string const key = sub.str(1);
+               string translated;
+               if (isAscii(key))
+                       translated = to_utf8(getMessages(lang->code()).get(key));
+               else {
+                       lyxerr << "Warning: not translating `" << key
+                              << "' because it is not pure ASCII." << endl;
+                       translated = key;
+               }
+               preamble = subst(preamble, sub.str(), translated);
+       }
+#endif
+       return from_utf8(preamble);
+}
+
+}
+
+
+docstring const Layout::langpreamble(Language const * lang) const
+{
+       return i18npreamble(lang, langpreamble_);
+}
+
+
+docstring const Layout::babelpreamble(Language const * lang) const
+{
+       return i18npreamble(lang, babelpreamble_);
+}
+
+
 bool Layout::operator==(Layout const & rhs) const
 {
        // This is enough for the applications we actually make,