mouuff / mtranslate

A simple api for google translate
MIT License
286 stars 83 forks source link

Just an inquiry #22

Closed ArtanisTheOne closed 3 years ago

ArtanisTheOne commented 3 years ago

Hey, Cool library, very useful. Just wanted to ask, since html parsing is used here.... Would HTML Parsing in this module be faster than using another module which uses rpc's to make requests from the server? Both are blazing fast but I just want to know if you guys might have some more insight.

Also, is it possible to set it to only use one gender-translation (if you try and translate "they" to french it will result in both gender translations since translate.google.com displays both in different fields the translation returns "ils ou elles" which means "they(m) or they(f)) so as to prevent the merging of two different gender translations into the returned translation.

ArtanisTheOne commented 3 years ago

@mouuff Perhaps you would know an answer to my questions?

mouuff commented 3 years ago

Hello, I believe RPC is faster than HTTP. Especially in our case because we load the entire web page and parse it. (Many useless information is loaded, but don't worry there is a good reason of why we do that) For most usages the difference doesn't really matter. If speed really matters in your case, then don't use this library. I would be surprised that it would be faster than the RPC based one. In the end it all really depends on the server speed, maybe the speed is different for the RPC API and the web client. So maybe we could have some surprises by doing a benchmark.... As for gender specific translations, I have not found anything. Do you know if the RPC API supports that and how? I have seen that you are working on a discord translator bot, can you tell me more about the project? If you have one server handling all the requests and indent to make the translations on the server side, then I advise you to use the official Google Translate API.

Thank you for your interest in this project!

ArtanisTheOne commented 3 years ago

I work an on open-source discord translator bot. Because it isnt one bot it allows us to be able to use cool and creative methods like this to translate. Each of our users makes their own bot etc; Currently we're making one in python and

ArtanisTheOne commented 3 years ago

Anyway, I tested the speed of the RPC and it's actually pretty much the same.... Maybe a 0.1 to 0.04 sec difference but fast 😁 I was honestly just curious

Regarding gender specific translations, with the RPC API, because it uses translate.google.com web requests using rpc's gender specific translations return a list of the 2 different ways it could be translated(as it returns in json). (Masculine translation or feminine translation). However, when I tested ("they" from english to french) it returned both together (ils ou elles) because translate.google.com adds both to the webpage, I was wondering if there was a way to only parse masculine or feminine translations instead of them both being parsed in?

Thanks! Artanis

ArtanisTheOne commented 3 years ago

Screenshot_20210310-082104_Guilded Screenshot_20210310-081955_Chrome

ArtanisTheOne commented 3 years ago

Oh also forgot to mention, each user also makes their own Heroku application to host their bot, so their isnt one server making requests and thus there isnt any overloading.

ArtanisTheOne commented 3 years ago

Is there perhaps a specific marker (ID) which you could use to identify the two to prevent the adding together of the two translations in the parsing? @mouuff

ArtanisTheOne commented 3 years ago

I'd also like to ask if you would think it possible to avoid translating a word in a string you provide to the translator? For example:

import mtranslate
from mtranslate import translate
x = "This is a <string> and <so>"
print(translate(x, "ru", "en"))

>>> это string и so

I was thinking to make translate the string fully, remove the <> and at the same time make another translate request which translates the singular words/phrases and then just replace the translated words to the words to stay the same.

mouuff commented 3 years ago

Hello, For now there is no native way to prevent the translation of a specific word using mtranslate, but I can think of an easy workaround:

>>> rep = mtranslate.translate("This is a {} and {}", "ru")
>>> rep
'Это {} и {}'
>>> rep.format("string", "so")
'Это string и so'

But I m not sure that the {} will be treated correctly in all cases, but you get the idea.

For the "they" translating to "elles ou ils" problem. I don't have a solution atm, you might have more luck with the official API.

ArtanisTheOne commented 3 years ago

👍 Thanks for the help