3
votes

I speak fluently in French and English. I would like my website to be displayed in either language, depending on the visitor’s language setting. For the record, this information is provided by the visitor’s browser, a Accept-Language HTTP header.

As far as I know, the best (and only?) way to achieve that is by using Apache’s mod_negotiation. Considering the following tree structure:

.
├── page.html.en
└── page.html.fr

Visiting page.html displays the page in either English or French. I would like to use a CMS which makes use of this i18n method.


I am considering using Jekyll for my website. In the directory structure below, I guess I need to write my includes, layouts and posts in both French and English (2013-06-04-Omelette-du-fromage.markdown.en, etc.).

.
├── _config.yml
├── _includes
│   ├── footer.html
│   └── header.html
├── index.html
├── _layouts
│   ├── page.html
│   └── post.html
├── _posts
│   └── 2013-06-04-Omelette-du-fromage.markdown
└── _site

So, the question is: How can I implement automatic internationalization on my website, with a CMS? I hardly imagine myself writing all my website by hand.

1

1 Answers

0
votes

Jekyll does not support i18n by itself.

You will probably need to translate your includes and layouts yourself. You will probably want to name your includes properly - footer_en.html for example. Same with your layouts - call them page_en.html, post.en.html etc. In YAMl front matter, specify which layout has to be used:

---
layout: post_en
lang: en
---

If you set the lang attribute as custom YAML Front matter, you can then even render only post from the desired language in post lists, e.g. when you have a tag cloud or a list of specific posts in a category.

This will, however, most likely break pagination. You can avoid that by doubling the elemnts per page for the paginator, and then manually discarding the elements that have the wrong language in your for loop:

{% for post in paginator.posts %}
    {% if post.lang == 'en' %}
    <!--- display --->
    {% endif %}
{% endfor %}

There will ofc be issues with pagination when you do not translate every post (you might end up having more then the expected amount of posts per page if posts are missing in the other language).

If you are not afraid of using plugins, there might even be a better alternative.