PHP code example of willskates / translator

1. Go to this page and download the library: Download willskates/translator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

willskates / translator example snippets


$translator = new Translator();

$translator->useTranslation('Hello', 'Hallo');

$hello = $translator->translate('Hello');
//The value of $hello is 'Hallo'.

$translator->useTranslations(
    [
        'Hello' => 'Hallo',
        'Goodbye' => 'auf Wiedersehen'
    ]
);

$german = $translator->translations();

//$german is an array, assuming they were set it will contain ['Hello' => 'Hallo', 'Goodbye' => 'auf Wiedersehen'].

$deTranslator = new Translator();

$deTranslator->useTranslations(
    [
        'Hello' => 'Hallo',
        'Goodbye' => 'auf Wiedersehen'
    ]
);

$hello = $deTranslator->translate('Hello'); //Hallo
$goodbye = $deTranslator->translate('Goodbye'); //auf Wiedersehen

$broTranslator = new Translator();

$broTranslator->useTranslations(
    [
        'Hello' => 'Yo',
        'Goodbye' => 'Piece!'
    ]
);

$hello = $broTranslator->translate('Hello'); //Yo
$goodbye = $broTranslator->translate('Goodbye'); //Piece!