You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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 translatorPartliteral value in CLS-JSON #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 }}.
{{- end -}}{{/* First letter (initial). */}}
{{- with $translator.secondInitial -}}
<meta itemprop="additionalName" content="{{ . }}" />
{{- substr . 0 1 -}}. {{- end -}}
{{- with $translator.family -}}
<span itemprop="familyName">{{ . }}</span>
{{- end -}}
</span>
{{- if and (gt $totalTranslators 1) (lt (add $translatorIndex 2) $totalTranslators) -}}, 
{{ end -}}
{{ if eq $totalTranslators (add $translatorIndex 2) -}} & {{ end -}}{{/* Last name has ampersand */}}
{{- end -}}
{{- else -}}{{/* Fallback if no translators are specified */}}
{{- end -}}
{{- end -}}{{/* END translator */}}
In the book type after title add:
{{- if isset . "translator" -}} (<span itemprop="translator">{{- template "translatorPart" . -}}</span>){{- end -}}
The text was updated successfully, but these errors were encountered:
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:
authorPart
and modified it to becometranslatorPart
(if theauthorPart
is modified to include handle corporate or "literal" names, then those adjustments should also be made to thetranslatorPart
literal value in CLS-JSON #26 ):The text was updated successfully, but these errors were encountered: