willskates/translator

Translator is a very simple string translation library for PHP.

Installs: 0

Dependents: 0

Stars: 1

Watchers: 2

Language: PHP

1.0.1 2013-06-20 22:49 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": "v1.0.1"
        }
    }

Usage.

Creating the Translator Object

    <?php
        $translator = new Translator();
    ?>

Setting a Translation.

    <?php
        $translator->setTranslation('Hello', 'Hallo', 'de');
    ?>

Getting a Translation.

    <?php
        $hello = $translator->getTranslation('Hello', 'de');
        //The value of $hello is 'Hallo'.
    ?>

Setting a list of translations.

    <?php
        $translator->setTranslations(
            array(
                'Hello' => 'Hallo',
                'Goodbye' => 'auf Wiedersehen'
            ),
            'de'
        );
    ?>

Getting a list of translations.

    <?php
        $german = $translator->getTranslations('de');

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

Setting and using the default language.

    <?php
        $translator->setTranslations(
            array(
                'Hello' => 'Hallo',
                'Goodbye' => 'auf Wiedersehen'
            ),
            'de'
        );

        $translator->setTranslations(
            array(
                'Hello' => 'Yo',
                'Goodbye' => 'Piece!'
            ),
            'bro'
        );

        $translator->setDefaultLang('de');
        $hello = $translator->getTranslation('Hello'); //Hallo
        $goodbye = $translator->getTranslation('Goodbye'); //auf Wiedersehen

        $translator->setDefaultLang('bro');
        $hello = $translator->getTranslation('Hello'); //Yo
        $goodbye = $translator->getTranslation('Goodbye'); //Piece!

    ?>