Making a multilingual website with collections

Because it involved quite a bit of trial and error, I’m sharing this blog post here: Making a multilingual website with Jekyll collections. Perhaps it’s of help when you’re also adding translations to your site :slight_smile:

4 Likes

Thank you. You have inspired me! I have improved your solution (IMO). The following code respects collections and sets a language parameter based on a folder within the collection:

file structure:

_posts
  en
    2020-01-01-test-post.md
    2020-01-02-second-post.md
  nl
    2020-01-01-testbericht.md
    2020-01-02-tweede-bericht.md
_customcollection
  en
    first-post.md
  nl
    eerste-bericht.md

_config:

defaults:
- scope:
    path: '_posts/en'
  values:
    permalink: 'news/:title'
    language: en
- scope:
    path: '_posts/nl'
  values:
    permalink: 'nieuws/:title'
    language: nl
- scope:
    path: '_customcollection/en'
  values:
    permalink: 'custom/:title'
    language: en
- scope:
    path: '_customcollection/nl'
  values:
    permalink: 'maatwerk/:title'
    language: nl

layout file:

{% assign siteposts = site.posts | where: 'page',page.language %}
{% for item in siteposts limit:20 %}
  ...
{% endfor %}

I love it! Be careful though: site.posts is a collection too. That means that if you add collections, you will have to add them to the siteposts variable. For instance like this: {{ site.pages | concat: site.documents }}.

Can you create a directory with all content (pages, posts) for each language with your approach?

Thanks! I have updated my post with a custom collection and wrote an article about my approach here: https://www.usecue.com/blog/multilingual-jekyll-websites/