untra / polyglot

:abc: Multilingual and i18n support tool for Jekyll Blogs
https://polyglot.untra.io
MIT License
416 stars 59 forks source link

Localising the default layout #81

Closed BeMrTeal closed 7 months ago

BeMrTeal commented 7 years ago

This is more a question than an issue.

How would I localise the default layout in order to have my includes in different languages?

I managed to get my menu to dynamically sort the language with this liquid code:

{% assign pages_list = site.pages | sort: 'index' %}
          {% assign written = "" | split: '' %}
          {% for node in pages_list %}
            {% if written contains node.title %}
              {% continue %}
            {% endif %}
            {% if node.title != null %}
              {% if node.layout == "page" and node.lang == site.active_lang %}
          <li class="nav-item mx-3">
            <a class="nav-link header--nav__link {% if page.url == node.url %} active {% endif %}" href="{{site.baseurl}}{{ node.url }}">{{ node.title }}</a>
          </li>
              {% endif %}
              {% assign written = written | push: node.title %}
            {% endif %}
          {% endfor %}

but I wasn't able to get my default layout to pick the includes accordingly to the site.active_language any suggestion?

Cheers

BeMrTeal commented 7 years ago

I see that in the LogRhythm website you have subdomains for languages but how do you build the home pages in different languages? Do you have a different layout for each language? How did you set it so you can have Jekyll to build it?

I'd love to have a tip on how to do that for my site.

untra commented 7 years ago

Hey @bernardomed,

So I cannot tell you how the Logrhythm website does it's full layout. In fact they made recent changes that I was not involved in. I'm not sure how they recently setup the language subdomains, so I cannot help you with that.

I can tell you how the example polyglot website works. In fact, it's source code is included on this repo.

how do you build the home pages in different languages?

You are going to want to make multiple index.md pages for each of your languages (index.es.md, index.en.md, ...) In the headers, set the correct lang for each page. I would guess that is the secret sauce to what you're missing.

Cheers, @untra

BeMrTeal commented 7 years ago

Thanks mate, I'll give it a try.

bitmoji

BeMrTeal commented 7 years ago

Right @untra,

I have one index.md for each language (index.es.md, index.en.md, index.pt.md), one layout > home.html for each language (home-en.html ... ) and one layout > default.html for each language (default-en.html ...)

I also have one of each _includes file for each language.

I discovered that if I change the language and layout of the index.md file, it changes the layout to the required language so the million dollars question is: What do I have to do in order to get the correct index.md file to be loaded when the corresponded language is selected by the user?

Once again, thanks for your help.

bitmoji

BeMrTeal commented 7 years ago

I just realised that the index page any language is compiled with the default language so this is clearly me not knowing how to setup correctly the languages in the _config.yml file.

bitmoji