files/en-us/web/api/languagedetector/create_static/index.md
{{APIRef("Translator and Language Detector APIs")}}{{SeeCompatTable}}{{securecontext_header}}
The create() static method of the {{domxref("LanguageDetector")}} interface creates a new LanguageDetector instance to detect languages.
[!NOTE] The
create()method requires transient activation, that is, it must be invoked in response to a user action such as a mouse click or button press.
LanguageDetector.create(options)
options
LanguageDetector. Possible values include:
expectedInputLanguages
["en"].monitor {{optional_inline}}
signal {{optional_inline}}
create() operation to be aborted via the associated {{domxref("AbortController")}}. The exact effect is dependant on when {{domxref("AbortController.abort()")}} is called:
abort() is called before the create() promise resolves, the create() operation is cancelled.abort() is called after the create() promise fulfills, it has the same effect as calling {{domxref("LanguageDetector.destroy()")}}: The resources assigned to the resulting LanguageDetector instance are released, and any ongoing and subsequent LanguageDetector method calls will reject with an AbortError.A {{jsxref("Promise")}} that fulfills with a LanguageDetector object instance.
InvalidStateError {{domxref("DOMException")}}
NetworkError {{domxref("DOMException")}}
NotAllowedError {{domxref("DOMException")}}
create() method wasn't called via {{glossary("transient activation")}}.NotSupportedError {{domxref("DOMException")}}
expectedInputLanguages are invalid, or not supported.expectedInputLanguages is not available.OperationError {{domxref("DOMException")}}
LanguageDetector creation failed for any other reason.LanguageDetector creationconst detector = await LanguageDetector.create({
expectedInputLanguages: ["en-US", "zh"],
});
{{Specifications}}
{{Compat}}