Translations
Nicotine has language files defined per Admin side and Site side. Depending on HTTP request side, Nicotine will load appropriate language file. Example:
Create a file ro.php for Romanian language, in the folder workspace/site/langs/. Add the following code in that file:
<?php
declare(strict_types=1);
use nicotine\Registry;
Registry::set('language', [
'Hex color is %1$s, and the number is %2$d.' => 'Numarul este %2$d, iar culoarea este %1$s.',
// ...more translations here
]);
?>
Use setcookie() PHP native function, to set a cookie called language, with the value of ro.
Now, in your view - Site side, as in the example, add the following:
<?php print sprintf(__('Hex color is %1$s, and the number is %2$d.'), '#222', 2_000); ?>
On page refresh outputs: Numarul este 2000, iar culoarea este #222.
For Admin side, rules are the same. Note that arguments format are those used for sprintf() native PHP function. You can read more about them here.
As a security measure, language cookie value cannot contain .., in order to block file injection, so that users cannot navigate up into folders.
Note that HTML special characters aren't escaped by the helper __() since the translations are made by the programmer. You should use for example " instead of " in the language file.
Also note that if the translation fails, e.g. file or translation doesn't exists the helper will use source code string provided, as a fallback, and no errors will occur.