Language switch implemented
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import cheerio from "cheerio";
|
||||
import { mappings } from "./languages.json";
|
||||
|
||||
const isKeyOf = <T extends object>(obj: T) => (key: keyof any): key is keyof T => key in obj;
|
||||
import { replaceBoth } from "./language";
|
||||
|
||||
export async function googleScrape(
|
||||
source: string,
|
||||
@@ -11,10 +9,8 @@ export async function googleScrape(
|
||||
translation?: string,
|
||||
error?: number
|
||||
}> {
|
||||
const newTarget = isKeyOf(mappings.target)(target)
|
||||
? mappings.target[target]
|
||||
: target;
|
||||
const res = await fetch(`https://translate.google.com/m?sl=${source}&tl=${newTarget}&q=${encodeURI(query)}`);
|
||||
const parsed = replaceBoth("mapping", { source, target });
|
||||
const res = await fetch(`https://translate.google.com/m?sl=${parsed.source}&tl=${parsed.target}&q=${encodeURI(query)}`);
|
||||
|
||||
if (!res.ok)
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user