On 12/01/2013 11:34 AM, Jürgen Spitzmüller wrote:
Julien Rioux wrote:
The goal is to translate these strings (using mo database) to the
document language.

Then Buffer::B_() is the correct approach.

Jürgen


Does something like the attached patch (for branch) look OK?

Regards,
Julien
>From a8f5a42b4c27cf2c6405c023cbb13ab519336853 Mon Sep 17 00:00:00 2001
From: Julien Rioux <jri...@lyx.org>
Date: Mon, 14 Jan 2013 15:25:26 +0100
Subject: [PATCH] Better fix for #7732: Use buffer.B_().

---
 src/BiblioInfo.cpp           |   49 ++++++++++++++++++++++++++++++------------
 src/BiblioInfo.h             |   20 +++++++++++++---
 src/insets/InsetBibtex.cpp   |    4 +-
 src/insets/InsetCitation.cpp |    6 +---
 4 files changed, 55 insertions(+), 24 deletions(-)

diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index cd707c1..43b8662 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -212,7 +212,7 @@ BibTeXInfo::BibTeXInfo(docstring const & key, docstring const & type)
 {}
 
 
-docstring const BibTeXInfo::getAbbreviatedAuthor(string lang) const
+docstring const BibTeXInfo::getAbbreviatedAuthor() const
 {
 	if (!is_bibtex_) {
 		docstring const opt = label();
@@ -244,17 +244,31 @@ docstring const BibTeXInfo::getAbbreviatedAuthor(string lang) const
 		getVectorFromString(author, from_ascii(" and "));
 
 	if (authors.size() == 2)
-		return bformat(translateIfPossible(from_ascii("%1$s and %2$s"), lang),
+		return bformat(from_ascii("%1$s and %2$s"),
 			familyName(authors[0]), familyName(authors[1]));
 
 	if (authors.size() > 2)
-		return bformat(translateIfPossible(from_ascii("%1$s et al."), lang),
+		return bformat(from_ascii("%1$s and others"),
 			familyName(authors[0]));
 
 	return familyName(authors[0]);
 }
 
 
+docstring const BibTeXInfo::getAbbreviatedAuthor(Buffer const & buf) const
+{
+	docstring const author = getAbbreviatedAuthor();
+	if (!is_bibtex_)
+		return author;
+	vector<docstring> const authors = getVectorFromString(author, from_ascii(" and "));
+	if (authors.size() == 2 && authors[1] == "others")
+		return bformat(buf.B_("%1$s et al."), authors[0]);
+	if (authors.size() == 2)
+		return bformat(buf.B_("%1$s and %2$s"), authors[0], authors[1]);
+	return author;
+}
+
+
 docstring const BibTeXInfo::getYear() const
 {
 	if (is_bibtex_) 
@@ -635,13 +649,13 @@ vector<docstring> const BiblioInfo::getEntries() const
 }
 
 
-docstring const BiblioInfo::getAbbreviatedAuthor(docstring const & key, string lang) const
+docstring const BiblioInfo::getAbbreviatedAuthor(docstring const & key, Buffer const & buf) const
 {
 	BiblioInfo::const_iterator it = find(key);
 	if (it == end())
 		return docstring();
 	BibTeXInfo const & data = it->second;
-	return data.getAbbreviatedAuthor(lang);
+	return data.getAbbreviatedAuthor(buf);
 }
 
 
@@ -655,7 +669,7 @@ docstring const BiblioInfo::getCiteNumber(docstring const & key) const
 }
 
 
-docstring const BiblioInfo::getYear(docstring const & key, bool use_modifier, string lang) const
+docstring const BiblioInfo::getYear(docstring const & key, bool use_modifier) const
 {
 	BiblioInfo::const_iterator it = find(key);
 	if (it == end())
@@ -667,11 +681,11 @@ docstring const BiblioInfo::getYear(docstring const & key, bool use_modifier, st
 		docstring const xref = data.getXRef();
 		if (xref.empty())
 			// no luck
-			return translateIfPossible(from_ascii("No year"), lang);
+			return docstring();
 		BiblioInfo::const_iterator const xrefit = find(xref);
 		if (xrefit == end())
 			// no luck again
-			return translateIfPossible(from_ascii("No year"), lang);
+			return docstring();
 		BibTeXInfo const & xref_data = xrefit->second;
 		year = xref_data.getYear();
 	}
@@ -681,6 +695,15 @@ docstring const BiblioInfo::getYear(docstring const & key, bool use_modifier, st
 }
 
 
+docstring const BiblioInfo::getYear(docstring const & key, Buffer const & buf, bool use_modifier) const
+{
+	docstring const year = getYear(key, use_modifier);
+	if (year.empty())
+		return buf.B_("No year");
+	return year;
+}
+
+
 docstring const BiblioInfo::getInfo(docstring const & key, 
 	Buffer const & buf, bool richtext) const
 {
@@ -726,9 +749,8 @@ vector<docstring> const BiblioInfo::getNumericalStrings(
 	if (empty())
 		return vector<docstring>();
 
-	string const lang = buf.params().language->code();
-	docstring const author = getAbbreviatedAuthor(key, lang);
-	docstring const year   = getYear(key, true, lang);
+	docstring const author = getAbbreviatedAuthor(key, buf);
+	docstring const year   = getYear(key, buf, true);
 	if (author.empty() || year.empty())
 		return vector<docstring>();
 
@@ -786,9 +808,8 @@ vector<docstring> const BiblioInfo::getAuthorYearStrings(
 	if (empty())
 		return vector<docstring>();
 
-	string const lang = buf.params().language->code();
-	docstring const author = getAbbreviatedAuthor(key, lang);
-	docstring const year   = getYear(key, true, lang);
+	docstring const author = getAbbreviatedAuthor(key, buf);
+	docstring const year   = getYear(key, buf, true);
 	if (author.empty() || year.empty())
 		return vector<docstring>();
 
diff --git a/src/BiblioInfo.h b/src/BiblioInfo.h
index 29d910c..53ac254 100644
--- a/src/BiblioInfo.h
+++ b/src/BiblioInfo.h
@@ -53,8 +53,11 @@ public:
 	BibTeXInfo(bool ib) : is_bibtex_(ib) {}
 	/// constructor that sets the entryType
 	BibTeXInfo(docstring const & key, docstring const & type);
-	/// \return the short form of an authorlist
-	docstring const getAbbreviatedAuthor(std::string lang = "en") const;
+	/// \return the short form of an authorlist, used for sorting
+	docstring const getAbbreviatedAuthor() const;
+	/// \return the short form of an authorlist, translated to the
+	/// buffer language.
+	docstring const getAbbreviatedAuthor(Buffer const & buf) const;
 	/// 
 	docstring const getYear() const;
 	///
@@ -162,14 +165,23 @@ public:
 	/// \return a sorted vector of BibTeX entry types in use
 	std::vector<docstring> const getEntries() const;
 	/// \return the short form of an authorlist
-	docstring const getAbbreviatedAuthor(docstring const & key, std::string lang = "en") const;
+	docstring const getAbbreviatedAuthor(docstring const & key, Buffer const & buf) const;
 	/// \return the year from the bibtex data record for \param key
 	/// if \param use_modifier is true, then we will also append any
 	/// modifier for this entry (e.g., 1998b).
 	/// Note that this will get the year from the crossref if it's
 	/// not present in the record itself.	
 	docstring const getYear(docstring const & key,
-			bool use_modifier = false, std::string lang = "en") const;
+			bool use_modifier = false) const;
+	/// \return the year from the bibtex data record for \param key
+	/// if \param use_modifier is true, then we will also append any
+	/// modifier for this entry (e.g., 1998b).
+	/// Note that this will get the year from the crossref if it's
+	/// not present in the record itself.
+	/// If no year is found, \return "No year" translated to the buffer
+	/// language.
+	docstring const getYear(docstring const & key, Buffer const & buf,
+			bool use_modifier = false) const;
 	///
 	docstring const getCiteNumber(docstring const & key) const;
 	/// \return formatted BibTeX data associated with a given key.
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index abc7e0f..bc85399 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -962,10 +962,10 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
 		if (numbers)
 			citekey = entry.citeNumber();
 		else {
-			docstring const auth = entry.getAbbreviatedAuthor(l->code());
+			docstring const auth = entry.getAbbreviatedAuthor(buffer());
 			// we do it this way so as to access the xref, if necessary
 			// note that this also gives us the modifier
-			docstring const year = bibinfo.getYear(*vit, true, l->code());
+			docstring const year = bibinfo.getYear(*vit, buffer(), true);
 			if (!auth.empty() && !year.empty())
 				citekey = auth + ' ' + year;
 		}
diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index c8078b9..11362af 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -21,7 +21,6 @@
 #include "DispatchResult.h"
 #include "FuncCode.h"
 #include "FuncRequest.h"
-#include "Language.h"
 #include "LaTeXFeatures.h"
 #include "output_xhtml.h"
 #include "ParIterator.h"
@@ -271,7 +270,6 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
 	// CITE:	author/<before field>
 
 	CiteEngine const engine = buffer().params().citeEngine();
-	Language const * lang = buffer().params().language;
 	// We don't currently use the full or forceUCase fields.
 	string cite_type = asValidLatexCommand(getCmdName(), engine);
 	if (cite_type[0] == 'C')
@@ -334,8 +332,8 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
 	vector<docstring>::const_iterator end = keys.end();
 	for (; it != end; ++it) {
 		// get the bibdata corresponding to the key
-		docstring const author = biblist.getAbbreviatedAuthor(*it, lang->code());
-		docstring const year = biblist.getYear(*it, for_xhtml, lang->code());
+		docstring const author = biblist.getAbbreviatedAuthor(*it, buffer());
+		docstring const year = biblist.getYear(*it, buffer(), for_xhtml);
 		docstring const citenum = for_xhtml ? biblist.getCiteNumber(*it) : *it;
 
 		if (author.empty() || year.empty())
-- 
1.7.3.4

Reply via email to