Identify language - findbrok/laravel-watson-translate GitHub Wiki
Identify the language in which a text is written in. Output provides list of languages with confidence level. The Higher the confidence level the more likely the language is to be the one in which the text is written in.
<?php
namespace App\Http\Controllers;
use FindBrok\WatsonTranslate\Contracts\TranslatorInterface as WatsonTranslator;
class IndexController extends Controller
{
/**
* Identify a language
*
* @param WatsonTranslator $translator
*/
public function identifyLanguage(WatsonTranslator $translator)
{
//Text to identify language
$text = 'English reading practice is very important if you want to improve your English reading skills.';
//Identify the language
$results = $translator->identifyLanguage($text);
/*
Collection {#159 ▼
#items: array:1 [▼
"languages" => array:62 [▼
0 => array:2 [▼
"language" => "en"
"confidence" => 0.999761
]
1 => array:2 [▼
"language" => "is"
"confidence" => 7.70521E-5
]
2 => array:2 [▼
"language" => "af"
"confidence" => 7.43791E-5
]
....
*/
}
}