Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eko/googletranslatebundle
A Symfony bundle to deals with Google Translate API
https://github.com/eko/googletranslatebundle
detect-language detector language symfony symfony-bundle translation-service
Last synced: about 2 months ago
JSON representation
A Symfony bundle to deals with Google Translate API
- Host: GitHub
- URL: https://github.com/eko/googletranslatebundle
- Owner: eko
- License: mit
- Created: 2013-07-05T15:20:34.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2018-07-17T14:22:30.000Z (over 6 years ago)
- Last Synced: 2024-09-24T21:52:35.924Z (3 months ago)
- Topics: detect-language, detector, language, symfony, symfony-bundle, translation-service
- Language: PHP
- Size: 71.3 KB
- Stars: 43
- Watchers: 5
- Forks: 22
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
GoogleTranslateBundle
=====================[![SensioLabsInsight](https://insight.sensiolabs.com/projects/41d3d242-a0fe-424c-8cb1-65327f89df11/big.png)](https://insight.sensiolabs.com/projects/41d3d242-a0fe-424c-8cb1-65327f89df11)
[![Build Status](https://secure.travis-ci.org/eko/GoogleTranslateBundle.png?branch=master)](http://travis-ci.org/eko/GoogleTranslateBundle)
[![Latest Stable Version](https://poser.pugx.org/eko/GoogleTranslateBundle/version.png)](https://packagist.org/packages/eko/GoogleTranslateBundle)
[![Total Downloads](https://poser.pugx.org/eko/GoogleTranslateBundle/d/total.png)](https://packagist.org/packages/eko/GoogleTranslateBundle)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:
```json
{
"require" : {
"eko/googletranslatebundle": "dev-master"
}
}
```Add this to app/AppKernel.php
```php
```
Usages
------### Detect a string language
Retrieve the detector service and call the `detect()` method:
```php
$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:
```php
$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:
```php
$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:
```php
$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.
Your translations will be concatenated in one single Google request. To use it, simply add `true` to the last argument:
```php
$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:
```php
$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:
```php
$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.