Use document language when exporting citations to LyXHTML (fixes #7732).

This commit is contained in:
Julien Rioux 2012-03-08 18:03:50 +01:00
parent 832acf8f58
commit 62b1319752
5 changed files with 28 additions and 19 deletions

View File

@ -212,7 +212,7 @@ BibTeXInfo::BibTeXInfo(docstring const & key, docstring const & type)
{}
docstring const BibTeXInfo::getAbbreviatedAuthor() const
docstring const BibTeXInfo::getAbbreviatedAuthor(string lang) const
{
if (!is_bibtex_) {
docstring const opt = label();
@ -244,11 +244,12 @@ docstring const BibTeXInfo::getAbbreviatedAuthor() const
getVectorFromString(author, from_ascii(" and "));
if (authors.size() == 2)
return bformat(_("%1$s and %2$s"),
return bformat(translateIfPossible(from_ascii("%1$s and %2$s"), lang),
familyName(authors[0]), familyName(authors[1]));
if (authors.size() > 2)
return bformat(_("%1$s et al."), familyName(authors[0]));
return bformat(translateIfPossible(from_ascii("%1$s et al."), lang),
familyName(authors[0]));
return familyName(authors[0]);
}
@ -634,13 +635,13 @@ vector<docstring> const BiblioInfo::getEntries() const
}
docstring const BiblioInfo::getAbbreviatedAuthor(docstring const & key) const
docstring const BiblioInfo::getAbbreviatedAuthor(docstring const & key, string lang) const
{
BiblioInfo::const_iterator it = find(key);
if (it == end())
return docstring();
BibTeXInfo const & data = it->second;
return data.getAbbreviatedAuthor();
return data.getAbbreviatedAuthor(lang);
}
@ -654,7 +655,7 @@ docstring const BiblioInfo::getCiteNumber(docstring const & key) const
}
docstring const BiblioInfo::getYear(docstring const & key, bool use_modifier) const
docstring const BiblioInfo::getYear(docstring const & key, bool use_modifier, string lang) const
{
BiblioInfo::const_iterator it = find(key);
if (it == end())
@ -665,10 +666,12 @@ docstring const BiblioInfo::getYear(docstring const & key, bool use_modifier) co
// let's try the crossref
docstring const xref = data.getXRef();
if (xref.empty())
return _("No year"); // no luck
// no luck
return translateIfPossible(from_ascii("No year"), lang);
BiblioInfo::const_iterator const xrefit = find(xref);
if (xrefit == end())
return _("No year"); // no luck again
// no luck again
return translateIfPossible(from_ascii("No year"), lang);
BibTeXInfo const & xref_data = xrefit->second;
year = xref_data.getYear();
}
@ -723,8 +726,9 @@ vector<docstring> const BiblioInfo::getNumericalStrings(
if (empty())
return vector<docstring>();
docstring const author = getAbbreviatedAuthor(key);
docstring const year = getYear(key);
string const lang = buf.params().language->code();
docstring const author = getAbbreviatedAuthor(key, lang);
docstring const year = getYear(key, true, lang);
if (author.empty() || year.empty())
return vector<docstring>();
@ -782,8 +786,9 @@ vector<docstring> const BiblioInfo::getAuthorYearStrings(
if (empty())
return vector<docstring>();
docstring const author = getAbbreviatedAuthor(key);
docstring const year = getYear(key);
string const lang = buf.params().language->code();
docstring const author = getAbbreviatedAuthor(key, lang);
docstring const year = getYear(key, true, lang);
if (author.empty() || year.empty())
return vector<docstring>();

View File

@ -54,7 +54,7 @@ public:
/// constructor that sets the entryType
BibTeXInfo(docstring const & key, docstring const & type);
/// \return the short form of an authorlist
docstring const getAbbreviatedAuthor() const;
docstring const getAbbreviatedAuthor(std::string lang = "en") const;
///
docstring const getYear() const;
///
@ -162,14 +162,14 @@ 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) const;
docstring const getAbbreviatedAuthor(docstring const & key, std::string lang = "en") 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) const;
bool use_modifier = false, std::string lang = "en") const;
///
docstring const getCiteNumber(docstring const & key) const;
/// \return formatted BibTeX data associated with a given key.

View File

@ -958,10 +958,10 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
if (numbers)
citekey = entry.citeNumber();
else {
docstring const auth = entry.getAbbreviatedAuthor();
docstring const auth = entry.getAbbreviatedAuthor(l->code());
// 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);
docstring const year = bibinfo.getYear(*vit, true, l->code());
if (!auth.empty() && !year.empty())
citekey = auth + ' ' + year;
}

View File

@ -21,6 +21,7 @@
#include "DispatchResult.h"
#include "FuncCode.h"
#include "FuncRequest.h"
#include "Language.h"
#include "LaTeXFeatures.h"
#include "output_xhtml.h"
#include "ParIterator.h"
@ -259,6 +260,7 @@ 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')
@ -321,8 +323,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);
docstring const year = biblist.getYear(*it, for_xhtml);
docstring const author = biblist.getAbbreviatedAuthor(*it, lang->code());
docstring const year = biblist.getYear(*it, for_xhtml, lang->code());
docstring const citenum = for_xhtml ? biblist.getCiteNumber(*it) : *it;
if (author.empty() || year.empty())

View File

@ -96,6 +96,8 @@ What's new
- Fix the output of LyXHTML bibliography with richtext (bug 8486).
- Use document language when exporting citations to LyXHTML (bug 7732).
* USER INTERFACE