# Reference translation (stored in yml file) in navigation yml file

**URL:** <https://talk.jekyllrb.com/t/reference-translation-stored-in-yml-file-in-navigation-yml-file/6661>\
**Category:** Help\
**Created:** [November 10, 2021, 7:18am UTC](https://talk.jekyllrb.com/t/reference-translation-stored-in-yml-file-in-navigation-yml-file/6661 "2021-11-10T07:18:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![keunes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/keunes/32/4923_2.png) [@keunes](https://talk.jekyllrb.com/u/keunes)\
**Post date:** [November 10, 2021, 7:18am UTC](https://talk.jekyllrb.com/t/reference-translation-stored-in-yml-file-in-navigation-yml-file/6661/1 "2021-11-10T07:18:28Z")

</div>

Hello,

In our navigation, we have the following loop:

```auto
{% for link in site.data.navbar %}
<div class="nav-item ml-2">
    <a class="nav-link" href="{{ site.baseurl }}{{ link.url }}">{{ link.title }}</a>
</div>
{% endfor %}

```

The loop refers to the file `_data/[locale]/navbar.yml`, which contains this:

```auto
- link:
  title: About
  url: /about
- link:
  title: Blog
  url: /blog

```

Now, there is one `navbar.yml` _per locale_ (per language). But as we already have the page titles translated in a main translation file in `_i18n/[locale].yml`:

```auto
## Page & menu titles
titles:
  blog: "Blog"
  about: "About"

```

We’re using the [jekyll-multiple-languages-plugin](https://github.com/kurtsson/jekyll-multiple-languages-plugin).

Rather including duplicate strings in our translation system (‘About’ from the page title variable, and from the navigation array item), I was thinking: can we not reference the translation string, which is stored in the translation yml file, in `navbar.yml` like this:

```auto
- link:
  title: {% t titles.about }
  url: /about
- link:
  title: {% t titles.about }
  url: /blog

```

I tried the above, but when building the site the following error is thrown: `found character that cannot start any token while scanning for the next token at line 2 column 11`

Is it correct that this is not possible, or did I just do something wrong in the execution? If what I attempt is not possible, would there be a workaround, so that we don’t need to have one `navbar.yml` per language?

Many thanks!

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [November 11, 2021, 7:57am UTC](https://talk.jekyllrb.com/t/reference-translation-stored-in-yml-file-in-navigation-yml-file/6661/2 "2021-11-11T07:57:50Z")

</div>

> [@keunes](#):
>
> `title: {% t titles.about }`

This doesn’t look like valid yaml or liquid.

And that is causing a syntax error.

What are you trying to do on this line?

If your goal is to reduce duplication, then have a base maybe the English and if no override is set for a language then use the base.

E.g.

English

```auto
- title: About
  url: /about

```

Some other

```auto
- url: /about

```

Then in your Liquid

```auto
{% assign title = item.title | default: site.data.engish[0].title %}

{{ title }}

```

But also I don’t know how to use the plugin

You can also try the approach with duplicates on a small scale and see if you error goes away. Then change on item without duplication to get it to work with better approach. That way you start from a working state and make small changes, to help narrow down exactly what does and doesn’t work.

---

<div class="post-metadata">

**Author:** ![keunes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/keunes/32/4923_2.png) [@keunes](https://talk.jekyllrb.com/u/keunes)\
**Post date:** [November 13, 2021, 3:01pm UTC](https://talk.jekyllrb.com/t/reference-translation-stored-in-yml-file-in-navigation-yml-file/6661/3 "2021-11-13T15:01:58Z")

</div>

Thanks @MichaelCurrin, you pointed me in the right direction there!

Instead of including the printed title in the `_data/[lang]/navbar.yml`, I now have a single `_data/navbar.yml` with not the actual texts, but just keys:

```auto
# note: entry must match page title key as used in _i18n/en.yml
- entry: about
  url: /about
- entry: blog
  url: /blog

```

Which I then use in `_includes/nav.html` to create the full string key that the translation plugin can pick up from `_i18n/[locale].yml` (instead of simply printing the ‘title’ for each item, taken from the navbar.yml):

```auto
{% for link in site.data.navbar %}
{% capture title %}titles.{{ link.entry }}{% endcapture %}
<div class="nav-item ml-2">
    <a class="nav-link" href="{{ site.baseurl }}{{ link.url }}">{% t {{ title }} %}</a>
</div>
{% endfor %}

```

The translations file `_i18n/[locale].yml` used by the plugin then looks like this (and if the site is generated in another language, it provides the translated version of the string):

```auto
titles:
  about: "About"
  blog: "Blog"

```

---

<div class="post-metadata">

**Author:** ![keunes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/keunes/32/4923_2.png) [@keunes](https://talk.jekyllrb.com/u/keunes)\
**Post date:** [November 14, 2021, 6:49pm UTC](https://talk.jekyllrb.com/t/reference-translation-stored-in-yml-file-in-navigation-yml-file/6661/4 "2021-11-14T18:49:58Z")

</div>

@MichaelCurrin The website in question is that of the open-source podcast manager for Android AntennaPod: [www.antennapod.org](http://www.antennapod.org). I’m preparing the site to be better translatable. I’m thinking just now: would you be open to doing a (quick) code review? I’m just building experience with Jekyll as I’m working on the site, so a pair of experienced eyes would be very welcome. Please don’t hesitate to say no, also 🙂

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [November 14, 2021, 8:52pm UTC](https://talk.jekyllrb.com/t/reference-translation-stored-in-yml-file-in-navigation-yml-file/6661/5 "2021-11-14T20:52:02Z")

</div>

Sure, you can assign me to “@” mention me on a GitHub PR and I can review.

Account on GH:

```auto
@MichaelCurrin

```
