Accept-Language test

This is a quick test of using MultiViews in apache2 to serve two versions of this article: this version in English and another in Swedish. Which one you see depends on what your browser has sent in the Accept-Language HTTP header. You can get the Swedish version by clicking "sv" in "Translations" further up.

In order to get this working right I had to fiddle around with pelican in a number of ways. First I had to edit and change the output filenames and URLs like so:

ARTICLE_URL = '{category}/{date:%Y}/{date:%m}/{date:%d}/{slug}/'
ARTICLE_SAVE_AS = ARTICLE_URL + 'index.html.en'
ARTICLE_LANG_URL = ARTICLE_URL + 'index.html.{lang}'
ARTICLE_LANG_SAVE_AS = ARTICLE_URL + 'index.html.{lang}'

The ARTICLE_LANG_URL thing is probably not necessary, as we shall see.

I tried various ways to get "Translations" to always link to the other translation explicitly (sv -> en and vice versa). This didn't end up working, so I just hardcoded the template to insert links to both language variants if there are translations available. Since I am only going to write content in English or Swedish, always linking to index.html.en and was enough. This site is based on the notmyidea template, so I replaced the content of notmyidea/templates/translations.html with:

{% macro translations_for(article) %}
{% if article.translations %}
Translations: <a href="index.html.en">en</a>, <a href="">sv</a>
{% endif %}
{% endmacro %}

That should be about it ☺