jekyll-multiple-languages-plugin icon indicating copy to clipboard operation
jekyll-multiple-languages-plugin copied to clipboard

Jekyll Multiple Languages Navigation

Open blogi-kriptovalyut opened this issue 5 years ago • 0 comments

Hey. I've been struggling for a week now to translate the navigation menu into several languages. I found many examples on Google where people were able to customize the translation of the menu. The articles were from 2018, maybe something has changed in the topic or in Jekyll?

How do I create a multilingual menu:

file: _data/navigation.yml

languages:
  - language: "en"
    links:
    - title: "About"
      url: /about/
    - title: "Archives"
      url: /archives/
    - title: "GitHub"
      url: https://github.com
    - title: "pt"
      url: /pt/
  - language: "pt"
    links:
    - title: "Sobre"
      url: /sobre/
    - title: "Arquivos"
      url: /arquivos/
    - title: "GitHub"
      url: https://github.com
    - title: "en"
      url: /

Two languages, two subtrees with the correct URLs for either.

Then I needed to incorporate that into the _includes/masthead.html

{% for item in site.data.navigation.languages %}
  {% if item.language == page.lang %}
    {% for link in item.links %}
      {% if link.url contains "http" %}
        {% assign url = link.url %}
      {% else %}
        {% assign url = link.url | relative_url %}
      {% endif %}
      <a class="page-link" href="{{ url }}">{{ link.title }}</a>
    {% endfor %}
  {% endif %}
{% endfor %}

By this design, it is not displayed even without the plugin "Jekyll Multiple Languages Plugin" in a clean theme "Minimal Mistakes"

I tried simpler and changed the standard theme code

    <ul class="visible-links">
          {%- for link in site.data.navigation.languages -%}
            <li class="masthead__menu-item">
              <a href="{{ link.url | relative_url }}"{% if link.description %} title="{{ link.description }}"{% endif %}>{{ link.title }}</a>
            </li>
          {%- endfor -%}
        </ul>

This displays all menu items in all languages.

Please help me figure it out because I think you are the best community!

blogi-kriptovalyut avatar Aug 17 '20 09:08 blogi-kriptovalyut