feat(i18n): add multilingual support for author data files

Hugo doesn't natively merge language-specific data directories with the default data. Add a `get_authors_data` partial that manually
looks up `data/<lang>/authors/` and deep-merges translated fields
on top of the default data/authors/ profiles.

Centralizes all `site.Data.authors` access through this new partial
so author names, bios, roles, and other fields can be translated
per language while inheriting non-translated fields from the default.
This commit is contained in:
George Cushen
2026-03-03 00:30:27 +00:00
parent dbe0c86df7
commit 4d38c40f9f
5 changed files with 64 additions and 6 deletions
+2 -1
View File
@@ -116,7 +116,8 @@
{{ $author = strings.TrimSpace $author_raw }}
{{ end }}
{{ $profile := partial "functions/get_author_profile" $author }}
{{ $author_data := index site.Data.authors (urlize $author) }}
{{ $authors := partialCached "functions/get_authors_data" $page site.Language.Lang }}
{{ $author_data := index $authors (urlize $author) }}
{{ $email := "" }}
{{ $email_raw := index $content "email" }}
{{ if eq (printf "%T" $email_raw) "string" }}
+3 -2
View File
@@ -90,9 +90,10 @@
{{/* Build profiles from data/authors */}}
{{ $allProfiles := slice }}
{{ range $slug, $_ := site.Data.authors }}
{{ $authors := partialCached "functions/get_authors_data" $page site.Language.Lang }}
{{ range $slug, $_ := $authors }}
{{ $profile := partial "functions/get_author_profile" (dict "slug" $slug) }}
{{ $profileData := index site.Data.authors $slug }}
{{ $profileData := index $authors $slug }}
{{ $allProfiles = $allProfiles | append (dict "profile" $profile "profileData" $profileData) }}
{{ end }}
@@ -38,7 +38,8 @@ Output (dict):
{{- $slug = $slug | urlize -}}
{{- $data := index site.Data.authors $slug -}}
{{- $authors := partialCached "functions/get_authors_data" . site.Language.Lang -}}
{{- $data := index $authors $slug -}}
{{- $hasData := $data -}}
{{/* Structured name resolution */}}
@@ -0,0 +1,54 @@
{{/*
Return the authors data map for the current language.
For multilingual sites, language-specific author data from data/<lang>/authors/
is merged on top of the default data/authors/ files. This allows translating
fields like name, bio, role, etc., while inheriting non-translated fields.
Usage:
{{ $authors := partialCached "functions/get_authors_data" . site.Language.Lang }}
Returns: map of slug → author data (same shape as site.Data.authors)
*/}}
{{- $authors := site.Data.authors -}}
{{- if not $authors -}}
{{- $authors = dict -}}
{{- end -}}
{{/* Check for language-specific author overrides */}}
{{- $lang := site.Language.Lang -}}
{{- $langData := index site.Data $lang -}}
{{- if $langData -}}
{{- $langAuthors := index $langData "authors" -}}
{{- if $langAuthors -}}
{{/* Merge each language-specific author data on top of the default */}}
{{- $merged := dict -}}
{{/* Start with all default authors */}}
{{- range $slug, $data := $authors -}}
{{- $langAuthor := index $langAuthors $slug -}}
{{- if $langAuthor -}}
{{/* Language data overrides default; merge gives $langAuthor priority */}}
{{- $mergedAuthor := merge $data $langAuthor -}}
{{/* Deep-merge the 'name' submap if both have it */}}
{{- $baseName := index $data "name" -}}
{{- $langName := index $langAuthor "name" -}}
{{- if and (reflect.IsMap $baseName) (reflect.IsMap $langName) -}}
{{- $mergedAuthor = merge $mergedAuthor (dict "name" (merge $baseName $langName)) -}}
{{- end -}}
{{- $merged = merge $merged (dict $slug $mergedAuthor) -}}
{{- else -}}
{{- $merged = merge $merged (dict $slug $data) -}}
{{- end -}}
{{- end -}}
{{/* Add any authors that only exist in the language data */}}
{{- range $slug, $data := $langAuthors -}}
{{- if not (index $authors $slug) -}}
{{- $merged = merge $merged (dict $slug $data) -}}
{{- end -}}
{{- end -}}
{{- $authors = $merged -}}
{{- end -}}
{{- end -}}
{{- return $authors -}}
@@ -18,12 +18,13 @@
{{ $superuser_role := "" }}
{{/* Prefer is_owner flag, fallback to slug 'me' */}}
{{ range $slug, $data := site.Data.authors }}
{{ $authors := partialCached "functions/get_authors_data" . site.Language.Lang }}
{{ range $slug, $data := $authors }}
{{ if and (not $superuser_slug) ($data.is_owner) }}
{{ $superuser_slug = $slug }}
{{ end }}
{{ end }}
{{ if and (eq $superuser_slug "") (index site.Data.authors "me") }}
{{ if and (eq $superuser_slug "") (index $authors "me") }}
{{ $superuser_slug = "me" }}
{{ end }}