jekyll-multiple-languages

jekyll-multiple-languages

A Multiple Languages plugin for Jekyll

It can work with Jekyll 3 now. Happy coding!

Document site

Visit Project Page for more information

中文版文档


What is it?

Jekyll is very powerful. It is very conveniect to write bolg with Jekyll.

If we write mainly in English, and sometimes in other languages, now we can do this in a easy way.

Name rule

THe default language:

  • Page: $page_name.$ext. For example: index.md, about.md.

  • Post: _posts/$dir_pre/$date-$post_name.$ext. For example: _posts/blog/2014-02-26-hi.md.

The other language, short as $lang, put $lang and a dot . after $page_name or $post_name

  • Page: page_name.$lang.$ext, for example:

    index.md => index.cn.md

  • Post: _posts/$dir_pre/$date-$post_name.$ext

    2014-02-26.hi.md => 2014-02-26-hi.cn.md

Build result

  • The default language will build into destination directory as usually, _site, for example.

  • The other language (mark as: $lang), will build into the subdirectory /$lang in the destination directory.

    For example: _site/$lang. If the $lang is en, will be built into _site/en.

Installation & Configure

Installation

gem install jekyll-multiple-languages

If you want you use pagination, you should install jekyll-paginate as well.

gem install jekyll-paginate

Configure

  • _config.yml

    # add this plugin to gems
    gems:           ['jekyll-multiple-languages']
    # if you want to use pagination, you should add jekyll-paginate into gems
    # and make sure it is in front of jekyll-multiple-languages
    # gems:           ['jekyll-paginate', 'jekyll-multiple-languages']
    
    # The all languages used
    languages:          ['en', 'cn']
    
    # If not config, the first item of languages will be used as the default.
    language_default:   'en'
    

Sample

Variables

Variables for pages and posts

  • page.language

    The language in this Page or Post.

  • page.is_default_language

    If this Page or Post is in the default language, its value is true

Variables only for posts

  • page.next_in_language

    Next post in the same language with this post.

  • page.previous_in_language

    Previous post in the same language with this post.

Variables for site

  • site.pages_by_language

    It is all the site.pages grouped by languages.

    It is a hash. The key is the language and the value is all of the Pages in this kind of language.

    The value is a list.

  • site.posts_by_language

    It is similar to site.pages_by_language, contains all the site.posts grouped by languages.

The sample of variables

http://jekyll-langs-sample.liaohuqiu.net/

Data

  • You can create a data file in the directory _data, for example: i18n.yaml:

    en:
        previous_page: Previous
        next_page:    Next
    
    cn:
        previous_page: 上一页
        next_page:    下一页
    
  • Then use the language variables in pagination.html:

    <li>
    <a href="{{ "{{ paginator.previous_page_path " }}}}" aria-label="Previous">
        <span>{{ "{{ site.data.i18n[page.language].previous_page " }}}}</span>
    </a>
    </li>
    

Paginate

This plugin enables that we can write blog in multiple languages easily, it also enables that we can use any files that end with differents extensions.

The template

  • Page named index.* is the paginate template for default language, no limited to index.html.

    For example: index.md, index.html.

  • Page named index.$lang.$ext is the paginate template for the other languages(short for $lang).

    For example: index.cn.md, index.html.

The variables

The sample of pagination

http://jekyll-langs-sample.liaohuqiu.net/

Github Pages Issue

Try to use Jekyll plugins on Github Pages is a little complicated.

And here is a solution.


Contributors

cbergmann kuka

Thanks

t tag: https://github.com/screeninteraction/jekyll-multiple-languages-plugin