2017 © Pedro PelĂĄez
 

library googletranslatebundle

A Symfony bundle to deals with Google Translate API

image

eko/googletranslatebundle

A Symfony bundle to deals with Google Translate API

  • Sunday, November 5, 2017
  • by eko
  • Repository
  • 3 Watchers
  • 36 Stars
  • 10,925 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 16 Forks
  • 2 Open issues
  • 6 Versions
  • 2 % Grown

The README.md

GoogleTranslateBundle

SensioLabsInsight, (*1)

Build Status Latest Stable Version Total Downloads, (*2)

Features

  • Detect language used for a string
  • Translate a string from a source language to a target one
  • Translate a string into a target language by using language auto-detection (consume 1 more API call)
  • Retrieve all languages available on API and obtain language names in a given language
  • Profile detector / translate / languages list API calls in the Symfony profiler!

Installation

Add the bundle to your composer.json file:, (*3)

{
    "require" :  {
        "eko/googletranslatebundle": "dev-master"
    }
}

Add this to app/AppKernel.php, (*4)

<?php
    public function registerBundles()
    {
        $bundles = array(
            ...
            new Eko\GoogleTranslateBundle\EkoGoogleTranslateBundle(),
        );

        ...

        return $bundles;
    }

Configuration

Edit app/config.yml

The following configuration lines are required:, (*5)

eko_google_translate:
    api_key: <your key api string>

Usages

Detect a string language

Retrieve the detector service and call the detect() method:, (*6)

$detector = $this->get('eko.google_translate.detector');
$value = $detector->detect('Hi, this is my string to detect!');
// This will return 'en'

Translate a string

Retrieve the translator service and call the translate() method:, (*7)

$translator = $this->get('eko.google_translate.translator');
$value = $translator->translate('Hi, this is my text to detect!', 'fr', 'en');
// This will return 'Salut, ceci est mon texte à détecter!'

Translate a string from unknown language (use detector)

Retrieve the translator service and call the translate() method without the source (third) parameter:, (*8)

$translator = $this->get('eko.google_translate.translator');
$value = $translator->translate('Hi, this is my text to detect!', 'fr');
// This will return 'Salut, ceci est mon texte à détecter!'

Translate multiple strings

Retrieve the translator service and call the translate() method with an array of your strings:, (*9)

$translator = $this->get('eko.google_translate.translator');
$value = $translator->translate(array('Hi', 'This is my second text to detect!'), 'fr', 'en');
// This will return the following array:
// array(
//     0 => 'Salut',
//     1 => 'Ceci est mon second texte à détecter !',
// )

Note that you can also use an "economic mode" to translate multiple strings in a single request which is better for your application performances., (*10)

Your translations will be concatenated in one single Google request. To use it, simply add true to the last argument:, (*11)

$translator = $this->get('eko.google_translate.translator');
$value = $translator->translate(array('Hi', 'This is my second text to detect!'), 'fr', 'en', true);
// This will return the following array:
// array(
//     0 => 'Salut',
//     1 => 'Ceci est mon second texte à détecter !',
// )

Obtain all languages codes available

Retrieve the languages service and call the get() method without any argument:, (*12)

$languages = $this->get('eko.google_translate.languages')->get();
// This will return:
// array(
//     array('language' => 'en'),
//     array('language' => 'fr'),
//     ...
// )

Obtain all languages codes available with their names translated

Retrieve the languages service and call the get() method with a target language argument:, (*13)

$languages = $this->get('eko.google_translate.languages')->get('fr');
// This will return:
// array(
//     array('language' => 'en', 'name' => 'Anglais'),
//     array('language' => 'fr', 'name' => 'Français'),
//     ...
// )

Notice: this will consume a detector API call., (*14)

The Versions

05/11 2017

dev-master

9999999-dev http://github.com/eko/GoogleTranslateBundle

A Symfony bundle to deals with Google Translate API

  Sources   Download

MIT

The Requires

 

by Vincent Composieux

api language bundle google translate detect

26/10 2016

1.1.3

1.1.3.0 http://github.com/eko/GoogleTranslateBundle

A Symfony bundle to deals with Google Translate API

  Sources   Download

MIT

The Requires

 

by Vincent Composieux

api language bundle google translate detect

08/10 2015

1.1.2

1.1.2.0 http://github.com/eko/GoogleTranslateBundle

A Symfony bundle to deals with Google Translate API

  Sources   Download

MIT

The Requires

 

by Vincent Composieux

api language bundle google translate detect

10/12 2014

1.1.0

1.1.0.0 http://github.com/eko/GoogleTranslateBundle

A Symfony bundle to deals with Google Translate API

  Sources   Download

MIT

The Requires

 

by Vincent Composieux

api language bundle google translate detect

10/12 2014

1.1.1

1.1.1.0 http://github.com/eko/GoogleTranslateBundle

A Symfony bundle to deals with Google Translate API

  Sources   Download

MIT

The Requires

 

by Vincent Composieux

api language bundle google translate detect

07/03 2014

1.0.0

1.0.0.0 http://github.com/eko/GoogleTranslateBundle

A Symfony bundle to deals with Google Translate API

  Sources   Download

MIT

The Requires

 

by Vincent Composieux

api language bundle google translate detect