willskates/translator

Translator is a very simple string translation library for PHP.

1.1.0 2016-02-09 19:18 UTC

This package is not auto-updated.

Last update: 2024-12-17 04:51:42 UTC


README

Translator is a very simple string translation library for PHP.

Build

Build Status

How To Install.

The best way to install Translator is through composer.

{
    "require": {
        "willskates/translator": "1.1.0"
    }
}

Usage.

Creating the Translator Object

$translator = new Translator();

Setting a Translation.

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

Getting a Translation.

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

Setting a list of translations.

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

Getting a list of translations.

$german = $translator->translations();

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

Setting and using the default language.

$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!