Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrections in translation service #363

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions extensions/src/textClassification/services/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const getTranslationURL = (params: SearchParams) => {

export const getTranslationToEnglish = async (words: string) => {
if (cachedTranslations.has(words)) return cachedTranslations.get(words);
const endpoint = getTranslationURL({ language: "en", text: encodeURIComponent(words) });
const endpoint = getTranslationURL({ language: "en", text: words }); // words already encoded
try {
const json: { result: string } = await (await fetchWithTimeout(endpoint, { timeoutMs: 30 })).json();
const json: { result: string } = await (await fetchWithTimeout(endpoint, { timeoutMs: 30000 })).json(); // 30ms was too short
const translated = json.result;
cachedTranslations.set(words, translated);
return translated;
Expand All @@ -30,4 +30,4 @@ export const getTranslationToEnglish = async (words: string) => {
console.warn(`error fetching translate result! ${error}`);
return '';
}
}
}