How to use array in i18n files?

Hi

When working with the Hugo data files or config we can loop through arrays. But I am not able to do it in i18n files.
Suppose following yaml snippet:

List:
  - item 1
  - item 2
  - item 3

Commonly we can do

{{range ...List}}
{{.}}
{{end}}

But I am not able to achieve this in i18n files I’m using for translation.
Actually I have to make select with options translatd.

I hope you understand my point.
Thanks :blush:

That’s not possible. Mostly because a translation is something where the only use is “what is THIS_STRING in LANGUAGE-X”. You could though take your i18n files, create a toml file in data for all the labels and then iterate through site.Data.tomlfilefori18n and read the terms from the translation files in. Lots of work if your translations change often.

That is “hacky”, but ranging through translation terms is hacky if their task is to translate, not to list.

Actually need is just to add select element with translated options. Can you please show a simple kind of way to do it?

I’m settle with following way which I experimented and worked like a charm:
Instead of i18n files I simply made use of page front matter. I simply created _index.md and _index.de.md and used front matter.

It’s even better because we use only one file for translation.

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