kurtsson / jekyll-multiple-languages-plugin

I18n support for Jekyll and Octopress
MIT License
927 stars 203 forks source link

Falling back to default lang when iterating on an array #98

Closed HugoCrd closed 4 years ago

HugoCrd commented 7 years ago

Hi!

First, thanks a lot for this very useful gem.

I'm looking for a way to iterate on an array and falling back to site.default_lang if site.lang does not contain the translation. The for o in site.translations[site.lang].somethings solution does work, but not if I want to fall back to default lang.

For now I came with the following solution which I don't find very elegant:

{% if site.translations[site.lang].blocks %}
  {% assign blocks = site.translations[site.lang].blocks %}
{% else %}
  {% assign blocks = site.translations[site.default_lang].blocks %}
{% endif %}

{% for block in blocks %}
   {{block}}
{% endfor %}

Is there a simpler way to achieve this that I did not think about? If not, is this something you would be interesting in supporting?

Thanks again, Hugo

hanniabu commented 4 years ago

From what I've seen, the current version uses the default language as a fallback. Found this issue while trying to figure out how to not have that behavior.

kurtsson commented 4 years ago

Should be fixed by #130 right?