Translations
Monti has a small, custom translation system. Strings are wrapped in the __() helper and translated at print-time using files loaded for the active language.
If no translation is found for a string, __() simply returns the original string unchanged.
Available and default language
Both are set in config/app.php:
\Project::get()->getLanguages(); // ["en", "it"]
\Project::get()->getDefaultLanguage(); // "en"
\Project::get()->hasLanguage("fr"); // false
Adding a translation file
Translation files are loaded from the locales folder at the project root, and from a locales folder inside each active module. Each file must be named <anything>.<language_code>.php (or .json) and return (or contain, for JSON) a map from the original string to its translation:
<?php
return [
"Welcome!" => "Benvenuto!",
"Welcome :name!" => "Benvenuto :name!",
];
The same file, as JSON:
Getting and setting the active language
If nothing was explicitly set, Monti determines the active language, in order: the active_language cookie, then the browser's Accept-Language header, then the configured default.
\Language::set() silently does nothing if the target language is not listed in app.languages.available.