kurtsson / jekyll-multiple-languages-plugin

I18n support for Jekyll and Octopress
MIT License
923 stars 201 forks source link

Different behavior for BUILD and SERVE #159

Closed kwisatz closed 12 months ago

kwisatz commented 4 years ago

We observed that jekyll serve and jekyll build seem to behave differently in regards to site.translations. Whereas the serve process seems to build a hash from all available languages, then build the site, the build process seems to start building a first version with only that locale present in the site.translations hash.

Consider the following snippet:

               <ul class="dropdown-menu">
                  {% for language in site.languages %}
                  <li class="{% if site.lang == language %}lang-active{% endif %}">
                    <a
                      href="{{ site.baseurl_root }}/{% if language != 'en' %}{{ language }}{% endif %}{% if page.url != '/' %}{{ page.url }}{% endif %}"
                      title="{{ site.translations[language]['meta']['name'] }}">
                        {{ site.translations[language]['meta']['name'] }}
                    </a>
                  </li>
                  {% endfor %}
                </ul>

And the following yaml files:

meta:
  name: English
meta:
  name: Français
meta:
  name: Deutsch

In a serve context, this drop-down will correctly display links for all locales defined for the project. However, in a build context, the dropdown for the first locale version will have empty values for any locale > 1, the second locale will only have values for 1 & 2 and the third locale version will have values for 1, 2 and 3.

So my assumption is that during the first run (1st locale), the site.translations hash does not yet have values for any locales other than that very first locale.

Can someone confirm that assumption and maybe explain why this difference exists?

figgles commented 1 year ago

I found this issue as well. The analysis by OP is correct:

So my assumption is that during the first run (1st locale), the site.translations hash does not yet have values for any locales other than that very first locale.

This would be fixed by: https://github.com/kurtsson/jekyll-multiple-languages-plugin/pull/207

shushugah commented 12 months ago

Thank you @figgles for fixing it!