Data with multilanguage

Hi there,

Is there a way to use the /data folder in a multilanguage website, eg. using a data-name.en.json and file ?

Otherwise, what would be the simplest way to create an array of multi-level data within the en-Us.toml and fr-FR.toml in the /i18n folder ?

Thanks in advance.

Regards .

You could do something like this:

{{ $data := index .Site.Data (printf "mydata_%s" .Site.Language.Lang ) }}
1 Like

thanks for your help!

{{ range $index, $val := .Site.Data (printf "faq_%s" .Site.Language.Lang ) }}

I tried this but it’s not working - I got the following error:
<.Site.Data>: Data has arguments but cannot be invoked as function

Any idea?

You have to follow my example and not make up something completely different.

Following advice from @bep, I did it this way and it works perfectly :sunny:
See it here in action:

1 Like

This is curiosity; But would the above be the same as:

{ if $testimonials }}

Which could then be rewritten to:

{ if with $testimonials }}

I’m to lazy to try … @kaushalmodi may know.

Yes it works!:clap:

What would be the difference with
{{ if with $testimonials }}

Should would be less verbose:

{{ with index .Site.Data.testimonials .Site.Language.Lang }}
{{ range . }}
// Do something with tesimonial here
{{ end }}
{{ end  }}
1 Like

Pretty sure that this is a typo as I have never seen if + with.

But yes, always a fan of with :slight_smile:


{{ with $testimonials }}

I don’t understand: this works: {{ if $testimonials }} but this

throws an error in my partial:
theme/partials/testimonials.html:14:50: executing “theme/partials/testimonials.html” at : wrong number of args for markdownify: want 1 got 0

Any idea?

Found it, sorry for my dumbness :roll_eyes:: forgot to change .Site.Params.testimonials.title to $.Site.Params.testimonials.title.

1 Like

Current version with with :slight_smile: . Thanks @bep and @kaushalmodi.
Visit to see it in action.

1 Like

And when the data is in one file:


{{ with index .Site.Data.dataname .Site.Language.Lang }}
  {{ range .dataname}}
    <a href="{{ .URL }}">{{ .Name }}</a>
  {{ end }}
{{ end }}
1 Like