Skip to content
Build multilingual applications
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Translator component

The Translator component aids in building multilingual applications.

Creating the Translator

$translator = new Gobline\Translator\Translator();

Adding a Translation File

$translator->addTranslationFile(__DIR__.'./translations/fr/messages.php', 'fr');

At the moment, only PHP arrays are supported.

Adding a Directory of Translation Files

$translator->addTranslationFile(__DIR__.'./translations/nl', 'nl');

The directory will be searched recursively for translations files.

Adding an Array of Translations

$translator->addTranslationArray(['First name' => 'Vorname'], 'de');

Translate a Message

$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
You can’t perform that action at this time.