Skip to content

Commit

Permalink
feat: translate collection labels (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Jan 24, 2024
1 parent 7db2bd1 commit 5ff085d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
11 changes: 7 additions & 4 deletions layouts/partials/decap-cms/functions/format.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
{{- range $name, $value := . }}
{{- if hasPrefix $name "_" }}
{{- $tmp.DeleteInMap "c" $name }}
{{- else if in (slice "label" "label_singular") $name }}
{{- $label := partial "decap-cms/functions/translate-label" $value }}
{{- $tmp.SetInMap "c" $name $label }}
{{- else if eq $name "meta" }}
{{- $meta := $value }}
{{- with index $meta "path" }}
{{- $pathLabel := partial "decap-cms/functions/translate-label" .label }}
{{- $pathLabel := partial "decap-cms/functions/translate-field-label" .label }}
{{- $meta = merge $meta (dict "path" (merge . (dict "label" $pathLabel))) }}
{{- $tmp.SetInMap "c" "meta" $meta }}
{{- end }}
Expand All @@ -31,15 +34,15 @@
{{- if hasPrefix $fName "_" }}
{{- $tmp2.DeleteInMap "f" $fName }}
{{- else if eq $fName "label" }}
{{- $label := partial "decap-cms/functions/translate-label" $fValue }}
{{- $label := partial "decap-cms/functions/translate-field-label" $fValue }}
{{- $tmp2.SetInMap "f" "label" $label }}
{{- else if eq $fName "field" }}
{{- $childLabel := partial "decap-cms/functions/translate-label" $fValue.label }}
{{- $childLabel := partial "decap-cms/functions/translate-field-label" $fValue.label }}
{{- $tmp2.SetInMap "f" "field" (merge $fValue (dict "label" $childLabel)) }}
{{- else if eq $fName "fields" }}
{{- $children := slice }}
{{- range $fValue }}
{{- $childLabel := partial "decap-cms/functions/translate-label" .label }}
{{- $childLabel := partial "decap-cms/functions/translate-field-label" .label }}
{{- $child := . }}
{{- $children = $children | append (merge . (dict "label" $childLabel)) }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ return default . (printf "cms_field_label_%s" (replace (lower .) " " "_") | i18n) }}
2 changes: 1 addition & 1 deletion layouts/partials/decap-cms/functions/translate-label.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ return default . (printf "cms_field_label_%s" (replace (lower .) " " "_") | i18n) }}
{{ return default . (printf "cms_label_%s" (replace (lower .) " " "_") | i18n) }}

0 comments on commit 5ff085d

Please sign in to comment.