Biblatex:根据语言选择内容

Biblatex:根据语言选择内容

我正在使用 biblatex,想引用英语和德语作品。在用德语撰写文档时,使用\DeclareLanguageMapping和连字符可以很好地指定参考文献是否应以德语或英语风格引用。然而,在撰写文档时,我需要更改德语参考书目条目 - 通过在相应字段的括号中添加英语翻译(参见附件 MWE)。

\documentclass{article}

\usepackage[english,american,ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{extarrows}
\usepackage{csquotes}
\usepackage[style=apa,
        bibencoding=utf8,
        sortcites=true,
        bibwarn=true,
        firstinits=true,
        isbn=false,
        dashed=false,
        maxbibnames=99,
        babel=other,
        backend=biber,
        hyperref=true]{biblatex}

\begin{filecontents}{myworks.bib}

@article{articleD,
  author  = {Peter Adams}, 
  title   = {Deutscher Titel},
  journal = {Journalname},
  year    = 1993,
  number  = 2,
  pages   = {201-213},
  month   = 7,
  note    = {Beispielkommentar}, 
  keyword = {D},
  volume  = 4
}

@article{articleE,
  author  = {Peter Adams}, 
  title   = {English Title},
  journal = {The name of the journal},
  year    = 1993,
  number  = 2,
  pages   = {201-213},
  month   = 7,
  note    = {An optional note}, 
  keyword = {E},
  volume  = 4
}

\end{filecontents}


\addbibresource{myworks.bib} 

\DeclareLanguageMapping{ngerman}{ngerman-apa}
\DeclareLanguageMapping{american}{american-apa}

\begin{document}
\nocite{*}
\selectlanguage{american}
\printbibliography[keyword=E]
\end{document}

可以通过为每个参考书目条目提供德语和英语版本来实现这一点(参见文章、文章 E),但这不是一个好的解决方案。保留参考书目的最佳方式是这样的(当文档以英语编写时,在标题后面的括号中添加翻译):

@article{article,
  author  = {Peter Adams}, 
  title   = {Deutscher Titel},
  titleE  = {English Title},
  journal = {Journalname},
  journalE= {The name of the journal},
  year    = 1993,
  number  = 2,
  pages   = {201-213},
  month   = 7,
  note    = {Beispielkommentar},
  noteE   = {An optional note}, 
  keyword = {E},
  volume  = 4
}

导致

亚当斯,P.(1993 年)。 Deutscher Titel [英文标题]。期刊名称/期刊名称2,201–213。

有人知道如何实现这一点吗?

干杯

答案1

正如评论中所提到的,实验性的 biblatex 4.0 知道字段的“变体”,并且可以与 biber 4.0 beta 一起使用它们。

但这并不容易(而像 APA 这样的复杂格式会使其变得更加困难),而且相当耗时。必须检查大量宏才能决定在哪里以及如何注入翻译(以及如果有多个变体,例如某个日语标题的翻译和转录,该怎么办)。

以下示例显示了使用实验性的 biblatex/biber 的示例代码及其输出:

\documentclass{article}

\usepackage[english,american,ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{extarrows}
\usepackage{csquotes}
\usepackage[style=apa,
        bibencoding=utf8,
        sortcites=true,
        bibwarn=true,
        firstinits=true,
        isbn=false,
        dashed=false,
        maxbibnames=99,
        babel=other,
        backend=biber,
        hyperref=true]{biblatex}


\addbibresource{test.bib}

\DeclareLanguageMapping{ngerman}{ngerman-apa}
\DeclareLanguageMapping{american}{american-apa}


\renewbibmacro*{journal}{%
  \iffieldundef{journaltitle}
    {}
    {\printtext[journaltitle]{%
       \printfield[titlecase]{journaltitle}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{journalsubtitle}}}%
  \iffieldundef[form=translated,lang=english]{journaltitle}
    {}
    {%
     \setunit{/}%
     \printfield[][form=translated,lang=english]{journaltitle}%
    }%       
  }  

\renewbibmacro*{title}{%
  \ifthenelse{\iffieldundef{title}\AND\iffieldundef{subtitle}}
    {}
    {\iffieldundef{origtitle}
      {\printtext[title]{%
        \printfield[apacase]{title}%
        \setunit{\subtitlepunct}%
        \printfield[apacase]{subtitle}}
       \iffieldundef[form=translated,lang=english]{title}
       {}
       {%
       \setunit{}%
       \addspace
       \mkbibbrackets{\printfield[][form=translated,lang=english]{title}}%
       }%
      }
      {\printfield{origtitle}%
       \setunit{\addspace}%
       \printtext[brackets]{%
        \printfield[apacase]{title}%
        \setunit{\subtitlepunct}%
        \printfield[apacase]{subtitle}}}%
     \setunit{\addspace}%
     \printfield{titleaddon}%
     \iffieldequalstr{entrytype}{book}%
       {\setunit{\addspace}\usebibmacro{bookaddinfo}}%
       {}%
     \ifthenelse{%
       \ifnameundef{author}\AND%
       \(\ifnameundef{editor}\AND\NOT\boolean{bbx:editorinauthpos}\)\AND%
       \ifnameundef{producer}\AND%
       \ifnameundef{director}\AND%
       \ifnameundef{writer}}
        {\newunit\newblock
         \usebibmacro{labelyear+extrayear}}
        {}}}

\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/editor}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \newunit\newblock
  \usebibmacro{journal+issuetitle}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit\newblock
  \printfield{note}%
  \iffieldundef[form=translated,lang=english]{note}
       {}
       {%
       \setunit{}%
       \addspace
       \mkbibparens{\printfield[][form=translated,lang=english]{note}}%
       }%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}%
  \usebibmacro{apa:finpunct}%
  \usebibmacro{apa:pageref}%
  \usebibmacro{finentry}}           
\newbibmacro*{note+pages}{%
  \printfield{note}%

  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit}

\begin{document}
\cite{articletranslated}
\selectlanguage{american}
\printbibliography
\end{document}

test.bib

@article{articletranslated,
  author  = {Peter Adams},
  title   = {Deutscher Titel},
  title_translated_english  = {English Title},
  journal = {Journalname},
  journaltitle_translated_english= {The name of the journal},
  year    = 1993,
  number  = 2,
  pages   = {201-213},
  month   = 7,
  note    = {Beispielkommentar},
  note_translated_english   = {An optional note},
  keyword = {E},
  volume  = 4
}

在此处输入图片描述

我认为,投入的时间往往不值得。

一种更简单的方法是直接在 bib 中注入条件文本:

@article{articlewithengl,
  author  = {Peter Adams},
  title   = {Deutscher {Titel}\ifbool{useenglish}{\addspace\mkbibbrackets{English Title}}{}},
  journal = {Journalname\ifbool{useenglish}{/The name of the journal}{}},
  year    = 1993,
  number  = 2,
  pages   = {201-213},
  month   = 7,
  note    = {Beispielkommentar\ifbool{useenglish}{\addspace(An optional note)}{}},
  keyword = {E},
  volume  = 4
}

然后可以简单地使用

\usepackage{etoolbox}
\newbool{useenglish}
\booltrue{useenglish} %or \boolfalse{useenglish}

答案2

最简单的解决方案(假设apa使用 biblatex 样式)是将翻译存储在titleaddon字段中(这是标准 biblatex 字段之一)。

答案3

也许这些想法会对你有帮助

% !TeX program = pdflatex 
\RequirePackage{filecontents}
\begin{filecontents*}{myworks.bib}
@article{article,
  author  = {Peter Adams}, 
  title   = {Deutscher Titel},
  titleE  = {English Title},
  journal = {Journalname},
  journalE= {The name of the journal},
  year    = 1993,
  number  = 2,
  pages   = {201-213},
  month   = 7,
  note    = {Beispielkommentar},
  noteE   = {An optional note}, 
  keywords = {E},
  volume  = 4
}
\end{filecontents*}

\documentclass{article}

\usepackage[english,american,ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{extarrows}
\usepackage{csquotes}
\usepackage[style=apa,
        bibencoding=utf8,
        sortcites=true,
        bibwarn=true,
        firstinits=true,
        isbn=false,
        dashed=false,
        maxbibnames=99,
        autolang=other,
        backend=biber,
        hyperref=true]{biblatex}

\addbibresource{myworks.bib} 

%%Thanks
%%http://tex.stackexchange.com/a/141831/79756
%%http://tex.stackexchange.com/a/226429/79756
%%for idea
\DeclareSourcemap{ 
    \maps{
        \map[overwrite]{
            \step[fieldsource=keywords,
            match={E},
            final]
            \step[fieldsource=titleE,]
            \step[fieldset=title, fieldvalue={~[}, append]
            \step[fieldset=title, origfieldval, append]
            \step[fieldset=title, fieldvalue={]}, append]
        }
        \map[overwrite]{
            \step[fieldsource=keywords,
            match={E},
            final]
            \step[fieldsource=journalE,]
            \step[fieldset=journal, fieldvalue={/}, append]
            \step[fieldset=journal, origfieldval, append]
        }
        \map[overwrite]{
            \step[fieldsource=keywords,
            match={E},
            final]
            \step[fieldsource=noteE,]
            \step[fieldset=note, fieldvalue={~[}, append]
            \step[fieldset=note, origfieldval, append]
            \step[fieldset=note, fieldvalue={]}, append]
        }
    }
}

\DeclareLanguageMapping{ngerman}{ngerman-apa}
\DeclareLanguageMapping{american}{american-apa}

\DeclareFieldFormat{apacase}{#1} %undo APA style sentence case correction for every field

\begin{document}
\nocite{*}
\selectlanguage{american}
\printbibliography[keyword=E]
\end{document}

代码输出

相关内容