This repository has been archived by the owner on May 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
List identifiable languages
Percy Mamedy edited this page Feb 5, 2016
·
2 revisions
Obtain a list of Languages that Watson is able to identify
<?php
namespace App\Http\Controllers;
...
use FindBrok\WatsonTranslate\Contracts\TranslatorInterface as WatsonTranslator;
class IndexController extends Controller
{
/**
* List identifiable languages
*
* @param WatsonTranslator $translator
*/
public function listIdentifiable(WatsonTranslator $translator)
{
//Get list of identifieable languages
$results = $translator->listLanguages()->collectResults();
/*outputs
Collection {#157 ▼
#items: array:1 [▼
"languages" => array:62 [▼
0 => array:2 [▼
"language" => "af"
"name" => "Afrikaans"
]
1 => array:2 [▼
"language" => "ar"
"name" => "Arabic"
]
...
*/
}
}
You can get only languages names
//Get only languages names as array
$results = $translator->listLanguages()->languagesNames();
//Get only languages names as collection
$results = $translator->listLanguages()->languagesNames(true);
You also can get only the languages codes
//Get only languages codes as array
$results = $translator->listLanguages()->languagesCodes();
//Get only languages codes as collection
$results = $translator->listLanguages()->languagesCodes(true);