Skip to content

Wonderful structure of the multilanguage blog

Roman Krylov edited this page Jul 27, 2017 · 2 revisions

Arrange the article files like this:

source/blog/2017/07/22/first_words/
 - /index.en.html.md
 - /index.ru.html.md

To get this sitemap when assembling:

Two blog articles

=== ENGLISH BLOG ARTICLE
Path	en/blog/2017/01/09/first_words/index.html
URL	/en/blog/2017/01/09/first_words/
Source File	source/blog/2017/01/09/first_words/index.en.html.md
Data	{:title=>"First words"}
Options	{:locale=>:en, :lang=>:en}
Locals	lang, locale

=== RUSSIAN BLOG ARTICLE
Path	blog/2017/01/09/first_words/index.html
URL	/blog/2017/01/09/first_words/
Source File	source/blog/2017/01/09/first_words/index.ru.html.md
Data	{:title=>"Первые слова"}
Options	{:locale=>:ru, :lang=>:ru}
Locals	lang, locale

Here are the settings in config.rb

langs = [:ru, :en]
root_lang = :ru
activate :i18n, :langs => langs, :mount_at_root => root_lang

langs.each do |lang|
  is_root_lang = lang == root_lang
  activate :blog do |blog|
    blog.name = lang
    blog.permalink = "#{'{locale}/' unless is_root_lang}blog/{year}/{month}/{day}/{title}"
    blog.sources = "#{'{locale}/' unless is_root_lang}blog/{year}/{month}/{day}/{title}/index.html"
  end
end

activate :directory_indexes

Use this!

# get current blog articles
blog(I18n.locale).articles
Clone this wiki locally