Cecil logo Cecil
What's on this page

Translate a site into multiple languages

Cecil handles multilingual sites natively: declare the languages, add translated pages, then link them together and translate your templates.

Declare languages

Define the main language and the list of available languages in cecil.yml:

language: en
languages:
  - code: en
    name: English
    locale: en_US
  - code: fr
    name: Français
    locale: fr_FR
    config:
      title: "Mon site en français"

Options stored under the config key of a language override the global ones (here the site title).

Translate a page

Duplicate the reference page and suffix its file name with the language code:

pages/
├─ about.md    # the reference page
└─ about.fr.md # the french version

Use the slug variable to translate the URL of the page:

---
title: À propos
slug: a-propos
---

about.md is published to /about/ and about.fr.md to /fr/a-propos/.

Each page exposes its translations with page.translations. Add a language switcher to your template:

{% for p in page.translations %}
  <a href="{{ url(p) }}" hreflang="{{ p.language }}">{{ site.language.name(p.language) }}</a>
{% endfor %}

You can also include the built-in partial: {{ include('partials/languages.html.twig') }}.

Translate template strings

Wrap texts with the trans tag or filter:

{% trans %}Read more{% endtrans %}
{{ 'Read more'|trans }}

Then add a translation file named after the language locale in the translations directory:

# translations/messages.fr_FR.yaml
Read more: Lire la suite

Extract the strings of your templates with:

php cecil.phar util:translations:extract --locale=fr_FR --save