mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Better fix for #7732: Use buffer.B_().
Also handle "and others" which is translated by BibTeX to "et al.".
This commit is contained in:
parent
de59722ba4
commit
3f8de8fe92
@ -254,7 +254,7 @@ BibTeXInfo::BibTeXInfo(docstring const & key, docstring const & type)
|
||||
{}
|
||||
|
||||
|
||||
docstring const BibTeXInfo::getAbbreviatedAuthor(bool jurabib_style, string lang) const
|
||||
docstring const BibTeXInfo::getAbbreviatedAuthor(bool jurabib_style) const
|
||||
{
|
||||
if (!is_bibtex_) {
|
||||
docstring const opt = label();
|
||||
@ -293,18 +293,33 @@ docstring const BibTeXInfo::getAbbreviatedAuthor(bool jurabib_style, string lang
|
||||
return shortauthor;
|
||||
}
|
||||
|
||||
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, 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_)
|
||||
@ -456,7 +471,6 @@ docstring BibTeXInfo::expandFormat(string const & format,
|
||||
static int max_passes = 5000;
|
||||
docstring ret; // return value
|
||||
string key;
|
||||
string lang = buf.params().language->code();
|
||||
bool scanning_key = false;
|
||||
bool scanning_rich = false;
|
||||
|
||||
@ -480,8 +494,6 @@ docstring BibTeXInfo::expandFormat(string const & format,
|
||||
// so we replace the key with its value, which may be empty
|
||||
if (key[0] == '!') {
|
||||
// macro
|
||||
// FIXME: instead of passing the buf, just past the macros
|
||||
// FIXME: and the language code
|
||||
string const val =
|
||||
buf.params().documentClass().getCiteMacro(engine_type, key);
|
||||
fmt = val + fmt.substr(1);
|
||||
@ -491,11 +503,11 @@ docstring BibTeXInfo::expandFormat(string const & format,
|
||||
string const val =
|
||||
buf.params().documentClass().getCiteMacro(engine_type, key);
|
||||
docstring const trans =
|
||||
translateIfPossible(from_utf8(val), lang);
|
||||
translateIfPossible(from_utf8(val), buf.params().language->code());
|
||||
ret += trans;
|
||||
} else {
|
||||
docstring const val =
|
||||
getValueForKey(key, before, after, dialog, xref, lang);
|
||||
getValueForKey(key, buf, before, after, dialog, xref);
|
||||
if (!scanning_rich)
|
||||
ret += from_ascii("{!<span class=\"bib-" + key + "\">!}");
|
||||
ret += val;
|
||||
@ -526,7 +538,7 @@ docstring BibTeXInfo::expandFormat(string const & format,
|
||||
return _("ERROR!");
|
||||
fmt = newfmt;
|
||||
docstring const val =
|
||||
getValueForKey(optkey, before, after, dialog, xref, lang);
|
||||
getValueForKey(optkey, buf, before, after, dialog, xref);
|
||||
if (optkey == "next" && next)
|
||||
ret += from_utf8(ifpart); // without expansion
|
||||
else if (!val.empty())
|
||||
@ -649,9 +661,9 @@ docstring const & BibTeXInfo::operator[](string const & field) const
|
||||
}
|
||||
|
||||
|
||||
docstring BibTeXInfo::getValueForKey(string const & key,
|
||||
docstring BibTeXInfo::getValueForKey(string const & key, Buffer const & buf,
|
||||
docstring const & before, docstring const & after, docstring const & dialog,
|
||||
BibTeXInfo const * const xref, string lang) const
|
||||
BibTeXInfo const * const xref) const
|
||||
{
|
||||
docstring ret = operator[](key);
|
||||
if (ret.empty() && xref)
|
||||
@ -670,12 +682,12 @@ docstring BibTeXInfo::getValueForKey(string const & key,
|
||||
return label_;
|
||||
else if (key == "abbrvauthor")
|
||||
// Special key to provide abbreviated author names.
|
||||
return getAbbreviatedAuthor(false, lang);
|
||||
return 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.
|
||||
return getAbbreviatedAuthor(true, lang);
|
||||
return getAbbreviatedAuthor(buf, true);
|
||||
else if (key == "shorttitle") {
|
||||
// When shorttitle is not defined, jurabib uses for `article'
|
||||
// and `periodical' entries the form `journal volume [year]'
|
||||
@ -750,13 +762,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(false, lang);
|
||||
return data.getAbbreviatedAuthor(buf, false);
|
||||
}
|
||||
|
||||
|
||||
@ -770,7 +782,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())
|
||||
@ -782,11 +794,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();
|
||||
}
|
||||
@ -796,6 +808,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
|
||||
{
|
||||
|
@ -51,8 +51,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(bool jurabib_style = false, std::string lang = "en") const;
|
||||
/// \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;
|
||||
///
|
||||
docstring const getYear() const;
|
||||
///
|
||||
@ -109,9 +112,9 @@ private:
|
||||
/// like operator[], except, if the field is empty, it will attempt
|
||||
/// to get the data from xref BibTeXInfo object, which would normally
|
||||
/// be the one referenced in the crossref field.
|
||||
docstring getValueForKey(std::string const & key,
|
||||
docstring getValueForKey(std::string const & key, Buffer const & buf,
|
||||
docstring const & before, docstring const & after, docstring const & dialog,
|
||||
BibTeXInfo const * const xref = 0, std::string lang = "en") const;
|
||||
BibTeXInfo const * const xref = 0) const;
|
||||
/// replace %keys% in a format string with their values
|
||||
/// called from getInfo()
|
||||
/// format strings may contain:
|
||||
@ -171,14 +174,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.
|
||||
|
@ -967,10 +967,10 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
|
||||
if (numbers)
|
||||
citekey = entry.citeNumber();
|
||||
else {
|
||||
docstring const auth = entry.getAbbreviatedAuthor(false, l->code());
|
||||
docstring const auth = entry.getAbbreviatedAuthor(buffer(), 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 = bibinfo.getYear(*vit, true, l->code());
|
||||
docstring const year = bibinfo.getYear(*vit, buffer(), true);
|
||||
if (!auth.empty() && !year.empty())
|
||||
citekey = auth + ' ' + year;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user