# Create dynamic loop depending on I18n language file

**URL:** <https://discourse.gohugo.io/t/create-dynamic-loop-depending-on-i18n-language-file/38557>\
**Category:** support\
**Tags:** i18n\
**Created:** [May 11, 2022, 5:40am UTC](https://discourse.gohugo.io/t/create-dynamic-loop-depending-on-i18n-language-file/38557 "2022-05-11T05:40:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trob999](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@Trob999](https://discourse.gohugo.io/u/Trob999)\
**Post date:** [May 11, 2022, 5:40am UTC](https://discourse.gohugo.io/t/create-dynamic-loop-depending-on-i18n-language-file/38557/1 "2022-05-11T05:40:43Z")

</div>

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**

```auto
...
     "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)**

```auto
…
  "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 …**

```auto
... 
<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

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 11, 2022, 12:35pm UTC](https://discourse.gohugo.io/t/create-dynamic-loop-depending-on-i18n-language-file/38557/2 "2022-05-11T12:35:17Z")

</div>

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

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

  

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

  

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

---

<div class="post-metadata">

**Author:** ![Trob999](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@Trob999](https://discourse.gohugo.io/u/Trob999)\
**Post date:** [May 11, 2022, 1:02pm UTC](https://discourse.gohugo.io/t/create-dynamic-loop-depending-on-i18n-language-file/38557/3 "2022-05-11T13:02:38Z")

</div>

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 …

```auto
            <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>

```

---

<div class="post-metadata">

**Author:** ![Trob999](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@Trob999](https://discourse.gohugo.io/u/Trob999)\
**Post date:** [May 12, 2022, 7:59am UTC](https://discourse.gohugo.io/t/create-dynamic-loop-depending-on-i18n-language-file/38557/4 "2022-05-12T07:59:01Z")

</div>

> [@jmooring](#):
>
> `{{ T (printf "slogans.%d" .) }}`

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

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 12, 2022, 8:50am UTC](https://discourse.gohugo.io/t/create-dynamic-loop-depending-on-i18n-language-file/38557/5 "2022-05-12T08:50:19Z")

</div>

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