There is an easy way to use the Google AJAX Language API to detect language with PHP without use any library or a giant framework?
views:
63answers:
2
+4
A:
Thats is easy,
function detect_language($string) {
$response = file_get_contents("http://www.google.com/uds/GlangDetect?v=1.0&q=" . urlencode($string));
$response = json_decode($response, true);
if ($response['responseStatus'] == 200) {
return $response['responseData']['language'];
} else {
return "tw";
}
}
carlfilips
2010-07-27 20:56:12
I like the default *tw* :)
Willi
2010-07-27 20:59:13
Thanks. I just tried, and it works.
carlfilips
2010-07-27 21:10:24
Because I don't want the overhead of a million lines of unnecessary code.
carlfilips
2010-07-27 21:01:39