Georg, all,

as an attempt to please you and to fix bug #3332, I produced the attached patch :-)

The bad news: The translations to the buffer language do not work on my machine (Win XP) - all translations are made to the menu language, instead :-(

Could someone please check whether the patch works on Linux at least? E.g., if you open a Spanish doc in a German environment and export the doc as plain text, you shouldn't see any German inset labels.

Georg, is this what you had in mind? Any comments on the code itself?

Regards, Michael

PS: Since plaintext output partly depends on screen labels, some screen labels are also printed in the buffer's language now. Whether this is preferable, is a matter of taste, of course. From a logical point of view, it may make sense.
Index: src/insets/InsetCaption.cpp
===================================================================
--- src/insets/InsetCaption.cpp	(Revision 18124)
+++ src/insets/InsetCaption.cpp	(Arbeitskopie)
@@ -134,7 +134,7 @@
 	int const width_offset = TEXT_TO_INSET_OFFSET / 2;
 	mi.base.textwidth -= width_offset;
 
-	computeFullLabel();
+	computeFullLabel(*mi.base.bv->buffer());
 
 	labelwidth_ = theFontMetrics(mi.base.font).width(full_label_);
 	// add some space to separate the label from the inset text
@@ -257,7 +257,7 @@
 int InsetCaption::plaintext(Buffer const & buf, odocstream & os,
                             OutputParams const & runparams) const
 {
-	computeFullLabel();
+	computeFullLabel(buf);
 
 	os << '[' << full_label_ << "\n";
 	InsetText::plaintext(buf, os, runparams);
@@ -278,13 +278,13 @@
 }
 
 
-void InsetCaption::computeFullLabel() const
+void InsetCaption::computeFullLabel(Buffer const & buf) const
 {
 	if (type_.empty())
-		full_label_ = _("Senseless!!! ");
+		full_label_ = buf.B_("Senseless!!! ");
 	else {
 		docstring const number = convert<docstring>(counter_);
-		docstring label = custom_label_.empty()? _(type_): custom_label_;
+		docstring label = custom_label_.empty()? buf.B_(type_): custom_label_;
 		full_label_ = bformat(from_ascii("%1$s %2$s:"), label, number);
 	}
 }
Index: src/insets/InsetFoot.cpp
===================================================================
--- src/insets/InsetFoot.cpp	(Revision 18124)
+++ src/insets/InsetFoot.cpp	(Arbeitskopie)
@@ -13,6 +13,7 @@
 
 #include "InsetFoot.h"
 
+#include "Buffer.h"
 #include "gettext.h"
 // the following are needed just to get the layout of the enclosing
 // paragraph. This seems a bit too much to me (JMarc)
@@ -82,7 +83,7 @@
 int InsetFoot::plaintext(Buffer const & buf, odocstream & os,
                          OutputParams const & runparams) const
 {
-	os << '[' << _("footnote") << ":\n";
+	os << '[' << buf.B_("footnote") << ":\n";
 	InsetText::plaintext(buf, os, runparams);
 	os << "\n]";
 
Index: src/insets/InsetMarginal.cpp
===================================================================
--- src/insets/InsetMarginal.cpp	(Revision 18124)
+++ src/insets/InsetMarginal.cpp	(Arbeitskopie)
@@ -13,6 +13,7 @@
 
 #include "InsetMarginal.h"
 
+#include "Buffer.h"
 #include "gettext.h"
 #include "Paragraph.h"
 #include "OutputParams.h"
@@ -66,7 +67,7 @@
 int InsetMarginal::plaintext(Buffer const & buf, odocstream & os,
                              OutputParams const & runparams) const
 {
-	os << '[' << _("margin") << ":\n";
+	os << '[' << buf.B_("margin") << ":\n";
 	InsetText::plaintext(buf, os, runparams);
 	os << "\n]";
 
Index: src/insets/InsetBranch.cpp
===================================================================
--- src/insets/InsetBranch.cpp	(Revision 18124)
+++ src/insets/InsetBranch.cpp	(Arbeitskopie)
@@ -235,7 +235,7 @@
 	if (!isBranchSelected(buf))
 		return 0;
 
-	os << '[' << _("branch") << ' ' << params_.branch << ":\n";
+	os << '[' << buf.B_("branch") << ' ' << params_.branch << ":\n";
 	InsetText::plaintext(buf, os, runparams);
 	os << "\n]";
 
Index: src/insets/InsetGraphics.cpp
===================================================================
--- src/insets/InsetGraphics.cpp	(Revision 18124)
+++ src/insets/InsetGraphics.cpp	(Arbeitskopie)
@@ -807,7 +807,7 @@
 }
 
 
-int InsetGraphics::plaintext(Buffer const &, odocstream & os,
+int InsetGraphics::plaintext(Buffer const & buf, odocstream & os,
                              OutputParams const &) const
 {
 	// No graphics in ascii output. Possible to use gifscii to convert
@@ -818,7 +818,7 @@
 	// FIXME UNICODE
 	// FIXME: We have no idea what the encoding of the filename is
 
-	docstring const str = bformat(_("Graphics file: %1$s"),
+	docstring const str = bformat(buf.B_("Graphics file: %1$s"),
 	                              from_utf8(params().filename.absFilename()));
 	os << '<' << str << '>';
 
Index: src/insets/InsetCaption.h
===================================================================
--- src/insets/InsetCaption.h	(Revision 18124)
+++ src/insets/InsetCaption.h	(Arbeitskopie)
@@ -84,7 +84,7 @@
 
 private:
 	///
-	void computeFullLabel() const;
+	void computeFullLabel(Buffer const & buf) const;
 	///
 	virtual std::auto_ptr<Inset> doClone() const;
 	///
Index: src/insets/InsetNote.cpp
===================================================================
--- src/insets/InsetNote.cpp	(Revision 18124)
+++ src/insets/InsetNote.cpp	(Arbeitskopie)
@@ -14,6 +14,7 @@
 
 #include "InsetNote.h"
 
+#include "Buffer.h"
 #include "BufferView.h"
 #include "Cursor.h"
 #include "debug.h"
@@ -307,7 +308,7 @@
 		// Ignore files that are exported inside a comment
 		runparams.exportdata.reset(new ExportData);
 	}
-	os << '[' << _("note") << ":\n";
+	os << '[' << buf.B_("note") << ":\n";
 	InsetText::plaintext(buf, os, runparams);
 	os << "\n]";
 
Index: src/insets/InsetInclude.cpp
===================================================================
--- src/insets/InsetInclude.cpp	(Revision 18124)
+++ src/insets/InsetInclude.cpp	(Arbeitskopie)
@@ -294,22 +294,22 @@
 }
 
 
-docstring const InsetInclude::getScreenLabel(Buffer const &) const
+docstring const InsetInclude::getScreenLabel(Buffer const & buf) const
 {
 	docstring temp;
 
 	switch (type(params_)) {
 		case INPUT:
-			temp += _("Input");
+			temp += buf.B_("Input");
 			break;
 		case VERB:
-			temp += _("Verbatim Input");
+			temp += buf.B_("Verbatim Input");
 			break;
 		case VERBAST:
-			temp += _("Verbatim Input*");
+			temp += buf.B_("Verbatim Input*");
 			break;
 		case INCLUDE:
-			temp += _("Include");
+			temp += buf.B_("Include");
 			break;
 	}
 
Index: src/insets/InsetFloat.cpp
===================================================================
--- src/insets/InsetFloat.cpp	(Revision 18124)
+++ src/insets/InsetFloat.cpp	(Arbeitskopie)
@@ -330,7 +330,7 @@
 int InsetFloat::plaintext(Buffer const & buf, odocstream & os,
                           OutputParams const & runparams) const
 {
-	os << '[' << _("float") << ' ' << floatName(params_.type, buf.params()) << ":\n";
+	os << '[' << buf.B_("float") << ' ' << floatName(params_.type, buf.params()) << ":\n";
 	InsetText::plaintext(buf, os, runparams);
 	os << "\n]";
 
Index: src/insets/InsetCollapsable.cpp
===================================================================
--- src/insets/InsetCollapsable.cpp	(Revision 18124)
+++ src/insets/InsetCollapsable.cpp	(Arbeitskopie)
@@ -458,7 +458,7 @@
 	FloatList const & floats = bp.getTextClass().floats();
 	FloatList::const_iterator it = floats[type];
 	// FIXME UNICODE
-	return (it == floats.end()) ? from_ascii(type) : _(it->second.name());
+	return (it == floats.end()) ? from_ascii(type) : bp.B_(it->second.name());
 }
 
 
Index: src/insets/InsetWrap.cpp
===================================================================
--- src/insets/InsetWrap.cpp	(Revision 18124)
+++ src/insets/InsetWrap.cpp	(Arbeitskopie)
@@ -194,7 +194,7 @@
 int InsetWrap::plaintext(Buffer const & buf, odocstream & os,
                          OutputParams const & runparams) const
 {
-	os << '[' << _("wrap") << ' ' << floatName(params_.type, buf.params()) << ":\n";
+	os << '[' << buf.B_("wrap") << ' ' << floatName(params_.type, buf.params()) << ":\n";
 	InsetText::plaintext(buf, os, runparams);
 	os << "\n]";
 
Index: src/insets/InsetCommand.cpp
===================================================================
--- src/insets/InsetCommand.cpp	(Revision 18124)
+++ src/insets/InsetCommand.cpp	(Arbeitskopie)
@@ -13,6 +13,7 @@
 
 #include "InsetCommand.h"
 
+#include "Buffer.h"
 #include "BufferView.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
@@ -92,10 +93,10 @@
 }
 
 
-int InsetCommand::plaintext(Buffer const &, odocstream & os,
+int InsetCommand::plaintext(Buffer const & buf, odocstream & os,
                             OutputParams const &) const
 {
-	docstring const str = "[" + _("LaTeX Command: ") + from_utf8(getCmdName()) + "]";
+	docstring const str = "[" + buf.B_("LaTeX Command: ") + from_utf8(getCmdName()) + "]";
 	os << str;
 	return str.size();
 }
Index: src/insets/InsetTOC.cpp
===================================================================
--- src/insets/InsetTOC.cpp	(Revision 18124)
+++ src/insets/InsetTOC.cpp	(Arbeitskopie)
@@ -40,11 +40,11 @@
 }
 
 
-docstring const InsetTOC::getScreenLabel(Buffer const &) const
+docstring const InsetTOC::getScreenLabel(Buffer const & buf) const
 {
 	if (getCmdName() == "tableofcontents")
-		return _("Table of Contents");
-	return _("Unknown toc list");
+		return buf.B_("Table of Contents");
+	return _("Unknown TOC type");
 }
 
 
Index: src/mathed/MathMacroTemplate.cpp
===================================================================
--- src/mathed/MathMacroTemplate.cpp	(Revision 18124)
+++ src/mathed/MathMacroTemplate.cpp	(Arbeitskopie)
@@ -15,6 +15,7 @@
 #include "MathParser.h"
 #include "MathSupport.h"
 
+#include "Buffer.h"
 #include "Cursor.h"
 #include "debug.h"
 #include "gettext.h"
@@ -234,10 +235,10 @@
 }
 
 
-int MathMacroTemplate::plaintext(Buffer const &, odocstream & os,
+int MathMacroTemplate::plaintext(Buffer const & buf, odocstream & os,
                                  OutputParams const &) const
 {
-	static docstring const str = '[' + _("math macro") + ']';
+	static docstring const str = '[' + buf.B_("math macro") + ']';
 
 	os << str;
 	return str.size();
Index: src/BufferParams.h
===================================================================
--- src/BufferParams.h	(Revision 18124)
+++ src/BufferParams.h	(Arbeitskopie)
@@ -60,6 +60,9 @@
 	BufferParams();
 	~BufferParams();
 
+	/// get l10n translated to the buffers language
+	docstring const B_(std::string const & l10n) const;
+
 	/// read a header token, if unrecognised, return it or an unknown class name
 	std::string const readToken(Lexer & lex, std::string const & token);
 
Index: src/output_plaintext.cpp
===================================================================
--- src/output_plaintext.cpp	(Revision 18124)
+++ src/output_plaintext.cpp	(Arbeitskopie)
@@ -142,10 +142,10 @@
 
 	case 6: // Abstract
 		if (runparams.linelen > 0) {
-			os << _("Abstract") << "\n\n";
+			os << buf.B_("Abstract") << "\n\n";
 			currlinelen = 0;
 		} else {
-			docstring const abst = _("Abstract: ");
+			docstring const abst = buf.B_("Abstract: ");
 			os << abst;
 			currlinelen += abst.length();
 		}
@@ -154,10 +154,10 @@
 	case 7: // Bibliography
 		if (!ref_printed) {
 			if (runparams.linelen > 0) {
-				os << _("References") << "\n\n";
+				os << buf.B_("References") << "\n\n";
 				currlinelen = 0;
 			} else {
-				docstring const refs = _("References: ");
+				docstring const refs = buf.B_("References: ");
 				os << refs;
 				currlinelen += refs.length();
 			}
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(Revision 18124)
+++ src/Buffer.cpp	(Arbeitskopie)
@@ -1451,11 +1451,7 @@
 
 docstring const Buffer::B_(string const & l10n) const
 {
-	Language const * lang = pimpl_->params.language;
-	if (lang)
-		return getMessages(lang->code()).get(l10n);
-
-	return _(l10n);
+	return params().B_(l10n);
 }
 
 
Index: src/BufferParams.cpp
===================================================================
--- src/BufferParams.cpp	(Revision 18124)
+++ src/BufferParams.cpp	(Arbeitskopie)
@@ -25,6 +25,7 @@
 #include "gettext.h"
 #include "Language.h"
 #include "LaTeXFeatures.h"
+#include "Messages.h"
 #include "Color.h"
 #include "Font.h"
 #include "Lexer.h"
@@ -335,6 +336,13 @@
 {}
 
 
+docstring const BufferParams::B_(string const & l10n) const
+{
+	BOOST_ASSERT(language);
+	return getMessages(language->code()).get(l10n);
+}
+
+
 AuthorList & BufferParams::authors()
 {
 	return pimpl_->authorlist;

Reply via email to