Package Data | |
---|---|
Maintainer Username: | pixxet |
Maintainer Contact: | omar@pixxet.de (Omar Sharkeyeh) |
Package Create Date: | 2017-03-20 |
Package Last Update: | 2017-03-20 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-16 15:00:53 |
Package Statistics | |
---|---|
Total Downloads: | 492 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 3 |
Total Watchers: | 1 |
Total Forks: | 2 |
Total Open Issues: | 0 |
Package allows to work with Google Translate API
Package can be installed using composer by adding to "require" object
"require": {
"pixxet/google-translate": "dev-master"
}
or from console:
composer require pixxet/google-translate dev-master
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"
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',
...
To translate text with given source language and target language:
$translator = new Dedicated\GoogleTranslate\Translator;
$result = $translator->setSourceLang('en')
->setTargetLang('ar')
->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:
$translator = new Dedicated\GoogleTranslate\Translator;
$result = $translator->setTargetLang('ar')
->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"
This repository code is open-sourced software licensed under the MIT license