2017 © Pedro Peláez
 

library google-translate-api

Google translate API V2 client for PHP

image

viniciusgava/google-translate-api

Google translate API V2 client for PHP

  • Tuesday, February 20, 2018
  • by viniciusgava
  • Repository
  • 1 Watchers
  • 19 Stars
  • 3,255 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 9 Forks
  • 0 Open issues
  • 6 Versions
  • 182 % Grown

The README.md

Google Translate API PHP Client

Build Status, (*1)

This project abstract the google translate api versio 2.0 in PHP. The lib has been refactored to support unit tests, composer, and a better architecture., (*2)

Installation

Use composer to install the lib, (*3)

composer require viniciusgava/google-translate-api

Examples of Usage

Translate with source language detection

<?php
require_once 'vendor/autoload.php';

$client = new \GoogleTranslate\Client('GOOGLE ACCESS KEY HERE');

echo $client->translate('Hello world!', 'pt-br', $sourceLanguage);
// output: Olá Mundo!

echo $sourceLanguage;
// output: en

Translate without source language detection

<?php
require_once 'vendor/autoload.php';

$client = new \GoogleTranslate\Client('GOOGLE ACCESS KEY HERE');

$sourceLanguage = 'pt-br';
echo $client->translate('Onde estou?', 'en', $sourceLanguage);
// output: Where am I?

Translate bundle of texts with language detection

<?php
require_once 'vendor/autoload.php';

$client = new \GoogleTranslate\Client('GOOGLE ACCESS KEY HERE');

$texts = [
    '¿Cómo estás?',
    'あなたはどこに住んでいますか?',
    'Where are you going?',
    'Essa lib é muito legal!'
];

print_r($client->translate($texts, 'en', $sourceLanguage));
/* output:
    Array
    (
        [0] => How are you?
        [1] => Where do you live?
        [2] => Where are you going?
        [3] => This lib is really cool!
    )
*/

print_r($sourceLanguage);
/* output:
    Array
    (
        [0] => es
        [1] => ja
        [2] => en
        [3] => pt
    )
*/

Detect language of a bundle of text

<?php
require_once 'vendor/autoload.php';

$client = new \GoogleTranslate\Client('GOOGLE ACCESS KEY HERE');

$texts = [
    '¿Cómo estás?',
    'あなたはどこに住んでいますか?',
    'Where are you going?',
    'Essa lib é muito legal!'
];

print_r($client->detect($texts));
/* output:
    Array
    (
        [0] => Array
        (
            [confidence] => 0.67241430282593
                [isReliable] =>
                [language] => es
            )

        [1] => Array
    (
        [confidence] => 1
                [isReliable] =>
                [language] => ja
            )

        [2] => Array
    (
        [confidence] => 0.67237991094589
                [isReliable] =>
                [language] => en
            )

        [3] => Array
    (
        [confidence] => 0.25708484649658
                [isReliable] =>
                [language] => pt
            )

    )
*/

Detect language of a text

<?php
require_once 'vendor/autoload.php';

$client = new \GoogleTranslate\Client('GOOGLE ACCESS KEY HERE');

print_r($client->detect('Let\'s help the community!'));
/* output:
    Array
    (
        [confidence] => 0.26097252964973
        [isReliable] =>
        [language] => en
    )
*/

List supported languages with name of language translated for a specific language

<?php
require_once 'vendor/autoload.php';

$client = new \GoogleTranslate\Client('GOOGLE ACCESS KEY HERE');

print_r($client->languages('pt-br'));
/* output:
    Array
    (
        [0] => Array
            (
                [language] => af
                [name] => Africâner
            )

        [1] => Array
            (
                [language] => sq
                [name] => Albanês
            )

        [2] => Array
            (
                [language] => de
                [name] => Alemão
            )

        [3] => Array
            (
                [language] => ar
                [name] => Árabe
            )

        [4] => Array
            (
                [language] => hy
                [name] => Armênio
            )
        [5] => Array
            (
                [language] => zh
                [name] => Chinês (simplificado)
            )
        [6] => Array
            (
                [language] => fr
                [name] => Francês
            )
        .
        .
        .
    )
*/

List supported languages

<?php
require_once 'vendor/autoload.php';

$client = new \GoogleTranslate\Client('GOOGLE ACCESS KEY');

print_r($client->languages());
/* output:
    Array
    (
        [0] => Array
            (
                [language] => af
            )

        [1] => Array
            (
                [language] => am
            )

        [2] => Array
            (
                [language] => ar
            )

        [3] => Array
            (
                [language] => az
            )

        [4] => Array
            (
                [language] => be
            )

        [5] => Array
            (
                [language] => bg
            )

        [6] => Array
            (
                [language] => bn
            )
        .
        .
        .
    )
*/

Version Guidance

Version Status Repo PHP Version
2.* Maintained v2 >= 5.6 <= 7.1
3.* Latest v3 >= 7.2

The Versions

20/02 2018

dev-master

9999999-dev https://github.com/viniciusgava/google-translate-php-client

Google translate API V2 client for PHP

  Sources   Download

MIT GNU

The Requires

 

The Development Requires

by Vinicius Gava

google client translate adapter

20/02 2018

2.0.2

2.0.2.0 https://github.com/viniciusgava/google-translate-php-client

Google translate API V2 client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vinicius Gava

google client translate adapter

08/10 2017

2.0.1

2.0.1.0 https://github.com/viniciusgava/google-translate-php-client

Google translate API V2 client for PHP

  Sources   Download

GNU

The Requires

 

The Development Requires

by Vinicius Gava

google client translate adapter

08/10 2017

dev-hotfix/multiple-strings-bug-and-add-examples-at-readme.md

dev-hotfix/multiple-strings-bug-and-add-examples-at-readme.md https://github.com/viniciusgava/google-translate-php-client

Google translate API V2 client for PHP

  Sources   Download

GNU

The Requires

 

The Development Requires

by Vinicius Gava

google client translate adapter

08/10 2017

2.0

2.0.0.0 https://github.com/viniciusgava/google-translate-php-client

Google translate API V2 client for PHP

  Sources   Download

GNU

The Requires

 

The Development Requires

by Vinicius Gava

google client translate adapter

08/10 2017

dev-feature/refactory

dev-feature/refactory https://github.com/viniciusgava/google-translate-php-client

Google translate API V2 client for PHP

  Sources   Download

GNU

The Requires

 

The Development Requires

by Vinicius Gava

google client translate adapter