Take this better patch without using an extern global variable.
regards Uwe
Index: preamble.cpp =================================================================== --- preamble.cpp (revision 22040) +++ preamble.cpp (working copy) @@ -9,8 +9,6 @@ * Full author contact details are available in file CREDITS. */ -// {[( - #include <config.h> #include "tex2lyx.h" @@ -361,6 +359,9 @@ << "\\begin_body\n"; // clear preamble for subdocuments h_preamble.str(""); + + // store the document language to be used in text.cpp + setDocumentLanguage(h_language); } } // anonymous namespace @@ -625,7 +626,5 @@ return textclass; } -// }]) - } // namespace lyx Index: tex2lyx.cpp =================================================================== --- tex2lyx.cpp (revision 22021) +++ tex2lyx.cpp (working copy) @@ -126,7 +126,21 @@ return active_environments.empty() ? string() : active_environments.back(); } +// the document's main language +string document_language; + +string getDocumentLanguage() +{ + return document_language; +} + + +void setDocumentLanguage(string const & lang) +{ + document_language = lang; +} + CommandMap known_commands; CommandMap known_environments; CommandMap known_math_environments; Index: tex2lyx.h =================================================================== --- tex2lyx.h (revision 22021) +++ tex2lyx.h (working copy) @@ -85,6 +85,10 @@ extern std::vector<std::string> active_environments; std::string active_environment(); +// to store the document language +std::string getDocumentLanguage(); +void setDocumentLanguage(std::string const & lang); + enum ArgumentType { required, verbatim, Index: text.cpp =================================================================== --- text.cpp (revision 22032) +++ text.cpp (working copy) @@ -52,7 +52,11 @@ using support::contains; using support::subst; +// to store the current selectlanguage to be used after \foreignlanguage +// or \end{otherlanguage} +string selectlang; + void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer, Context const & context) { @@ -810,6 +814,21 @@ p.skip_spaces(); } + else if (name == "otherlanguage") { + eat_whitespace(p, os, parent_context, false); + // We must begin a new paragraph if not already done + parent_context.check_layout(os); + // switch to given language + os << "\\lang " << subst(p.verbatim_item(), "\n", " ") << "\n"; + // write text + parse_text(p, os, FLAG_END, outer, parent_context); + // switch back to former used language + if (!selectlang.empty()) + parent_context.add_extra_stuff("\n\\lang " + selectlang); + else + parent_context.add_extra_stuff("\n\\lang " + getDocumentLanguage()); + } + else if (!parent_context.new_layout_allowed) parse_unknown_environment(p, name, os, FLAG_END, outer, parent_context); @@ -1130,8 +1149,6 @@ Context & context) { LayoutPtr newlayout; - // store the current selectlanguage to be used after \foreignlanguage - string selectlang; // Store the latest bibliographystyle (needed for bibtex inset) string bibliographystyle; bool const use_natbib = used_packages.find("natbib") != used_packages.end();