jekyll-multilingual

jekyll-multilingual

A multilingual approach for Jekyll/Octopress sites

jekyll-multilingual

A multilingual approach for Jekyll/Octopress sites

A detailed look into how this plugin works can be found in this blog post.

Features

  • Supports both multilingual and single language posts/pages
  • Supports translation of static text
  • Supports conversion of pages generated by third-party plugins (Note: might not work in every case)
  • Supports ability to indicate a post was written in a particular language

How to use the plugin

put the two Ruby files in your project's _plugins/ folder.

This plugin might not work with every third-party plugin out there. You will need to adapt them to support multiple languages.

Configuration

Add a languages array to your _config.yml

# The first language is the default language of your site
languages: ['en', 'de']

Defining a language for your files

This plugin supports two kinds of posts/pages:

  • Single-language (i.e. only written in a particular language, but still being shown in other languages)
  • multilingual (i.e. one post/page per language.)

Single-language posts/pages have a primary language that is indicated by a tag in the post's/page's front-matter:
language: en

Multilingual posts/pages define their language in the filename (any language tag in the front-matter is ignored):

  • 2014-08-04-foo-bar.en.md (for posts)
  • foo-bar.en.md for pages

Of course this works with .md, .markdown and .html file extensions.

File lacking any of the above are considered to be written in the default language.

Preventing a page from being copied into the language folder

When you use this plugin, you automatically define a default language (i.e. the first language in your languages array). Sometimes, you need a page that is created at the root of your site and not in the language specific subfolders.

How do you do this? Simple: you set the language to "none".

Example: You're hosting a blog on github pages and want index page to be some kind of a gateway where visitor has to select language (or it's selected by JavaScript after analyzing Accept header reflected by some external server).

Steps:

  1. Create source/index-root.html with custom welcome message and a header:
---
layout: root
permalink: /index.html
language: none
---
Please select language...
  1. Create source/_layouts/root.html if needed (to include head.html and so on), example:
{% capture root_url %}{{ site.root | strip_slash }}{% endcapture %}
{% include head.html %}

<body>
    <div class="container">
        <div id="content" class="inner">{{ content | expand_urls: root_url }}</div>
        </div>
</body>
</html>

Inspiration

Full credit should go to the Jekyll Multiple Languages Plugin. The translation code is heavily based on their work (and a copy for the most part).

Contributers

Contact

Feel free to ask for help, if you encounter any issues.