The way this was previously, it had to fail if the GUI language

was not English: We return the the abbreviated author "One and Two",
but translated to the GUI language; then we search that for " and "
in order to pull the authors apart again.

I've just replaced the distinct routines with a single one that handles
both cases, depending upon whether a Buffer is provided as one argument.
This commit is contained in:
Richard Heck 2016-07-17 22:50:17 -04:00
parent d5633f17e5
commit fb84ccd9fb
2 changed files with 22 additions and 30 deletions

View File

@ -255,7 +255,8 @@ BibTeXInfo::BibTeXInfo(docstring const & key, docstring const & type)
{}
docstring const BibTeXInfo::getAbbreviatedAuthor(bool jurabib_style) const
docstring const BibTeXInfo::getAbbreviatedAuthor(
Buffer const * buf, bool jurabib_style) const
{
if (!is_bibtex_) {
docstring const opt = label();
@ -296,32 +297,23 @@ docstring const BibTeXInfo::getAbbreviatedAuthor(bool jurabib_style) const
docstring retval = familyName(authors[0]);
if (authors.size() == 2 && authors[1] != "others")
retval = bformat(from_ascii("%1$s and %2$s"),
familyName(authors[0]), familyName(authors[1]));
else if (authors.size() >= 2)
retval = bformat(from_ascii("%1$s et al."),
familyName(authors[0]));
if (authors.size() == 2 && authors[1] != "others") {
docstring const dformat = buf ?
buf->B_("%1$s and %2$s") : from_ascii("%1$s and %2$s");
retval = bformat(dformat, familyName(authors[0]), familyName(authors[1]));
} else if (authors.size() >= 2) {
// we get here either if the author list is longer than two names
// or if the second 'name' is "others". we do the same thing either
// way.
docstring const dformat = buf ?
buf->B_("%1$s et al.") : from_ascii("%1$s et al.");
retval = bformat(dformat, familyName(authors[0]));
}
return convertLaTeXCommands(retval);
}
docstring const BibTeXInfo::getAbbreviatedAuthor(Buffer const & buf, bool jurabib_style) const
{
docstring const author = getAbbreviatedAuthor(jurabib_style);
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_)
@ -719,12 +711,12 @@ docstring BibTeXInfo::getValueForKey(string const & oldkey, Buffer const & buf,
ret = cite_number_;
else if (key == "abbrvauthor")
// Special key to provide abbreviated author names.
ret = getAbbreviatedAuthor(buf, false);
ret = getAbbreviatedAuthor(&buf, false);
else if (key == "shortauthor")
// When shortauthor is not defined, jurabib automatically
// provides jurabib-style abbreviated author names. We do
// this as well.
ret = getAbbreviatedAuthor(buf, true);
ret = getAbbreviatedAuthor(&buf, true);
else if (key == "shorttitle") {
// When shorttitle is not defined, jurabib uses for `article'
// and `periodical' entries the form `journal volume [year]'
@ -821,7 +813,7 @@ docstring const BiblioInfo::getAbbreviatedAuthor(docstring const & key, Buffer c
if (it == end())
return docstring();
BibTeXInfo const & data = it->second;
return data.getAbbreviatedAuthor(buf, false);
return data.getAbbreviatedAuthor(&buf, false);
}
@ -1097,7 +1089,7 @@ void BiblioInfo::makeCitationLabels(Buffer const & buf)
if (numbers) {
entry.label(entry.citeNumber());
} else {
docstring const auth = entry.getAbbreviatedAuthor(buf, false);
docstring const auth = entry.getAbbreviatedAuthor(&buf, false);
// we do it this way so as to access the xref, if necessary
// note that this also gives us the modifier
docstring const year = getYear(*it, buf, true);

View File

@ -52,10 +52,10 @@ public:
/// constructor that sets the entryType
BibTeXInfo(docstring const & key, docstring const & type);
/// \return the short form of an authorlist, used for sorting
docstring const getAbbreviatedAuthor(bool jurabib_style = false) const;
/// \return the short form of an authorlist, translated to the
/// buffer language.
docstring const getAbbreviatedAuthor(Buffer const & buf, bool jurabib_style = false) const;
/// this will be translated to the UI language if buf is null
/// otherwise, it will be translated to the buffer language.
docstring const getAbbreviatedAuthor(
Buffer const * buf = 0, bool jurabib_style = false) const;
///
docstring const getYear() const;
///