Translator: translateStreaming() method
Khả dụng hạn chế
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 translateStreaming() của giao diện Translator tạo bản dịch dưới dạng ReadableStream.
Cú pháp
translateStreaming(input)
translateStreaming(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
translateStreaming(). Các giá trị có thể bao gồm:signal-
Một đối tượng
AbortSignal, cho phép hủy thao táctranslateStreaming()quaAbortControllerliên kết.
Giá trị trả về
Một ReadableStream 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 stream = translator.translateStreaming(myTextString);
let translation = "";
for await (const chunk of stream) {
console.log(chunk);
translation += chunk;
}
console.log("Complete translation:", translation);
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Translator and Language Detector APIs> # dom-translator-translatestreaming> |