-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathd.ts
More file actions
40 lines (39 loc) · 1.08 KB
/
d.ts
File metadata and controls
40 lines (39 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import D from "./d/mod.ts";
import { delay } from "./deps.ts";
import { toZhHant } from "./to-zh-hant.ts";
import { Language } from "./d/interface.ts";
export default class Translation {
constructor() {
}
async translate(
sentence: string,
sourceLanguage: string,
targetLanguages: string[],
): Promise<Record<string, string>> {
const d = new D();
// console.log("sourceLanguage", sourceLanguage);
// console.log("targetLanguages", targetLanguages);
const results: Record<string, string> = {};
for (
const targetLanguage of targetLanguages.filter((lang) =>
lang !== "zh-Hant"
)
) {
await delay(100);
const result = await d.translateList({
url: "https://google.com",
text: [
sentence,
],
from: sourceLanguage as Language,
to: targetLanguage as Language,
});
results[targetLanguage] = result.text[0];
}
if (results["zh-Hans"]) {
results["zh-Hant"] = toZhHant(results["zh-Hans"]);
}
// console.log("results", results);
return results;
}
}