About multi-language support

I’m using hugo to create a site with the following file directory structure

|----archetypes
|----content
|----data
      |----en
             |----about.yml
             |----contact.yml
      |----es
             |----about.yml
             |----contact.yml
|----resource
|----static
|----themes

The code in about.yml like following (e.g. about.yml in folder en)

---
enable: true
title: >
  ## About

content: >
  ### We're friends

  sdfsaff
  
  dafdfsafsaf
image: images/about.jpg

The code in template of themes

{{ with .Site.Data.en.aboutSection }}
{{ if .enable }}
{{ .title | markdownify}}
{{ .content | markdownify}}
{{ end }}
{{ end }}

I want to display different content in different languages, I tried to update the code to

{{ if (eq "es" $.Site.Language.Lang)}}
{{ with .Site.Data.es.aboutSection }}
{{ else }}
{{ with .Site.Data.en.aboutSection }}
{{ end }}
{{ if .enable }}
{{ .title | markdownify}}
{{ .content | markdownify}}
{{ end }}
{{ end }}

But I get an error

process: loading templates: "/Users/Local/hugo/of/themes/hsss/layouts/partials/aboutSection.html:11:1": parse failed unexpected EOF 
/Users/Local/hugo/of/themes/hsss/layouts/partials/aboutSection.html:11:1:
{{ end }}
{{ end }}

Why? Please help, thank you.

You can write it like this:

{{- $data := index site.Data site.Language.Lang -}}

{{ with $data.aboutSection }}
  {{ if .enable }}
    {{ .title | markdownify}}
    {{ .content | markdownify}}
  {{ end }}
{{ end }}

Thank you so much. @pamubay

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.