Setup

Kirby has built-in support for multi-language sites.

Setup

Languages are being added in /site/config/config.php

c::set('languages', array(
  array(
    'code'    => 'en',
    'name'    => 'English',
    'default' => true,
    'locale'  => 'en_US',
    'url'     => '/',
  ),
  array(
    'code'    => 'de',
    'name'    => 'Deutsch',
    'locale'  => 'de_DE',
    'url'     => '/de',
  ),
));

As soon as one language is setup in the languages array, multi-language support is switched on.

2.4.0 +

Using different domains for each language

Since Kirby 2.4, Kirby supports cross-domain multi-language sites. You can define the domain for each language like this:

c::set('languages', array(
  array(
    'code'    => 'en',
    'name'    => 'English',
    'default' => true,
    'locale'  => 'en_US',
    'url'     => 'https://example.com',
  ),
  array(
    'code'    => 'de',
    'name'    => 'Deutsch',
    'locale'  => 'de_DE',
    'url'     => 'https://example.de',
  ),
));

You then need to make sure that both domains point to your Kirby site.

Detailed locale settings

If you need more control over your locale settings for each language, you can pass an array of locales:

c::set('languages', array(
  array(
    'code'    => 'en',
    'name'    => 'English',
    'default' => true,
    'url'     => '/',
    'locale'  => array(
      LC_COLLATE  => 'en_US.utf8',
      LC_MONETARY => 'en_US.utf8',
      LC_NUMERIC  => 'en_US.utf8',
      LC_TIME     => 'en_US.utf8',
      LC_MESSAGES => 'en_US.utf8',
      LC_CTYPE    => 'en_US.utf8'
    ),
  ),
  array(
    'code'    => 'de',
    'name'    => 'Deutsch',
    'url'     => '/de',
    'locale'  => array(
      LC_COLLATE  => 'de_DE.utf8',
      LC_MONETARY => 'de_DE.utf8',
      LC_NUMERIC  => 'de_DE.utf8',
      LC_TIME     => 'de_DE.utf8',
      LC_MESSAGES => 'de_DE.utf8',
      LC_CTYPE    => 'de_DE.utf8'
    ),
  ),
));

Automatic Language Detection

Kirby can detect the prefered language of the visitor. This has to be activated by adding:

c::set('language.detect', true);

Attention! Switching from single-language to multi-language

If you start with a single language setup and wish to switch to multiple languages later, you have to rename your text files to include the language code.

i.e.
projects.txt > projects.en.txt
myimage.jpg.txt > myimage.jpg.en.txt

This process is not yet handled by Kirby and can lead to broken content.

Date handlers

By default Kirby is using PHP's date function to format dates for pages and files. date() does not respect locale settings though and always creates English month and day names. You can now switch to strftime() as your primary date handler, which uses a different format for dates, but also supports translated month and day names. To switch the handler, add the following to your config:

c::set('date.handler', 'strftime');