Skip to content

Commit

Permalink
feat: fill i18n fields if enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Nov 26, 2023
1 parent a8e2254 commit e3452e7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
12 changes: 12 additions & 0 deletions layouts/_default/index.decapcmsconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@
{{- $config.Set "logo_url" . }}
{{- end }}
{{- end }}
{{/* Fill i18n fields if enabled. */}}
{{- with $config.Get "i18n" }}
{{- $i18n := . }}
{{- $locales := partialCached "decap-cms/functions/locales" . }}
{{- if not .locales }}
{{- $i18n = merge $i18n (dict "locales" $locales) }}
{{- end }}
{{- if not .default_locale }}
{{- $i18n = merge $i18n (dict "default_locale" (index $locales 0)) }}
{{- end }}
{{- $config.Set "i18n" $i18n }}
{{- end }}
{{- transform.Remarshal "yaml" $config.Values | safeHTML -}}
10 changes: 2 additions & 8 deletions layouts/partials/decap-cms/functions/locale.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{{- $locales := dict
"zh-cn" "zh_Hans"
"zh-hans" "zh_Hans"
"zh-hant" "zh_Hant"
"zh-hk" "zh_Hant"
"zh-tw" "zh_Hant"
}}
{{- $map := partialCached "decap-cms/functions/locales-map" . }}
{{- $locale := site.Language.LanguageCode }}
{{- with index $locales $locale }}
{{- with index $map $locale }}
{{- $locale = . }}
{{- end }}
{{- return $locale }}
7 changes: 7 additions & 0 deletions layouts/partials/decap-cms/functions/locales-map.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- return dict
"zh-cn" "zh_Hans"
"zh-hans" "zh_Hans"
"zh-hant" "zh_Hant"
"zh-hk" "zh_Hant"
"zh-tw" "zh_Hant"
}}
10 changes: 10 additions & 0 deletions layouts/partials/decap-cms/functions/locales.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- $map := partialCached "decap-cms/functions/locales-map" . }}
{{- $locales := slice }}
{{- range site.Languages }}
{{- with index $map .LanguageCode }}
{{- $locales = $locales | append . }}
{{- else }}
{{- $locales = $locales | append .LanguageCode }}
{{- end }}
{{- end }}
{{- return $locales }}

0 comments on commit e3452e7

Please sign in to comment.