untra / polyglot

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

Won't switch back to default language in Github Pages #194

Open alejandrocs98 opened 7 months ago

alejandrocs98 commented 7 months ago

Hi! Thanks for developing this plug-in, I think is awesome. I am having a problem when deploying my website in Github Pages, it is working to switch from the default language to the other one, but switching back to the default language does not works. When I tested locally in my computer locally it works perfectly. i will really appreciate if you could help me to solve this, I have not been able to spot the issue. Here is how I have defined my language switcher in my header.html:

{% assign lang = site.active_lang %}
{% for l in site.languages %}
  <li><a {% if l == lang %}style="font-weight: bold;"{% endif %}
    {% static_href %}href="{% if l == site.default_lang %}{{site.baseurl}}{{page.url}}{% else %}{{site.baseurl}}/{{ l }}{{page.url}}{% endif %}"{% endstatic_href %}>{{ l }} {% if l == 'en' %} <span class="flag-icon flag-icon-gbr"></span> {% else %} <span class="flag-icon flag-icon-esp"></span> {% endif %} </a></li>
  {% if forloop.last == false %}<li role="separator" class="divider"></li>{% endif %}
{% endfor %}

And here is an example of the front matter for one of my pages:

---
title: "Team"
layout: gridlay
excerpt: "BCEM - Team"
sitemap: false
permalink: team/
lang: en
inheader_order: 1
---

Just in case here is my project in case it helps and you have time to check it: https://github.com/alejandrocs98/multilingual-research-group-website

Thanks!

george-gca commented 7 months ago

Maybe the problem is the if/else inside the {% static_href %} tag. Try to invert this, like using the if/else outside. This is the only difference I can see from your code to mine. To check where I do this search for static_href inside this code. You can see it working in my demo site.

alejandrocs98 commented 7 months ago

Thanks for your suggestion! I already changed. It still does not work and I don't understand why but at least I believe that the code looks much better now. Also, you have a very cool website template!! I might switch to using yours instead!! :)

george-gca commented 7 months ago

Feel free to use it, it was created for academics. It is actually a fork of al-folio with multilingual support, but I am also currently a maintainer there, so I try to contribute there and keep my template in sync with the latest al-folio changes.

Another difference I just found is in our config files, where I also use lang_from_path: true for polyglot, so I can keep my files for different languages in different directories. Maybe that helps.