在javascript中通过字符串检测语言

时间:2014-11-11 13:10:33

标签: javascript

我正在寻找一些工具来检测javascript字符串的语言。我需要检测发送" Locale"的语言。参数到服务器。是否有一些图书馆在客户端做这件事?

1 个答案:

答案 0 :(得分:3)

Google有一个可用于此的API:

https://developers.google.com/apis-explorer/?csw=1#search/language.detections.list/m/translate/v2/language.detections.list

例如,您要求:

  

GET https://www.googleapis.com/language/translate/v2/detect?q=I'm +寻找+ for + some + tool + to + detect + + language + of + + string + for + javascript。& key = {YOUR_API_KEY}

您收到:

200 OK

{
 "data": {
  "detections": [
   [
    {
     "language": "en",
     "isReliable": false,
     "confidence": 0.80974126
    }
   ]
  ]
 }
}