-
Notifications
You must be signed in to change notification settings - Fork 721
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
German Umlauts(ä, ö, ü) seem to throw ValueError exceptions #20
Comments
I added some debug lines to utils.py
The output seems to indicate the following: for text with umlaut, r.text from requests is not valid (not jason data): <title>Error 403 (Forbidden)!!1</title> I do hope you'll be able to fix it. $ python trans_clipboard.py 403. That’s an error. Your client does not have permission to get URL Traceback (most recent call last): $ python trans_clipboard.py |
This is because of the invalid token. It will take some time to fix this issue. Please wait a moment. |
remove_accents from EDIT in the thrid answer in http://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string Seems to do the trick in the meantime... I was doing replace(umlauts, ae|oe|ue) for German, but remove_accents is much cleaner... and works for French as well...
|
remove_accents cant handle "Weiß". |
I'm trying to fix this issue as soon as possible but it may take some time to fix this issue as this is related to the token generator. |
from googletrans import Translator
translator = Translator()
dest = 'zh-CN'
text='Mädchen'
translator.translate(text, src='de', dest=dest).text
text = 'schön'
translator.translate(text, src='de', dest=dest).text
text = 'Prüfung'
translator.translate(text, src='de', dest=dest).text
----> 2 translator.translate(text, src='de', dest=dest).text
d:\python34\lib\site-packages\googletrans\client.py in translate(self, text, dest, src, delay)
147
148 origin = text
--> 149 data = self._translate(text, dest, src)
150
151 # this code will be updated when the format is changed.
d:\python34\lib\site-packages\googletrans\client.py in _translate(self, text, dest, src)
89 LOGGER.debug(" from_cache: %s", self.from_cache)
90
---> 91 data = utils.format_json(r.text)
92 return data
93
d:\python34\lib\site-packages\googletrans\utils.py in format_json(original)
49 text = text[:p] + states[j][1] + text[nxt:]
50
---> 51 converted = json.loads(text)
52 return converted
53
d:\python34\lib\json_init_.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
316 parse_int is None and parse_float is None and
317 parse_constant is None and object_pairs_hook is None and not kw):
--> 318 return _default_decoder.decode(s)
319 if cls is None:
320 cls = JSONDecoder
d:\python34\lib\json\decoder.py in decode(self, s, _w)
341
342 """
--> 343 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
344 end = _w(s, end).end()
345 if end != len(s):
d:\python34\lib\json\decoder.py in raw_decode(self, s, idx)
359 obj, end = self.scan_once(s, idx)
360 except StopIteration as err:
--> 361 raise ValueError(errmsg("Expecting value", s, err.value)) from None
362 return obj, end
ValueError: Expecting value: line 1 column 1 (char 0)
Python 3.4, 32 bit Windows 7, no umlaut german OK.
text='Maedchen'
translator.translate(text, src='de', dest=dest).text
-- End pasted text --
googletrans.client - client.py[line:89] 2017-04-10 19:06:38,270 : DEBUG : from_cache: False
Out[220]: '女孩'
The text was updated successfully, but these errors were encountered: