Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

i18n.detectLanguage()

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

Syntax

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

This API is also available as browser.i18n.detectLanguage() in a version that returns a promise.

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

Chrome Edge Firefox Firefox for Android Opera
Basic support Yes No 47.0 48.0 33

Examples

function onLanguageDetected(langInfo) {
  for (lang of  langInfo.languages) {
    console.log("Language is: " + lang.language);
    console.log("Percentage is: " + lang.percentage);
  }
}

var text = "L'homme est né libre, et partout il est dans les fers."

chrome.browserAction.onClicked.addListener(function() {
  chrome.i18n.detectLanguage(text, onLanguageDetected);
});

Acknowledgements

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

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

Document Tags and Contributors

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