Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

i18n.detectLanguage()

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

This is an asynchronous function that returns aPromise.

See theInternationalization page for a guide on using this function.

Syntax

js
let detectingLanguages = browser.i18n.detectLanguage(  text                  // string)

Parameters

text

string. User input string to be translated.

Return value

APromise that will be fulfilled with a result object. The result object has two properties:

isReliable

boolean. Whether the language was detected reliably.

languages

array of objects, each of which has two properties:

language

i18n.LanguageCode. The detected language.

percentage

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

Examples

js
function onLanguageDetected(langInfo) {  for (const lang of langInfo.languages) {    console.log(`Language is: ${lang.language}`);    console.log(`Percentage is: ${lang.percentage}`);  }}let text = "L'homme est né libre, et partout il est dans les fers.";let detecting = browser.i18n.detectLanguage(text);detecting.then(onLanguageDetected);

Browser compatibility

Note:This API is based on Chromium'schrome.i18n API. This documentation is derived fromi18n.json in the Chromium code.

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp