A multilingual approach for Jekyll/Octopress sites
A detailed look into how this plugin works can be found in this blog post.
- 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
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.
Add a languages array to your _config.yml
# The first language is the default language of your site
languages: ['en', 'de']
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.
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:
- Create
source/index-root.htmlwith custom welcome message and a header:
---
layout: root
permalink: /index.html
language: none
---
Please select language...
- Create
source/_layouts/root.htmlif needed (to includehead.htmland 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>
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).
Feel free to ask for help, if you encounter any issues.