Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Jekyll Multiple Languages Navigation #175

Open
blogi-kriptovalyut opened this issue Aug 17, 2020 · 0 comments
Open

Jekyll Multiple Languages Navigation #175

blogi-kriptovalyut opened this issue Aug 17, 2020 · 0 comments

Comments

@blogi-kriptovalyut
Copy link

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant