i18n.detectLanguage()

Detects the language of the provided text using the Compact Language Detector (CLD).

Syntax

browser.i18n.detectLanguage(
  text,                  // string
  function(result) {...} // function
)

Parameters

text
string. User input string to be translated.
callback
function. The function is passed the following arguments:
result
object. LanguageDetectionResult object. If the language could not be determined this will be undefined.

Additional objects

result

LanguageDetectionResult object containing two properties:

isReliable
boolean. Whether the language was detected reliably.
languages
array of object. Array of detectedLanguage.

languages

DetectedLanguage object containing two properties:

language
i18n.LanguageCode. The detected language.
percentage
integer. The percentage of the input string that was in the detected language.

Browser compatibility

EdgeFirefoxChromeOpera
Basic support?47.0Yes33
Firefox
Basic support48.0

Examples

Acknowledgements

This API is based on Chromium's chrome.i18n API. This documentation is derived from i18n.json in the Chromium code.

Document Tags and Contributors

 Contributors to this page: wbamberg
 Last updated by: wbamberg,