alex-patterson-webdev/arp-translator

There is no license information available for the latest version (v1.0) of this package.

v1.0 2015-08-10 11:22 UTC

This package is auto-updated.

Last update: 2020-02-14 14:26:37 UTC


README

A generic PHP text translator which supports translating different languages at runtime.

Installation

Installation via composer

php composer.phar require alex-patterson-webdev/arp-translator 1.0

Translation Strategy

A translation strategy is an object implementing ArpTranslator\Strategy\StrategyInterface which performs the translation of the supplied text into the desired language.

The following strategies are supported.

  • \ArpTranslator\Strategy\EnglishToPigLatin
  • \ArpTranslator\Strategy\PigLatinToEnglish

Translator

To perform text translation create a new instance of the ArpTranslator\Translator class and supply the required translation strategy.

The example below uses the example "EnglishToPigLatin" translation strategy.

$translator = new \ArpTranslator\Translator(
    new \ArpTranslator\Strategy\EnglishToPigLatin
);

To produce the translation text simply call Translator::translate() with the source text.

$englishText = 'Some english text to translate';

$pigLatin = $translator->translate($englishText);

You can easily swap out the required strategy with another at runtime, without needing a new translator instance, by calling Translator::setStrategy().

$strategy = new \ArpTranslator\Strategy\PigLatinToEnglish;
$translator->setStrategy($strategy);

Tests

Test can be run using PHPUnit

phpunit /tests