Translation swap added
This commit is contained in:
@@ -3,7 +3,9 @@ import { replaceBoth } from "./language";
|
||||
export const initialState = {
|
||||
source: "auto",
|
||||
target: "en",
|
||||
query: ""
|
||||
query: "",
|
||||
delayedQuery: "",
|
||||
translation: ""
|
||||
}
|
||||
|
||||
type State = typeof initialState;
|
||||
@@ -46,7 +48,10 @@ export default function reducer(state: State, action: Action) {
|
||||
source: source !== target
|
||||
? source
|
||||
: initialState.source,
|
||||
target
|
||||
target,
|
||||
query: state.translation,
|
||||
delayedQuery: state.translation,
|
||||
translation: ""
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
|
||||
@@ -6,7 +6,7 @@ export async function googleScrape(
|
||||
target: string,
|
||||
query: string
|
||||
): Promise<{
|
||||
translation?: string,
|
||||
translationRes?: string,
|
||||
statusCode?: number,
|
||||
errorMsg?: string
|
||||
}> {
|
||||
@@ -26,11 +26,11 @@ export async function googleScrape(
|
||||
};
|
||||
|
||||
const html = await res.text();
|
||||
const translation = cheerio.load(html)(".result-container").text().trim();
|
||||
const translationRes = cheerio.load(html)(".result-container").text().trim();
|
||||
|
||||
return translation
|
||||
return translationRes
|
||||
? {
|
||||
translation
|
||||
translationRes
|
||||
} : {
|
||||
errorMsg: "An error occurred while parsing the translation"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user