Translator: translate() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Phương thức translate() của giao diện Translator trả về bản dịch của một chuỗi đầu vào.
Cú pháp
translate(input)
translate(input, options)
Tham số
input-
Một chuỗi đại diện cho văn bản cần dịch.
optionsOptional-
Một đối tượng chỉ định các tùy chọn cấu hình cho thao tác
translate(). Các giá trị có thể bao gồm:signal-
Một đối tượng
AbortSignal, cho phép hủy thao táctranslate()quaAbortControllerliên kết.
Giá trị trả về
Một Promise thực hiện với một chuỗi chứa bản dịch đã tạo.
Ngoại lệ
AbortErrorDOMException-
Được ném ra nếu
Translatorđã bị phá hủy trước đó (đã cóTranslator.destroy()được gọi trên nó, hoặc bị hủy quasignalhủy bỏ sau khi tạo). InvalidStateErrorDOMException-
Được ném ra nếu
Documenthiện tại không hoạt động. QuotaExceededError-
Được ném ra nếu thao tác dịch vượt quá
inputQuotacó sẵn.
Ví dụ
>Sử dụng cơ bản translate()
const translator = await Translator.create({
sourceLanguage: "en",
targetLanguage: "ja",
});
const translation = await translator.translate(myTextString);
console.log(translation);
Thông số kỹ thuật
| Specification |
|---|
| Translator and Language Detector APIs> # dom-translator-translate> |