Skip to content

Commit 2363b60

Browse files
committed
Rename canDetect() and canTranslate()
Closes #19.
1 parent f83312b commit 2363b60

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ Both APIs provide a promise-returning `capabilities()` methods which let you kno
8787

8888
Each of these capabilities objects has further methods which give the state of specific translation or language detection capabilities:
8989

90-
* `canTranslate(sourceLanguageTag, targetLanguageTag)`
91-
* `canDetect(languageTag)`
90+
* `languagePairAvailable(sourceLanguageTag, targetLanguageTag)`, for the `ai.translation.capabilities()` object
91+
* `languageAvailable(languageTag)`, for the `ai.languageDetection.capabilities()` object
9292

9393
Both of these methods return `"no"`, `"after-download"`, or `"readily"`, which have the same meanings as above, except specialized to the specific arguments in question.
9494

@@ -110,7 +110,7 @@ async function translateUnknownCustomerInput(textToTranslate, targetLanguage) {
110110
}
111111

112112
// Special-case check for Japanese since for our site it's particularly important.
113-
if (languageDetectorCapabilities.canDetect("ja") === "no") {
113+
if (languageDetectorCapabilities.languageAvailable("ja") === "no") {
114114
console.warn("Japanese Language detection is not available. Falling back to cloud API.");
115115
sourceLanguage = await useSomeCloudAPIToDetectLanguage(textToTranslate);
116116
} else {
@@ -127,15 +127,15 @@ async function translateUnknownCustomerInput(textToTranslate, targetLanguage) {
127127
}
128128

129129
// Now we've figured out the source language. Let's translate it!
130-
// Note how we can just check `translatorCapabilities.canTranslate()` instead of also checking
130+
// Note how we can just check `translatorCapabilities.languagePairAvailable()` instead of also checking
131131
// `translatorCapabilities.available`.
132-
const canTranslate = translatorCapabilities.canTranslate(sourceLanguage, targetLanguage);
133-
if (canTranslate === "no") {
132+
const availability = translatorCapabilities.languagePairAvailable(sourceLanguage, targetLanguage);
133+
if (availability === "no") {
134134
console.warn("Translation is not available. Falling back to cloud API.");
135135
return await useSomeCloudAPIToTranslate(textToTranslate, { sourceLanguage, targetLanguage });
136136
}
137137

138-
if (canTranslate === "after-download") {
138+
if (availability === "after-download") {
139139
console.log("Translation is available, but something will have to be downloaded. Hold tight!");
140140
}
141141

@@ -250,7 +250,7 @@ interface AITranslator {
250250
interface AITranslatorCapabilities {
251251
readonly attribute AICapabilityAvailability available;
252252
253-
AICapabilityAvailability canTranslate(DOMString sourceLanguage, DOMString targetLanguage);
253+
AICapabilityAvailability languagePairAvailable(DOMString sourceLanguage, DOMString targetLanguage);
254254
};
255255
256256
dictionary AITranslatorCreateOptions {
@@ -287,7 +287,7 @@ interface AILanguageDetector {
287287
interface AILanguageDetectorCapabilities {
288288
readonly attribute AICapabilityAvailability available;
289289
290-
AICapabilityAvailability canDetect(DOMString languageTag);
290+
AICapabilityAvailability languageAvailable(DOMString languageTag);
291291
};
292292
293293
dictionary AILanguageDetectorCreateOptions {
@@ -339,7 +339,7 @@ Some sort of mitigation may be necessary here. We believe this is adjacent to ot
339339
* Partitioning download status by top-level site, introducing a fake download (which takes time but does not actually download anything) for the second-onward site to download a language pack.
340340
* Only exposing a fixed set of languages to this API, e.g. based on the user's locale or the document's main language.
341341

342-
As a first step, we require that detecting the availability of translation for a given language pair be done via individual calls to `canTranslate()` and `canDetect()`. This allows browsers to implement possible mitigation techniques, such as detecting excessive calls to these methods and starting to return `"no"`.
342+
As a first step, we require that detecting the availability of translation/detection be done via individual calls to `translationCapabilities.languagePairAvailable()` and `detectionCapabilities.languageAvailable()`. This allows browsers to implement possible mitigation techniques, such as detecting excessive calls to these methods and starting to return `"no"`.
343343

344344
Another way in which this API might enhance the web's fingerprinting surface is if translation and language detection models are updated separately from browser versions. In that case, differing results from different versions of the model provide additional fingerprinting bits beyond those already provided by the browser's major version number. Mandating that older browser versions not receive updates or be able to download models from too far into the future might be a possible remediation for this.
345345

0 commit comments

Comments
 (0)