-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from iroegbu/master
Updated to use Azure and included examples
- Loading branch information
Showing
5 changed files
with
159 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace DaveRandom\AsyncMicrosoftTranslate\Examples; | ||
|
||
use DaveRandom\AsyncMicrosoftTranslate\Client; | ||
use DaveRandom\AsyncMicrosoftTranslate\Credentials; | ||
use Amp\Artax\Client as HttpClient; | ||
use function Amp\resolve; | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$credentials = new Credentials(client_id, azure_subscription_key); | ||
|
||
$client = new Client(new HttpClient()); | ||
|
||
function token($client, $credentials) | ||
{ | ||
return yield $client->getAccessToken($credentials); | ||
} | ||
|
||
\Amp\run(function () use ($client, $credentials) { | ||
//text to be translated | ||
$text = 'Alles ist entweder eine Kartoffel oder nicht'; | ||
|
||
//access token - note that token has lifespan | ||
$token = yield $client->getAccessToken($credentials); | ||
|
||
//get list of supported languages | ||
$langs = yield $client->getSupportedLanguages($token); | ||
|
||
//detect text language | ||
$lang = yield $client->detectLanguage($token, $text); | ||
|
||
//get translation using token | ||
$trans = yield $client->getTranslation($token, $text, 'en', $lang); | ||
echo $trans; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters