generated from vendetta-mod/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Dislate): half ready to go GTranslate API support
- Loading branch information
Showing
8 changed files
with
109 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// "inspired" by https://github.com/Vendicated/Vencord/blob/main/src/plugins/translate/utils.ts | ||
import { GTranslateResponse } from "../type" | ||
|
||
const translate = async (text: string, source_lang: string = "auto", target_lang: string, original: boolean = false) => { | ||
try { | ||
if (original) return { source_lang, text } | ||
|
||
const API_URL = "https://translate.googleapis.com/translate_a/single?" + new URLSearchParams({ | ||
client: "gtx", | ||
sl: source_lang, | ||
tl: target_lang, | ||
dt: "t", | ||
dj: "1", | ||
source: "input", | ||
q: text | ||
}); | ||
|
||
const data: GTranslateResponse = await (await fetch(API_URL)).json() | ||
|
||
console.log(data) | ||
|
||
return { source_lang, text: data.sentences[0].trans } | ||
} catch (e) { | ||
throw Error(`Failed to fetch from Google Translate: ${e}`) | ||
} | ||
} | ||
|
||
export default { translate } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import DeepL from "./DeepL" | ||
import GTranslate from "./GTranslate" | ||
|
||
export { | ||
DeepL | ||
DeepL, | ||
GTranslate | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { getAssetIDByName } from "@vendetta/ui/assets" | ||
import { React, ReactNative } from "@vendetta/metro/common" | ||
import { Forms } from "@vendetta/ui/components" | ||
import { showToast } from "@vendetta/ui/toasts" | ||
import { useProxy } from "@vendetta/storage" | ||
import { settings } from ".." | ||
|
||
const { FormRow } = Forms | ||
const { ScrollView } = ReactNative | ||
|
||
export default () => { | ||
useProxy(settings) | ||
return ( | ||
<ScrollView style={{ flex: 1 }}> | ||
<FormRow | ||
label="DeepL" | ||
trailing={() => <FormRow.Arrow />} | ||
onPress={() => { | ||
if (settings.translator == 0) return | ||
settings.translator = 0 | ||
showToast(`Saved Translator to DeepL`, getAssetIDByName("check")) | ||
}} | ||
/> | ||
<FormRow | ||
label="Google Translate" | ||
trailing={() => <FormRow.Arrow />} | ||
onPress={() => { | ||
if (settings.translator == 1) return | ||
settings.translator = 1 | ||
showToast(`Saved Translator to Google Translate`, getAssetIDByName("check")) | ||
}} | ||
/> | ||
</ScrollView>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters