I develop stuff and have opinions on things -
About me/Contact

Articles:

Pelican and internationalization

Since I started using Pelican for my blog, I tried to write most of my articles (when I’m motivated enough) in english and french at the same time. Pelican works with internationalization well enough by default, as long as the chosen theme can handle it (I am using the SoMA2 theme for which this is the case). However, it is impossible to generate a RSS feed by language and tag/category; I also tried to put different tags for each language, but that does not work.

In the latest (and first) french XMPP meetup, I met Jean-Baptiste who is quite experienced in that domain, and who explained to me it was possible using subsites (while I was complaining, as usual). Instead of offering a beer for the solution, he suggested I should write an article to describe the process. Once you know what to use it isn’t that complicated, but since I promised, here we go.

1 - Adding the i18n_subsites plugin

The easiest way to add the plugin is to clone the pelican_plugins repository which holds all the possible plugins, in order to get the one we want.

Doing it in the folder which contains the blog makes things simpler:

git clone https://github.com/getpelican/pelican-plugins.git

Next we have to configure the blog to use the plugin, so we must edit the pelicanconf.py file and add those lines:

PLUGIN_PATHS = ['pelican-plugins']
PLUGINS = ['i18n_subsites']

Then you only have to setup the languages you want to display on the website (I put here my very complex configuration):

I18N_SUBSITES = {
    'en': {
        'SITENAME': 'mathieui’s blog',
    },
    'fr': {
        'SITENAME': 'mathieui’s blog',
    }
}

That’s it, the blog is configured, it will:

  • Make en/ and fr/ subdirs in the pelican output folders
  • Duplicate the subdir for the configured default language and write the files to the root
  • Create specific RSS feeds for each tag and lang in the corresponding folders

2 - Nginx configuration

This step is optional, but since all my articles were available in the same directory by adding -fr to their name, going to the subsite layout broke all links to them.

Therefore, I added a simple nginx directive which acts as if the articles didn’t move, without tweaking pelican again.

location ~ /(.+)-fr.html {
    try_files $uri /fr/$1.html;
}
If you have remarks or suggestions concerning this article, please by all means contact me.