Internationalisation

Saturn provides full support for multilingual applications. Database schema automatically generates columns for multiple languages, and queries are translated transparently. Translation in routes and views can be implemented with the global l() function. This function takes an associative array as argument, returning the value corresponding to the current language.

application/news/views/index.php
<h1><?= l([
    'en' => 'News',
    'nl' => 'Nieuws',
    'fr' => 'Nouvelles',
]) ?></h1>
application/news/news.php
public static function route($router)
{
    $router->get(l([
        'en' => 'news',
        'nl' => 'nieuws',
        'fr' => 'nouvelles',
    ]), 'index');
}

Language files

An alternative way of using the l() function is by using language files. Create a folder named languages alongside your controller, and add a txt file with a language identifier as filename. In this file you can add translatable strings, each one on a new line containing name and value, separated by an equals sign. You can then call the l() function with just the name of the translatable string as parameter.

application/news/languages/nl.txt
News = Nieuws
news = nieuws
Page = Pagina
No news at this time = Momenteel geen nieuws
application/news/views/index.php
<h1><?= l('News') ?></h1>
String names are case sensitive and shared accross all controllers. Make your string names as descriptive as possible to avoid conflicts.
Edit this page on GitHub Updated at Mon, Feb 14, 2022