Create dynamic loop depending on I18n language file

Hello

I have the following problem I would like the Parameter “number_slogan_info” to be dynamic. Is this somehow possible?

Currently the it works like this:

1) in the “config.json” I have set the parameter number_slogan_info

...
     "params": {
        "header_img": "img/header_250.png",
        "number_slogan_info": 4,
      ...
        },
...

2) In the language file of i18n I then defined the slogans (for each language different of course)

…
  "slogan_info_0": {
    "other": "Security Management - ISMS27001 & Ethical Hacker"
  },
  "slogan_info_1": {
    "other": "Agile Project Management - Scrum & Kanban"
  },
  "slogan_info_2": {
    "other": "IT Service Management - ISMS20000 & FitSM"
  },
  "slogan_info_3": {
    "other": "DevOps - Continuous Integration  & Continuous Delivery"
  },
…

3) In the home.html I do …

... 
<div id="typing">
   <ul id="typing-carousel-data">
      {{ range $i, $sequence := (seq .Site.Params.number_slogan_info) }} 
        {{ $i18n_tag := print "slogan_info_" $i }}
        <li> {{ $i18n_tag | i18n }}</li>
     {{ end }}
   </ul>
</div>
...

I would now like to make the parameter dynamic. It shall work without definition of the max value “number_slogan_info” in the config.json.

Can I modify the loop so that it reads from the Language file until no more slogans are delivered?

So when I want to add another slogan – I just add a slogan in the en.json, de.json, fr.json … without editing config.json. For the start we can assume that in every langfile we have the same number of slogans …

Thanks for your help
rob

Modify your i18n files (the data structure is somewhat flexible) and mount the i18n directory to the data directory.

config.json
{
  ...
  "module": {
    "mounts": [
      {
        "source": "data",
        "target": "data"
      },
      {
        "source": "i18n",
        "target": "data"
      }
    ]
  }
}

i18n/en.json
{
  "slogans": {
    "1": "Slogan A (en)",
    "2": "Slogan B (en)",
    "3": "Slogan C (en)"
  }
}

template
{{ range seq (index site.Data .Lang "slogans" | len) }}
  <h2>{{ T (printf "slogans.%d" .) }}</h2>
{{ end }}

HI jm
Thanks I try tomorrow - I have a workarround that works but like your approach more
Here is my solution with max_loops set to 100 …

            <div id="typing">
                <ul id="typing-carousel-data">
                    {{ range $i, $sequence := (seq .Site.Params.max_loops) }}
                        {{ $i18n_tag := print "slogan_info_" $i }}
                        {{ $slogan := $i18n_tag | i18n }}
                        {{ if (ne $slogan "") }}
                             <li>{{$slogan}}</li> 
                        {{ end }}
                    {{ end }}
                </ul>
            </div>

can you explain me what T (this line) is doing? thanks

T and i18n are aliases for the lang.Translate function.