* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
* \author Jean-Marc Lasgouttes
- * \author André Pönitz
+ * \author André Pönitz
*
* Full author contact details are available in file CREDITS.
*/
#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 <ostream>
+#include <boost/regex.hpp>
using namespace std;
using namespace lyx::support;
LT_LATEXPARAM,
LT_OPTARGS,
LT_LATEXTYPE,
- LT_LATEXHEADER,
- LT_LATEXFOOTER,
- LT_LATEXPARAGRAPH,
LT_LEFTMARGIN,
LT_NEED_PROTECT,
LT_NEWLINE,
LT_PARSKIP,
//LT_PLAIN,
LT_PREAMBLE,
+ LT_LANGPREAMBLE,
+ LT_BABELPREAMBLE,
LT_REQUIRES,
LT_RIGHTMARGIN,
LT_SPACING,
Layout::Layout()
{
+ unknown_ = false;
margintype = MARGIN_STATIC;
latextype = LATEX_PARAGRAPH;
intitle = false;
newline_allowed = true;
free_spacing = false;
pass_thru = false;
- is_environment = false;
toclevel = NOT_IN_TOC;
commanddepth = 0;
}
LexerKeyword layoutTags[] = {
{ "align", LT_ALIGN },
{ "alignpossible", LT_ALIGNPOSSIBLE },
+ { "babelpreamble", LT_BABELPREAMBLE },
{ "bottomsep", LT_BOTTOMSEP },
{ "category", LT_CATEGORY },
{ "commanddepth", LT_COMMANDDEPTH },
{ "labelstringappendix", LT_LABELSTRING_APPENDIX },
{ "labeltag", LT_LABELTAG },
{ "labeltype", LT_LABELTYPE },
- { "latexfooter", LT_LATEXFOOTER },
- { "latexheader", LT_LATEXHEADER },
+ { "langpreamble", LT_LANGPREAMBLE },
{ "latexname", LT_LATEXNAME },
- { "latexparagraph", LT_LATEXPARAGRAPH },
{ "latexparam", LT_LATEXPARAM },
{ "latextype", LT_LATEXTYPE },
{ "leftmargin", LT_LEFTMARGIN },
this->operator=(tclass[style]);
name_ = tmpname;
} else {
- lyxerr << "Cannot copy unknown style `"
- << to_utf8(style) << "'\n"
- << "All layouts so far:"
- << endl;
+ LYXERR0("Cannot copy unknown style `"
+ << style << "'\n"
+ << "All layouts so far:");
DocumentClass::const_iterator lit = tclass.begin();
DocumentClass::const_iterator len = tclass.end();
for (; lit != len; ++lit)
- lyxerr << to_utf8(lit->name()) << endl;
-
- //lex.printError("Cannot copy known "
- // "style `$$Token'");
+ LYXERR0(lit->name());
}
break;
}
if (obsoleted_by().empty())
obsoleted_by_ = style;
} else {
- lyxerr << "Cannot replace with unknown style `"
- << to_utf8(style) << '\'' << endl;
+ LYXERR0("Cannot replace with unknown style `"
+ << style << '\'');
//lex.printError("Cannot replace with"
// " unknown style "
readLatexType(lex);
break;
- case LT_LATEXHEADER: // header for environments
- lex >> latexheader;
- break;
-
- case LT_LATEXFOOTER: // footer for environments
- lex >> latexfooter;
- break;
-
- case LT_LATEXPARAGRAPH:
- lex >> latexparagraph;
- break;
-
case LT_INTITLE:
lex >> intitle;
break;
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;
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;
endlabeltype = static_cast<EndLabelType>(le);
break;
default:
- LYXERR0("Unhandled value " << le
- << " in Layout::readEndLabelType.");
+ LYXERR0("Unhandled value " << le);
break;
}
}
margintype = static_cast<MarginType>(le);
break;
default:
- lyxerr << "Unhandled value " << le
- << " in Layout::readMargin." << endl;
+ LYXERR0("Unhandled value " << le);
break;
}
}
latextype = static_cast<LatexType>(le);
break;
default:
- lyxerr << "Unhandled value " << le
- << " in Layout::readLatexType." << endl;
+ LYXERR0("Unhandled value " << le);
break;
}
}
}
+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,