Translate locations in bibliography depending on document/babel language

I often write texts in German and Englisch and use JabRef to organize my references. Citing a lot of conference papers, it is often quite annoying to always change the language of the locations according to the document language. So I wondered whether I could provide a kind of dictionary to biblatex, so I don't have to adapt my database every time.

E.g. in the preamble I'd like to define:

Munich = München
Germany = Deutschland


in case the document or babel language is ngerman.

Can this be done?

MWE

\documentclass[ngerman]{article}

\usepackage[ngerman]{babel}

\begin{filecontents}{bla.bib}
@inproceedings{Orwell1984,
author  = "George Orwell",
title   = "1984",
year    = "1948",
booktitle = "Books about big brothers",
location = "Munich, Germany",
}
\end{filecontents}

\RequirePackage[backend=biber,style=ieee-alphabetic]{biblatex}

\begin{document}
\cite{Orwell1984}. \\
\printbibliography
\end{document}


You can use biblatex's bibstrings to translate certain phrases. The question is what would be a good interface. If you want to be able to combine arbitrary terms in one field, you'd have to do something like the following (which feels a bit clunky).

\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[backend=biber,style=ieee-alphabetic]{biblatex}

\NewBibliographyString{munich,germany}
\DefineBibliographyStrings{german}{
munich  = {München},
germany = {Deutschland},
}

\begin{filecontents}{\jobname.bib}
@inproceedings{Orwell1984,
author    = {George Orwell},
title     = {1984},
year      = {1948},
booktitle = {Books about big brothers},
location  = {\bibstring{munich}, \bibstring{germany}},
}
\end{filecontents}

\begin{document}
\autocite{Orwell1984}
\printbibliography
\end{document}


If you are OK with using only one string per field, you could make things a little nicer

\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[backend=biber,style=ieee-alphabetic]{biblatex}

\NewBibliographyString{de-munich}
\DefineBibliographyStrings{german}{
de-munich  = {München},
}
\DefineBibliographyStrings{english}{
de-munich  = {Munich, Germany},
}

\DeclareListFormat{location}{%
\usebibmacro{list:delim}{#1}%
\ifbibstring{#1}{\bibstring{#1}}{#1}\isdot
\usebibmacro{list:andothers}}

\begin{filecontents}{\jobname.bib}
@inproceedings{Orwell1984,
author    = {George Orwell},
title     = {1984},
year      = {1948},
booktitle = {Books about big brothers},
location  = {de-munich},
}
\end{filecontents}

\begin{document}
\autocite{Orwell1984}
\printbibliography
\end{document}


A more BibTeX-y solution uses @strings. You can define strings for each location in different .bib files (one for each language) and then select the .bib file for the language you need in your document.

\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[backend=biber,style=ieee-alphabetic]{biblatex}

\begin{filecontents}{locationstrings-german.bib}
@string{de:munich = "München"}
\end{filecontents}
\begin{filecontents}{locationstrings-english.bib}
@string{de:munich = "Munich, Germany"}
\end{filecontents}
% select the bib file for the language you want

\begin{filecontents}{\jobname.bib}
@inproceedings{Orwell1984,
author    = {George Orwell},
title     = {1984},
year      = {1948},
booktitle = {Books about big brothers},
location  = de:munich,
}
\end{filecontents}

\begin{document}
\autocite{Orwell1984}
\printbibliography
\end{document}


The still very experimental multiscript version of biblatex might also be of interest: https://github.com/plk/biblatex/issues/416

• Thank you! My aim is to leave the original .bib file unmodified.. So I wonder if maybe your first approach allows something like \DeclareFieldFormat{pubstate}{\ifbibstring{#1}{\bibstring{#1}}{#1}}, so I won't have to define with bibstring withtin the bib-file. However, I could't manage to pass the two comma-separated values to the command. Do you think it can be done? – thewaywewalk Sep 14 at 7:13
• @thewaywewalk In theory you could try and use etoolbox CSV list macros to loop over the field as a comma-separated list. But that removes spaces around commas, so you'd have to manually re-add them. Furthermore, I believe that there is a difference between printable text and 'keys'/bibstring names (bibstring names should ideally use ASCII only for maximum compatibility, while printable text can consist of everything). ... – moewe Sep 14 at 14:28
• ... I think you can't have your cake and eat it, too. Either go for fixed printable text in your .bib fields or for sane key markup (as shown in this or Ulrike's answer). Having both will get extremely messy at some point. – moewe Sep 14 at 14:29
\documentclass[ngerman]{article}

\usepackage[ngerman]{babel}

\begin{filecontents}{german-strings.bib}
@string{muenchen={München}}
@string{germany={Deutschland}}
\end{filecontents}

\begin{filecontents}[overwrite]{bla.bib}
@inproceedings{Orwell1984,
author  = "George Orwell",
title   = "1984",
year    = "1948",
booktitle = "Books about big brothers",
location = muenchen # ", " # germany
}
\end{filecontents}

\RequirePackage[backend=biber,style=ieee-alphabetic]{biblatex}