Locomotive CMS provides plenty of features aimed to support international users. It's packed with multilingual admin interface as well as number of primitives that help to easily build complex multilingual sites.

Multiple locales

First off, you have to declare the set of locales before teaching your site the new languages. Change the following settings in config/site.yml:

locales: [en, fr]

Since now, you've got an access to all i18n features bounded by these two particular locales.


Once we declared the list of locales that we're going to support, router will recognize their codes in the beginning of the url, otherwise it'll use the default one. So any visitor, if she knew which locales are supported, can see the site in desired locale just by placing its code in front of the url. Hm... Not really convenient, right? There should be some way to explicitly give user information on available locales. And it's there.

Meet the locale_switcher! This is a helper that produces the set of links to the current page for all supported locales:

{{ locale_switcher }}

Turns into...

<div id="locale-switcher">
  <a href="/features" class="current en">en</a>
  <a href="/fr/fonctionnalites" class="fr">fr</a>

There are some options available:

Option Value Description

Content of the links
(default: iso)
iso Locale code as set in settings: de, fr, en, ...etc
locale Fancy name of locale: Deutsch, Français, English, ...etc
title The page title translated to the target locale

(default: "|")
Any string String to separate links

The customized call might look like...

{{ locale_switcher label: title, sep: ">>" }}

Translation of Strings

If you need to translate some pieces of template, translate filter comes to help. It just substitutes the key with associated translation according to current locale. Use it as follows in the template:

{{ 'some_meaningful_key' | translate }}

The place where you store the translations is config/translations.yml:

  en: I'm translated string, yay!
  fr: Je suis la ligne traduite, hourra!

If your current locale is en, it'll appear like "I'm translated string, yay!" on the page.

Translation of Content

The Locomotive's approach to translation of the content is amazing. It's really transparent. Every field can be translated, even files, which is extremely useful if you store images with captions or documents in different locales there. You may choose whether translate field or not on creation of content-type using localize option.

Once content-type is setup, it's really easy to manage translated content using admin interface. But you may want to see translated entries in development. If that's the case, just use locale codes as sub-keys as we did before. Say if you have content-type thing with localized field description, it'll look like following in data/things.yml:

 - "First thing":
       en: Something
       fr: Quelque chose


Finally you may want to setup the timezone in config/site.yml:

timezone: Paris

It's important to properly display date of creation of content entries.

© 2023 LocomotiveCMS Terms of use Privacy Policy
Back to top