Document site
December 27, 2015 · View on GitHub
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.$ext2014-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/$langin the destination directory.For example:
_site/$lang. If the$langisen, 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
-
Here is a sample projcet:
-
Here is the website of the sample projcet:
Variables
Variables for pages and posts
-
page.languageThe language in this Page or Post.
-
page.is_default_languageIf this Page or Post is in the default language, its value is
true
Variables only for posts
-
page.next_in_languageNext post in the same language with this post.
-
page.previous_in_languagePrevious post in the same language with this post.
Variables for site
-
site.pages_by_languageIt is all the
site.pagesgrouped 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_languageIt is similar to
site.pages_by_language, contains all thesite.postsgrouped by languages.
The sample of variables
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 toindex.html.For example:
index.md,index.html. -
Page named
index.$lang.$extis the paginate template for the other languages(short for$lang).For example:
index.cn.md,index.html.
The variables
- Same with jekyll-paginate
The sample of pagination
Github Pages Issue
Try to use Jekyll plugins on Github Pages is a little complicated.
And here is a solution.
Contributors
Thanks
t tag: https://github.com/screeninteraction/jekyll-multiple-languages-plugin