ddctd143/google-translate

Free Laravel package for Paid Google Translate REST API
1,558
Install
composer require ddctd143/google-translate
Latest Version:v1.0.1
PHP:>=5.5.9
License:MIT
Last Updated:Dec 14, 2019
Links: GitHub  ·  Packagist
Maintainer: khaledkhamis

Laravel package for Google Translate REST API

Downloads Total

Package allows to work with Google Translate API

Installation

Package can be installed using composer by adding to "require" object

"require": {
    "ddctd143/google-translate": "dev-master"
}

or from console:

composer require ddctd143/google-translate dev-master

Configuration

You should publish config file to be able to add your Google API key. To publish config you should do:

php artisan vendor:publish \
--provider="Dedicated\GoogleTranslate\GoogleTranslateProvider" --tag=config

After config is published, you will have it in config\google-translate.php of your Laravel project directory

You should change only one line:

    ...
    
    /**
     * Google key for authentication
     */
    'api_key' => 'YOUR-GOOGLE-API-KEY-GOES-HERE',
    
    ...

Usage

To translate text with given source language and target language:

$translator = new Dedicated\GoogleTranslate\Translator;


$result = $translator->setSourceLang('en')
                     ->setTargetLang('ru')
                     ->translate('Hello World');
                           
dd($result); // "Привет мир"                           

By default language detection is turned on, so you can translate text without specifying source language.

This will make 2 requests to google API:

  • First request will go to /detect URL and get source language name
  • Second request will make actual translate request and give out result.
$translator = new Dedicated\GoogleTranslate\Translator;


$result = $translator->setTargetLang('ru')
                     ->translate('Hello World');
                           
dd($result); // "Привет мир"                           

You can also use function to only detect text's source language:


$result = $translator->detect('Hello World');

dd($result); // "en"

License

This repository code is open-sourced software licensed under the MIT license

Related Packages

pixxet/google-translate

Free Laravel package for Paid Google Translate REST API

493 2
dusterio/laravel-google-guard

Auth guard for Laravel that completely relies on Google Login and doesn't persis...

350 6
edisonthk/google-oauth-laravel4

Optimize artdarek/oauth-4-laravel with Google OAuth 2.0 for laravel 4

5,131 1
ozankurt/google-translate

Laravel 5 Google Translate

415 0

Version History

Version Released PHP License
v1.0.1 >=5.5.9 MIT
v1.0 >=5.5.9 MIT