const translator = await Translator.create({
sourceLanguage: "en",
targetLanguage: "ja",
});
const totalInputQuota = translator.inputQuota;
const inputUsage = await translator.measureInputUsage(myTextString);
if (inputUsage > totalInputQuota) {
throw new Error("Insufficient quota to translate.");
} else {
console.log("Quota available to translate.");
const translation = await translator.translate(myTextString);
// ...
}Translator: measureInputUsage() method / notebook
Translator: measureInputUsage() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.