2017 © Pedro PelĂĄez
 

library translator

Translator to strings using APIs or other things

image

gabrieljmj/translator

Translator to strings using APIs or other things

  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Translator

![Gitter](https://badges.gitter.im/Join Chat.svg) Total Downloads Latest Unstable Version License Scrutinizer Code Quality, (*1)

Translator to texts using Web Services or other things that can do this action., (*2)

Install

Composer

{
  "require": {
    "gabrieljmj/translator": "dev-master"
  }
}

Needs

Support

Google Translate - Not tested

To use the Google Translate, it is necessary an API Key. To create one, follow this steps: * Go to the Google Developers Console. * Select a project, or create a new one. * In the sidebar on the left, select APIs & auth. In the list of APIs, make sure the status is ON for the Google Translate API. * In the sidebar on the left, select Credentials., (*3)

How to instance: new \Translator\Service\GoogleTranslate(\Translator\Http\RequestInterface $request, string $apiKey), (*4)

Yandex Translate - Tested

To use, also is necessary an API Key. * Go to API key request form. * After create, go to My keys., (*5)

How to instance: new \Translator\Service\YandexTranslate(\Translator\Http\RequestInterface $request, string $apiKey), (*6)

How to use

Examples with Google Translate, (*7)

Getting accepted languages of a web service

Use the method getAcceptedLangs(). It will return an array with all languages accepted by web service that you are using., (*8)

Translating

use Translator\Service\GoogleTranslate;
use Translator\Http\CurlRequest;

$text = 'Hi! How are you?';
$apiKey = 'YOUR_API_KEY';

$translator = new GoogleTranslate(new CurlRequest(), $apiKey);
$translatedText = $translator->translate('en', 'pt', $text);
$translatedText->getNewText();//'Oi! Como vai vocĂȘ?'
$translatedText->getOriginalText();//'Hi! How are you?'
$translatedText->getOriginalLang();//en
$translatedText->getNewLang();//pt

With an array:, (*9)

$texts = array('Hi!', 'How are you?');

$translatedText = $translator->translate('en', 'pt', $texts);
$translatedText->getNewText();//Array('Oi!', 'Como vai vocĂȘ?')
$translatedText->getOriginalText();//Array('Hi!', 'How are you?')
$translatedText->getOriginalLang();//en
$translatedText->getNewLang();//pt

Detecting language

$detectedText = $translator->detect($text);
$detectedText->getLang();//en
$detectedText->getText()//Hi! How are you?
$detectedText->getDetectedTextWithLang();//Array('Hi! How are you?' => 'en')

With an array:, (*10)

$texts = array('Hi!', 'OlĂĄ!');

$detectedText = $translator->detect($texts);
$detectedText->getLang();//Array('en', 'pt')
$detectedText->getText();//Array('Hi!', 'OlĂĄ!')
$detectedText->getDetectedTextWithLang();//Array('Hi!' => 'en', 'OlĂĄ!' => 'pt')

The Versions

28/12 2014

dev-master

9999999-dev

Translator to strings using APIs or other things

  Sources   Download

MIT

The Development Requires

library translator