Skip to content

Commit

Permalink
Use labels in content language, if available
Browse files Browse the repository at this point in the history
  • Loading branch information
cmahnke committed Jan 3, 2025
1 parent d9be9b2 commit f4fa00a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
15 changes: 11 additions & 4 deletions layouts/partials/data/functions/wikidata-label.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
{{- $debug := partialCached "partials/functions/debug/enabled.html" . -}}

{{- $url := .url -}}
{{- if isset "langs" . -}}
{{- $defaultLangs = .langs -}}
{{- with .langs -}}
{{- $defaultLangs = . -}}
{{- if $debug -}}
{{- warnf "[data/functions/wikidata-label.html] Setting languages to %s for %s" $defaultLangs $url -}}
{{- end -}}
{{- end -}}

{{- $uri := "" -}}
Expand Down Expand Up @@ -40,11 +43,15 @@

{{- $entity := index $data.entities $id -}}

{{- $label := $id -}}
{{- $label := "" -}}
{{- range $defaultLangs -}}
{{- if isset $entity.labels . -}}
{{- if and (isset $entity.labels .) (eq $label "") -}}
{{- $label = (index $entity.labels .).value -}}
{{- end -}}
{{ end }}

{{- if eq $label "" -}}
{{- $label = $id -}}
{{- end -}}

{{- return $label -}}
11 changes: 9 additions & 2 deletions layouts/partials/data/wikidata.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
{{- $entityBase := "http://www.wikidata.org/entity/" -}}

{{- with .Params.wikidata -}}

{{- $primaryLang := $.Language.Lang -}}
{{- $langs := slice $primaryLang -}}
{{- range $.Translations -}}
{{- $langs = $langs | append .Language.Lang -}}
{{- end -}}

{{- $entries := dict -}}
{{- if not (reflect.IsMap .) -}}
{{- $list := slice -}}
Expand All @@ -23,8 +30,8 @@
{{- $id := replaceRE `https://www.wikidata.org/wiki/` "" $url -}}
{{- $uri := printf "%s%s" $entityBase $id -}}
<li class="wikidata-entry">
{{- $name := partial "data/functions/wikidata-label.html" (dict "url" $id) -}}
<a href="{{ $uri }}" title="{{ $id }}" rel="{{ $relation }}">{{ printf "%s: " (i18n "WikidataEntry") }}{{ $name }}</a>
{{- $name := partial "data/functions/wikidata-label.html" (dict "url" $id "langs" $langs) -}}
<a href="{{ $uri }}" title="{{ $name }}" rel="{{ $relation }}">{{ printf "%s: " (i18n "WikidataEntry") }}{{ $name }}</a>
</li>
{{- end -}}
</ul>
Expand Down

0 comments on commit f4fa00a

Please sign in to comment.