The branch, 2.0.x, has been updated. - Log -----------------------------------------------------------------
commit 5bb18ffea7bf7356ec385c409e36948269de8416 Author: Julien Rioux <[email protected]> Date: Mon Jan 14 15:25:26 2013 +0100 Better fix for #7732: Use buffer.B_(). Also handle "and others" which is translated by BibTeX to "et al.". diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index cd707c1..d01cc32 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(); @@ -243,18 +243,33 @@ docstring const BibTeXInfo::getAbbreviatedAuthor(string lang) const vector<docstring> const authors = getVectorFromString(author, from_ascii(" and ")); - if (authors.size() == 2) - return bformat(translateIfPossible(from_ascii("%1$s and %2$s"), lang), + if (authors.size() == 2 && authors[1] != "others") + 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), + if (authors.size() >= 2) + return bformat(from_ascii("%1$s et al."), 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) + return bformat(buf.B_("%1$s and %2$s"), authors[0], authors[1]); + docstring::size_type const idx = author.rfind(from_ascii(" et al.")); + if (idx != docstring::npos) + return bformat(buf.B_("%1$s et al."), author.substr(0, idx)); + return author; +} + + docstring const BibTeXInfo::getYear() const { if (is_bibtex_) @@ -635,13 +650,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 +670,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 +682,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 +696,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 +750,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 +809,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()) ----------------------------------------------------------------------- Summary of changes: src/BiblioInfo.cpp | 54 +++++++++++++++++++++++++++++------------ src/BiblioInfo.h | 20 ++++++++++++--- src/insets/InsetBibtex.cpp | 4 +- src/insets/InsetCitation.cpp | 6 +--- 4 files changed, 58 insertions(+), 26 deletions(-) hooks/post-receive -- The LyX Source Repository
