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

This commit is contained in:
Julien Rioux 2013-01-07 15:51:19 +01:00
parent e04523f77b
commit e6aab49ff4
3 changed files with 28 additions and 21 deletions

View File

@ -6,6 +6,7 @@
* \author Angus Leeming
* \author Herbert Voß
* \author Richard Heck
* \author Julien Rioux
*
* Full author contact details are available in file CREDITS.
*/
@ -210,7 +211,7 @@ BibTeXInfo::BibTeXInfo(docstring const & key, docstring const & type)
{}
docstring const BibTeXInfo::getAbbreviatedAuthor(bool jurabib_style) const
docstring const BibTeXInfo::getAbbreviatedAuthor(bool jurabib_style, string lang) const
{
if (!is_bibtex_) {
docstring const opt = label();
@ -250,11 +251,12 @@ docstring const BibTeXInfo::getAbbreviatedAuthor(bool jurabib_style) const
}
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]);
}
@ -411,6 +413,7 @@ 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;
@ -445,10 +448,11 @@ docstring BibTeXInfo::expandFormat(string const & format,
string const val =
buf.params().documentClass().getCiteMacro(engine_type, key);
docstring const trans =
translateIfPossible(from_utf8(val), buf.params().language->code());
translateIfPossible(from_utf8(val), lang);
ret += trans;
} else {
docstring const val = getValueForKey(key, before, after, dialog, xref);
docstring const val =
getValueForKey(key, before, after, dialog, xref, lang);
ret += val;
}
} else {
@ -474,7 +478,8 @@ docstring BibTeXInfo::expandFormat(string const & format,
if (newfmt == fmt) // parse error
return _("ERROR!");
fmt = newfmt;
docstring const val = getValueForKey(optkey, before, after, dialog, xref);
docstring const val =
getValueForKey(optkey, before, after, dialog, xref, lang);
if (optkey == "next" && next)
ret += from_utf8(ifpart); // without expansion
else if (!val.empty())
@ -602,7 +607,7 @@ docstring const & BibTeXInfo::operator[](string const & field) const
docstring BibTeXInfo::getValueForKey(string const & key,
docstring const & before, docstring const & after, docstring const & dialog,
BibTeXInfo const * const xref) const
BibTeXInfo const * const xref, string lang) const
{
docstring ret = operator[](key);
if (ret.empty() && xref)
@ -621,12 +626,12 @@ docstring BibTeXInfo::getValueForKey(string const & key,
return label_;
else if (key == "abbrvauthor")
// Special key to provide abbreviated author names.
return getAbbreviatedAuthor();
return getAbbreviatedAuthor(false, lang);
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);
return getAbbreviatedAuthor(true, lang);
else if (key == "shorttitle") {
// When shorttitle is not defined, jurabib uses for `article'
// and `periodical' entries the form `journal volume [year]'
@ -701,13 +706,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(false, lang);
}
@ -721,7 +726,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())
@ -732,10 +737,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();
}
@ -984,4 +991,3 @@ string citationStyleToString(const CitationStyle & cs)
}
} // namespace lyx

View File

@ -7,6 +7,7 @@
* \author Angus Leeming
* \author Herbert Voß
* \author Richard Heck
* \author Julien Rioux
*
* Full author contact details are available in file CREDITS.
*/
@ -51,7 +52,7 @@ public:
/// 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) const;
docstring const getAbbreviatedAuthor(bool jurabib_style = false, std::string lang = "en") const;
///
docstring const getYear() const;
///
@ -110,7 +111,7 @@ private:
/// be the one referenced in the crossref field.
docstring getValueForKey(std::string const & key,
docstring const & before, docstring const & after, docstring const & dialog,
BibTeXInfo const * const xref = 0) const;
BibTeXInfo const * const xref = 0, std::string lang = "en") const;
/// replace %keys% in a format string with their values
/// called from getInfo()
/// format strings may contain:
@ -165,14 +166,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

@ -967,10 +967,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(false, 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;
}