PHP Detecting Language

Detecting Language via PHP

To detect a language via php first we need to create account on detectlanguage.

after successfully registration you will get a api-key.

use following link to download library.

then we need a php language file which will contain all language name and its short code.

download the language php file here.

now the final step we need to create a function to detect the langeuage.


require_once("/path/to/lib/detectlanguage.php");
require_once "language.php";

$key = "demo";
$world = "Buenos dias seƱor";
DetectLanguage::setApiKey($key);

$languageCode = DetectLanguage::detect($word);  // detect the language
foreach($languageCode as &$code){
    $code->name = $arr[$code->language];
}

The output of above code will give following response


[
    {
        "language": "es",
        "name": "Spanish"
    }
]