willskates/translator

Translator is a very simple string translation library for PHP.

1.1.0 2016-02-09 19:18 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

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

###Setting a Translation.


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

###Getting a Translation.


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

###Setting a list of translations.


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

###Getting a list of translations.


	<?php
		$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.


	<?php

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

	?>