Potsky\LaravelLocalizationHelpers\Factory\Localization::translate PHP Method

translate() public method

public translate ( string $word, string $to, null $from = null ) : mixed
$word string
$to string
$from null
return mixed
    public function translate($word, $to, $from = null)
    {
        if (is_null($this->translator)) {
            $translator = Config::get(self::PREFIX_LARAVEL_CONFIG . 'translator');
            $this->translator = new Translator('Microsoft', array('client_id' => Config::get(self::PREFIX_LARAVEL_CONFIG . 'translators.' . $translator . '.client_id'), 'client_secret' => Config::get(self::PREFIX_LARAVEL_CONFIG . 'translators.' . $translator . '.client_secret'), 'default_language' => Config::get(self::PREFIX_LARAVEL_CONFIG . 'translators.' . $translator . '.default_language')));
        }
        $translation = $this->translator->translate($word, $to, $from);
        if (is_null($translation)) {
            $translation = $word;
        }
        return $translation;
    }

Usage Example

 /**
  *
  */
 public function testNoTranslation()
 {
     $manager = new Localization(new MessageBag());
     $this->assertEquals('AAA', $manager->translate('AAA', 'zz'));
 }