loup-brun / hugo-cite

📝 Easily manage your bibliography and in-text citations with Hugo, the popular static-site generator.
https://labs.loupbrun.ca/hugo-cite/
Do What The F*ck You Want To Public License
110 stars 28 forks source link

APA 6th for translator roles #33

Open HughP opened 3 years ago

HughP commented 3 years ago

Greetings,

I needed to add a translator so I did. Translators can be attached to any resource type. But in my templates I only added them to books as that is all I needed sofar. Ideally there would be a better way than to add translator to each title... maybe a title template is needed. Here is the two part solution I came up with:

  1. I duplicated the authorPart and modified it to become translatorPart (if the authorPart is modified to include handle corporate or "literal" names, then those adjustments should also be made to the translatorPart #26 ):
{{/* BEGIN translator */}}
{{- define "translatorPart" }}
  {{- $translators := .translator }}
  {{- if $translators -}}
  {{- $totalTranslators := len $translators -}}
  {{- range $translatorIndex, $translator := $translators -}}
  <span itemprop="author" itemscope itemtype="https://schema.org/Person">
     {{- with $translator.given -}}
    <meta itemprop="givenName" content="{{ . }}" />{{ substr . 0 1 }}.&nbsp;
    {{- end -}}{{/* First letter (initial). */}}
    {{- with $translator.secondInitial -}}
    <meta itemprop="additionalName" content="{{ . }}" />
    {{- substr . 0 1 -}}.&nbsp;{{- end -}}
   {{- with $translator.family -}}
    <span itemprop="familyName">{{ . }}</span>
    {{- end -}}
  </span>
  {{- if and (gt $totalTranslators 1) (lt (add $translatorIndex 2) $totalTranslators) -}},&#32;
  {{ end -}}
  {{ if eq $totalTranslators (add $translatorIndex 2) -}}&#32;&amp;&#32;{{ end -}}{{/* Last name has ampersand */}}
  {{- end -}}
  {{- else -}}{{/* Fallback if no translators are specified */}}
  {{- end -}}
{{- end -}}{{/* END translator */}}
  1. In the book type after title add:
{{- if isset . "translator" -}}&#32;(<span itemprop="translator">{{- template "translatorPart" . -}}</span>){{- end -}}
loup-brun commented 3 years ago

Thank you! 😊 I’m getting everything ready to integrate all these changes. Stay tuned!

HughP commented 3 years ago

I hope your comment doesn't mean that I am providing templates you have already created but have not yet published!

loup-brun commented 3 years ago

@HughP no don’t worry, it’s not already created, thanks for your contribution :)