The Translator component aids in building multilingual applications.
$translator = new Gobline\Translator\Translator();
$translator->addTranslationFile(__DIR__.'./translations/fr/messages.php', 'fr');
At the moment, only PHP arrays are supported.
$translator->addTranslationFile(__DIR__.'./translations/nl', 'nl');
The directory will be searched recursively for translations files.
$translator->addTranslationArray(['First name' => 'Vorname'], 'de');
$translator->setDefaultLanguage('fr'); // you can set a default language
$translator->translate('First name'); // no language specified, using def. lang "fr" and returns "Prénom"
$translator->translate('First name', null, 'nl'); // returns "Voornaam"
$translator->translate('First name', null, 'it'); // no Italian translations provided, returns "First name"
$translator->translate('User %1 created', 'John'); // returns "Utilisateur John créé"
$translator->translate('User %1 %2 created', ['John', 'Smith']); // returns "Utilisateur John Smith créé"
You can install the Translator component using the dependency management tool Composer. Run the require command to resolve and download the dependencies:
composer require gobline/translate