Skip to content

Commit

Permalink
new google translate engine
Browse files Browse the repository at this point in the history
  • Loading branch information
WillTDA committed Nov 24, 2023
1 parent 203b148 commit ede2cad
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 185 deletions.
9 changes: 9 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs"
},
"exclude": [
"node_modules"
]
}
192 changes: 12 additions & 180 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A Discord.js v14 module that allows you to create an Akinator command for your discord bot in a matter of seconds.",
"main": "src/index.js",
"funding": {
"type": "buymecoffee",
"type": "buymeacoffee",
"url": "https://www.buymeacoffee.com/willtda"
},
"scripts": {
Expand All @@ -22,7 +22,7 @@
"author": "WillTDA",
"license": "Apache-2.0",
"dependencies": {
"@vitalets/google-translate-api": "^9.2.0",
"@kreisler/js-google-translate-free": "^2.1.0",
"aki-api": "^6.0.9"
}
}
5 changes: 2 additions & 3 deletions src/translate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require("fs");
const path = require("path");
const crypto = require("crypto");
const translator = require("@vitalets/google-translate-api");
const translator = require("@kreisler/js-google-translate-free");

/**
*
Expand Down Expand Up @@ -30,9 +30,8 @@ module.exports = async function translate(string, language, cachingOptions) {
if (language === "zh") language = "zh-CN";
if (language === "zhcn" || language === "zh-cn") language = "zh-CN";
if (language === "zhtw" || language === "zh-tw") language = "zh-TW";
let translation = await translator.translate(string, { to: language }).catch(e => console.log(e)); //translate the string using google translate
let translation = await translator.translate("en", language, string).catch(e => console.log(e)); //translate the string using google translate
if (!translation) return console.log("Translator: Error occured while translating.");
translation = translation.text;

//save the translation to the cache if caching is enabled
if (cachingOptions.enabled === true) {
Expand Down

0 comments on commit ede2cad

Please sign in to comment.