Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.0.0rc1 Translation._translate() Bug #279

Closed
2 of 6 tasks
terryyz opened this issue Mar 10, 2021 · 3 comments
Closed
2 of 6 tasks

4.0.0rc1 Translation._translate() Bug #279

terryyz opened this issue Mar 10, 2021 · 3 comments

Comments

@terryyz
Copy link
Collaborator

terryyz commented Mar 10, 2021

Googletrans version:

  • 4.0.0rc1
  • 3.1.0a0
  • 3.0.0
  • 2.x

I'm submitting a ...

  • bug report
  • feature request

Current behavior:

Line 120 in client.py, the return value r from self.client.post() is incompleted/incorrect.
Got

)]}'

574
[["wrb.fr","MkEWBc","[[null,null,null,[[[0,[[[null,8]\n]\n,[true]\n]\n]\n]\n,8]\n]\n,[[[null,null,null,null,null,[[\"Stripper.\",[\"Stripper.\",\"penari telanjang\"]\n]\n]\n]\n]\n,\"ms\",1,\"en\",[\"Stripper\",\"en\",\"ms\",true]\n]\n,null,[\"stripper\",[[[\"noun\",[[\"a device used for stripping something.\",\"plier-style wire strippers\",true]\n,[\"a striptease performer.\",\"the stripper gyrated on the tiny stage\",true]\n]\n]\n]\n,2]\n,null,null,null,null,null,null,\"en\",1]\n]\n",null,null,null,"generic"]
,["di",39]
,["af.httprm",38,"-5891969303140648931",17]
]
26
[["e",4,null,null,611]
]

for r.text

Expected behavior:

According to 3.1.0a0 version, r.text should be similar to (at least contains "Pelacur" )

[[["Pelacur","Stripper",null,null,3,null,null,[[]
]
,[[["245167c4f444a3a0147ffc37bbb18027","GreySheepA_2020q2.md"]
]
]
]
]
,null,"en",null,null,[["Stripper",null,[["Pelacur",0,true,false]
,["penari telanjang",0,true,false]
]
,[[0,8]
]
,"Stripper",0,0]
]
,0.9680427,[]
,[["en"]
,null,[0.9680427]
,["en"]
]
,null,null,null,[["kata nama",[["a device used for stripping something.","m_en_gbus1003470.006","plier-style wire strippers"]
,["a striptease performer.","m_en_gbus1003470.012","the stripper gyrated on the tiny stage"]
]
,"stripper"]
]
]

Steps to reproduce:

from googletrans import Translator
translator = Translator()
translator.translate("Stripper",src="en",dest="ms").text

Related code:

class Translator:
...
def _translate(self, text: str, dest: str, src: str):
        url = urls.TRANSLATE_RPC.format(host=self._pick_service_url())
        data = {
            'f.req': self._build_rpc_request(text, dest, src),
        }
        params = {
            'rpcids': RPC_ID,
            'bl': 'boq_translate-webserver_20201207.13_p0',
            'soc-app': 1,
            'soc-platform': 1,
            'soc-device': 1,
            'rt': 'c',
        }
        r = self.client.post(url, params=params, data=data)

        if r.status_code != 200 and self.raise_exception:
            raise Exception('Unexpected status code "{}" from {}'.format(
                r.status_code, self.service_urls))

        return r.text, r

Other information:

Related Issues: #267 #278
The way to handle url/data/params variables inside _translate function could be incorrect. A further investigation is needed.

@terryyz
Copy link
Collaborator Author

terryyz commented Mar 10, 2021

cc @ssut

@stale
Copy link

stale bot commented May 9, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 9, 2021
@stale stale bot closed this as completed May 17, 2021
@marcoh3mmm
Copy link

Hello, I've discovered a method that isn't about the bug-like itself, but rather the context of the term.

for codeLanguage, languageName in lang.items():
if languageBase.lower() == languageName:
try:
constellationTranslated =translator.translate(constellation , dest =codeLanguage)
dateTranslated = translator.translate(newConstellationNorth.get(constellation), dest = codeLanguage)
except TimeoutError:
time.sleep(10)
constellationTranslated =translator.translate(constellation , dest =codeLanguage)
dateTranslated = translator.translate(newConstellationNorth.get(constellation), dest = codeLanguage)

            except TypeError:
                time.sleep(10)
                constellationTranslated =translator.translate(constellation +" constellation", dest =codeLanguage)
                dateTranslated = translator.translate(newConstellationNorth.get(constellation), dest = codeLanguage)

As you can see, attempting to obtain the word does not work in all languages, but attempting to obtain the term using other words that provide context may be successful.

In Portuguese, for example, "Gemini" contains both male and female translations, but by adding the term "constellation", such as "Gemini constellation," the translation is now accurate.

I hope you find this useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants