{% 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:
- link:
title: About
url: /about
- link:
title: Blog
url: /blog
Now, there is one navbar.ymlper locale (per language). But as we already have the page titles translated in a main translation file in _i18n/[locale].yml:
## Page & menu titles
titles:
blog: "Blog"
about: "About"
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:
- 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?
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
- title: About
url: /about
Some other
- url: /about
Then in your Liquid
{% 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.
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:
# 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):
{% 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):
@MichaelCurrin The website in question is that of the open-source podcast manager for Android AntennaPod: 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