.Site.Data.lang.en shows up as string, expected as code

So what I’m doing is I have a theme that will have a data/lang folder with a bunch of files, like en.yml and lt.yml or whatever.

In these files, you can access language strings for the theme like this: .Site.Data.lang.en.okStatus. Here’s the problem: I can’t hardcode a language in the theme, I want it to be changeable from the config.yml file. As such, I’ve got a .Site.LanguageCode variable that would change whether it would be lt, or en, or en-CA, etc.

My code:

{{ $path := .Site.LanguageCode | printf "%s.%s" ".Site.Data.lang" | printf "%s" }}

{{ $path }} returns .Site.Data.lang.en.

I expect: map[downStatus:Experiencing major issues disruptedStatus:Experiencing disruptions noticeStatus:Please read announcement okStatus:All systems operationalx].

Also, I took a look at this, which kinda helped, but not really? String / Variable Concatenation to build Path for partial It’s kinda similar.

What that does is build the path string for you, so it just prints out Site.Data.lang.en instead of actually accessing data/lang/en.*.

index is probably more helpful.

1 Like

can you give an example snippet?

pointyfar linked to an example: https://gohugo.io/functions/index-function/#example-load-data-from-a-path-based-on-front-matter-params