5

Generally, we can do the localization by setting the language key in each .bib entry and using \DeclareBibliographyStrings(BibLaTeX Document, p.204).

Mendeley can generate .bib resources, but there is no way to include the language key in each entry.

My question is how to change the BibLaTeX references format for each language without a language key.

I know that BibTeX can get the multiple .bib resources. Can BibLaTeX use different format settings in each .bib resource? Or, is there any suggestion in order to do the localization without a language key?

1 Answers1

6

Obviously it would be best for Mendeley to just allow to add the langid field for convenient language switching.

If you cannot have that, you might organise your bibliography in .bib files by language. You then can add the langid field for each entry like this

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \perdatasource{\jobname-en.bib}
      \step[fieldset=langid, fieldvalue={english}]
    }
    \map{
      \perdatasource{\jobname-de.bib}
      \step[fieldset=langid, fieldvalue={ngerman}]
    }
    \map{
      \perdatasource{\jobname-fr.bib}
      \step[fieldset=langid, fieldvalue={french}]
    }
  }
}

Where we use \perdatasource to restrict the mapping to the appropriate .bib file.

MWE

\documentclass[ngerman,french,english,british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[style=authoryear, backend=biber, abbreviate=false, autolang=other]{biblatex}
\usepackage{filecontents}
\begin{filecontents*}{\jobname-en.bib}
@book{abook,
  author     = {Ann Uthor},
  editor     = {Emily Ditor},
  translator = {Tracy R. Anslator},
  title      = {A Fancy Title},
  date       = {2015},
}
\end{filecontents*}
\begin{filecontents*}{\jobname-de.bib}
@book{einbuch,
  author     = {Andrea Torin},
  editor     = {Herbert R. Ausgeber},
  title      = {Ein Titel},
  date       = {2014},
}
\end{filecontents*}
\begin{filecontents*}{\jobname-fr.bib}
@book{livre,
  author     = {Amelie Uteur},
  editor     = {R. Édactrice},
  title      = {Titre},
  date       = {2014},
}
\end{filecontents*}

\addbibresource{\jobname-en.bib}
\addbibresource{\jobname-de.bib}
\addbibresource{\jobname-fr.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \perdatasource{\jobname-en.bib}
      \step[fieldset=langid, fieldvalue={english}]
    }
    \map{
      \perdatasource{\jobname-de.bib}
      \step[fieldset=langid, fieldvalue={ngerman}]
    }
    \map{
      \perdatasource{\jobname-fr.bib}
      \step[fieldset=langid, fieldvalue={french}]
    }
  }
}

\nocite{*}

\begin{document}
\printbibliography
\end{document}

enter image description here

Note that the language is different for all the entries.


Alternatively - thanks to @jon for the idea - you could also add a unique string to a field you can export to. In our example we add [[<langid>]] to the title field (where <langid> should expand to a language identifier biblatex or rather babel/polyglossia can cope with). The language string is then added to the langid field and deleted from the title.

Here, the mapping looks like this

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=title, match=\regexp{\s*\[\[(.+)\]\]}, final]
      \step[fieldset=langid, fieldvalue=\regexp{$1}]
      \step[fieldsource=title, match=\regexp{\s*\[\[(.+)\]\]}, replace={}]
    }
  }
}

And you add the language to the .bib entry like this

@book{einbuch,
  author     = {Andrea Torin},
  editor     = {Herbert R. Ausgeber},
  title      = {Ein Titel[[ngerman]]},
  date       = {2014},
}

MWE

\documentclass[ngerman,french,english,british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[style=authoryear, backend=biber, abbreviate=false, autolang=other]{biblatex}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{abook,
  author     = {Ann Uthor},
  editor     = {Emily Ditor},
  translator = {Tracy R. Anslator},
  title      = {A Fancy Title [[english]]},
  date       = {2015},
}
@book{einbuch,
  author     = {Andrea Torin},
  editor     = {Herbert R. Ausgeber},
  title      = {Ein Titel[[ngerman]]},
  date       = {2014},
}
@book{livre,
  author     = {Amelie Uteur},
  editor     = {R. Édactrice},
  title      = {Titre [[french]]},
  date       = {2014},
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=title, match=\regexp{\s*\[\[(.+)\]\]}, final]
      \step[fieldset=langid, fieldvalue=\regexp{$1}]
      \step[fieldsource=title, match=\regexp{\s*\[\[(.+)\]\]}, replace={}]
    }
  }
}

\nocite{*}

\begin{document}
\printbibliography
\end{document}
moewe
  • 175,683