mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-28 03:50:00 +00:00
Use document language when exporting citations to LyXHTML (fixes #7732).
This commit is contained in:
parent
e04523f77b
commit
e6aab49ff4
@ -6,6 +6,7 @@
|
|||||||
* \author Angus Leeming
|
* \author Angus Leeming
|
||||||
* \author Herbert Voß
|
* \author Herbert Voß
|
||||||
* \author Richard Heck
|
* \author Richard Heck
|
||||||
|
* \author Julien Rioux
|
||||||
*
|
*
|
||||||
* Full author contact details are available in file CREDITS.
|
* 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_) {
|
if (!is_bibtex_) {
|
||||||
docstring const opt = label();
|
docstring const opt = label();
|
||||||
@ -250,11 +251,12 @@ docstring const BibTeXInfo::getAbbreviatedAuthor(bool jurabib_style) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (authors.size() == 2)
|
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]));
|
familyName(authors[0]), familyName(authors[1]));
|
||||||
|
|
||||||
if (authors.size() > 2)
|
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]);
|
return familyName(authors[0]);
|
||||||
}
|
}
|
||||||
@ -411,6 +413,7 @@ docstring BibTeXInfo::expandFormat(string const & format,
|
|||||||
static int max_passes = 5000;
|
static int max_passes = 5000;
|
||||||
docstring ret; // return value
|
docstring ret; // return value
|
||||||
string key;
|
string key;
|
||||||
|
string lang = buf.params().language->code();
|
||||||
bool scanning_key = false;
|
bool scanning_key = false;
|
||||||
bool scanning_rich = false;
|
bool scanning_rich = false;
|
||||||
|
|
||||||
@ -445,10 +448,11 @@ docstring BibTeXInfo::expandFormat(string const & format,
|
|||||||
string const val =
|
string const val =
|
||||||
buf.params().documentClass().getCiteMacro(engine_type, key);
|
buf.params().documentClass().getCiteMacro(engine_type, key);
|
||||||
docstring const trans =
|
docstring const trans =
|
||||||
translateIfPossible(from_utf8(val), buf.params().language->code());
|
translateIfPossible(from_utf8(val), lang);
|
||||||
ret += trans;
|
ret += trans;
|
||||||
} else {
|
} else {
|
||||||
docstring const val = getValueForKey(key, before, after, dialog, xref);
|
docstring const val =
|
||||||
|
getValueForKey(key, before, after, dialog, xref, lang);
|
||||||
ret += val;
|
ret += val;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -474,7 +478,8 @@ docstring BibTeXInfo::expandFormat(string const & format,
|
|||||||
if (newfmt == fmt) // parse error
|
if (newfmt == fmt) // parse error
|
||||||
return _("ERROR!");
|
return _("ERROR!");
|
||||||
fmt = newfmt;
|
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)
|
if (optkey == "next" && next)
|
||||||
ret += from_utf8(ifpart); // without expansion
|
ret += from_utf8(ifpart); // without expansion
|
||||||
else if (!val.empty())
|
else if (!val.empty())
|
||||||
@ -602,7 +607,7 @@ docstring const & BibTeXInfo::operator[](string const & field) const
|
|||||||
|
|
||||||
docstring BibTeXInfo::getValueForKey(string const & key,
|
docstring BibTeXInfo::getValueForKey(string const & key,
|
||||||
docstring const & before, docstring const & after, docstring const & dialog,
|
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);
|
docstring ret = operator[](key);
|
||||||
if (ret.empty() && xref)
|
if (ret.empty() && xref)
|
||||||
@ -621,12 +626,12 @@ docstring BibTeXInfo::getValueForKey(string const & key,
|
|||||||
return label_;
|
return label_;
|
||||||
else if (key == "abbrvauthor")
|
else if (key == "abbrvauthor")
|
||||||
// Special key to provide abbreviated author names.
|
// Special key to provide abbreviated author names.
|
||||||
return getAbbreviatedAuthor();
|
return getAbbreviatedAuthor(false, lang);
|
||||||
else if (key == "shortauthor")
|
else if (key == "shortauthor")
|
||||||
// When shortauthor is not defined, jurabib automatically
|
// When shortauthor is not defined, jurabib automatically
|
||||||
// provides jurabib-style abbreviated author names. We do
|
// provides jurabib-style abbreviated author names. We do
|
||||||
// this as well.
|
// this as well.
|
||||||
return getAbbreviatedAuthor(true);
|
return getAbbreviatedAuthor(true, lang);
|
||||||
else if (key == "shorttitle") {
|
else if (key == "shorttitle") {
|
||||||
// When shorttitle is not defined, jurabib uses for `article'
|
// When shorttitle is not defined, jurabib uses for `article'
|
||||||
// and `periodical' entries the form `journal volume [year]'
|
// 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);
|
BiblioInfo::const_iterator it = find(key);
|
||||||
if (it == end())
|
if (it == end())
|
||||||
return docstring();
|
return docstring();
|
||||||
BibTeXInfo const & data = it->second;
|
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);
|
BiblioInfo::const_iterator it = find(key);
|
||||||
if (it == end())
|
if (it == end())
|
||||||
@ -732,10 +737,12 @@ docstring const BiblioInfo::getYear(docstring const & key, bool use_modifier) co
|
|||||||
// let's try the crossref
|
// let's try the crossref
|
||||||
docstring const xref = data.getXRef();
|
docstring const xref = data.getXRef();
|
||||||
if (xref.empty())
|
if (xref.empty())
|
||||||
return _("No year"); // no luck
|
// no luck
|
||||||
|
return translateIfPossible(from_ascii("No year"), lang);
|
||||||
BiblioInfo::const_iterator const xrefit = find(xref);
|
BiblioInfo::const_iterator const xrefit = find(xref);
|
||||||
if (xrefit == end())
|
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;
|
BibTeXInfo const & xref_data = xrefit->second;
|
||||||
year = xref_data.getYear();
|
year = xref_data.getYear();
|
||||||
}
|
}
|
||||||
@ -984,4 +991,3 @@ string citationStyleToString(const CitationStyle & cs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
* \author Angus Leeming
|
* \author Angus Leeming
|
||||||
* \author Herbert Voß
|
* \author Herbert Voß
|
||||||
* \author Richard Heck
|
* \author Richard Heck
|
||||||
|
* \author Julien Rioux
|
||||||
*
|
*
|
||||||
* Full author contact details are available in file CREDITS.
|
* Full author contact details are available in file CREDITS.
|
||||||
*/
|
*/
|
||||||
@ -51,7 +52,7 @@ public:
|
|||||||
/// constructor that sets the entryType
|
/// constructor that sets the entryType
|
||||||
BibTeXInfo(docstring const & key, docstring const & type);
|
BibTeXInfo(docstring const & key, docstring const & type);
|
||||||
/// \return the short form of an authorlist
|
/// \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;
|
docstring const getYear() const;
|
||||||
///
|
///
|
||||||
@ -110,7 +111,7 @@ private:
|
|||||||
/// be the one referenced in the crossref field.
|
/// be the one referenced in the crossref field.
|
||||||
docstring getValueForKey(std::string const & key,
|
docstring getValueForKey(std::string const & key,
|
||||||
docstring const & before, docstring const & after, docstring const & dialog,
|
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
|
/// replace %keys% in a format string with their values
|
||||||
/// called from getInfo()
|
/// called from getInfo()
|
||||||
/// format strings may contain:
|
/// format strings may contain:
|
||||||
@ -165,14 +166,14 @@ public:
|
|||||||
/// \return a sorted vector of BibTeX entry types in use
|
/// \return a sorted vector of BibTeX entry types in use
|
||||||
std::vector<docstring> const getEntries() const;
|
std::vector<docstring> const getEntries() const;
|
||||||
/// \return the short form of an authorlist
|
/// \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
|
/// \return the year from the bibtex data record for \param key
|
||||||
/// if \param use_modifier is true, then we will also append any
|
/// if \param use_modifier is true, then we will also append any
|
||||||
/// modifier for this entry (e.g., 1998b).
|
/// modifier for this entry (e.g., 1998b).
|
||||||
/// Note that this will get the year from the crossref if it's
|
/// Note that this will get the year from the crossref if it's
|
||||||
/// not present in the record itself.
|
/// not present in the record itself.
|
||||||
docstring const getYear(docstring const & key,
|
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;
|
docstring const getCiteNumber(docstring const & key) const;
|
||||||
/// \return formatted BibTeX data associated with a given key.
|
/// \return formatted BibTeX data associated with a given key.
|
||||||
|
@ -967,10 +967,10 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
|
|||||||
if (numbers)
|
if (numbers)
|
||||||
citekey = entry.citeNumber();
|
citekey = entry.citeNumber();
|
||||||
else {
|
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
|
// we do it this way so as to access the xref, if necessary
|
||||||
// note that this also gives us the modifier
|
// 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())
|
if (!auth.empty() && !year.empty())
|
||||||
citekey = auth + ' ' + year;
|
citekey = auth + ' ' + year;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user