I want to write a single BibLaTeX file to use in French as well as English documents. The only difference is that French titles must stay as they are in French documents, whereas in English documents, they should be translated.
It seems to me that this should be possible using BibLaTeX data annotations. The bibliographic file would be of the form:
@article{bibkey,
author = {...},
title = {Original title, possibly in French},
title+an:english = {="Translated title, if the original is in French"},
...
}
Then, if I am correct, I would need to override some macro, a bit like \mkbibcompletename in this thread where they use BibLaTeX data annotations to handle multiple author name formats. However, I could not find how to do this exactly in my case, be it in the BibLaTeX documentation, or on the Web.
EDIT: after having searched further, I think I should redefine the format of field title, using \DeclareFieldFormat. This is what I came up with, but it does not work : the English translation is not used even when available.
\documentclass{article}
\usepackage{iflang}
\usepackage[english]{babel}
\usepackage{biblatex}
\usepackage{filecontents}
\begin{filecontents}{biblio.bib}
@article{test1,
author = {Author, A.},
title = {Original title, possibly in French},
title+an:english = {="Translated title, if the original is in French"},
year = {1999},
}
@article{test2,
author = {Author, A.},
title = {Original title, possibly in French},
year = {2000},
}
\end{filecontents}
\addbibresource{biblio.bib}
\DeclareFieldFormat*{title}{%
\IfLanguageName{french}
{#1}
{\hasfieldannotation[english]
{\getfieldannotation[english]}
{#1}}}
\begin{document}
\autocite{test1,test2}
\printbibliography
\end{document}
I expect the first reference to contain the English title, and the second to contain the original title.