Note Just as explained in the product overview, DatoCMS is totally agnostic in terms of static site generators: it just allows you to dump content locally, and the rest is up to you. There are several ways to handle multiple languages with Jekyll — just as an example, take a look at this guide, or this plugin.
Within your dato.config.rb
file, you can easily switch between your locales like this:
# dato.config.rbI18n.locale = :endato.blog_posts.first.title # => "Hello world!"I18n.locale = :itdato.blog_posts.first.title # => "Ciao mondo!"
If you need to temporarily switch locale, and then restore the previous value, you can use I18n.with_locale
:
# dato.config.rbI18n.locale = :endato.blog_posts.first.title # => "Hello world!"I18n.with_locale('it') doI18n.locale # => :itdato.blog_posts.first.title # => "Ciao mondo!"endI18n.locale # => :endato.blog_posts.first.title # => "Hello world!"
You can also obtain the list of languages of your administrative area with I18n.available_locales
:
# dato.config.rbI18n.available_locales # => [ :en, :it ]
Here's an complete example that creates multiple versions of your articles, one for each available locale:
# dato.config.rb# inside the "_posts" directorydirectory "_posts" do# iterate over all the administrative area languagesI18n.available_locales.each do |locale|# switch to the nth localeI18n.with_locale(locale) do# iterate over the "Blog post" records...dato.blog_posts.each do |article|# ...and create a localized markdown file for each article!create_post "#{locale}-#{article.slug}.md" dofrontmatter(:yaml,title: article.title,language: locale,)content(article.content)endendendendend
DatoCMS allows a great deal of customization when dealing with localization. Check out these tutorial videos for a hands-on learning experience: