parent
60859940c6
commit
4d4f3ec41b
@ -6,6 +6,7 @@ You can translate text using this module.
|
|||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
|
import sys
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from future.moves.urllib.parse import quote
|
from future.moves.urllib.parse import quote
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/537.36 (
|
|||||||
|
|
||||||
EXCLUDES = ['en', 'ca', 'fr']
|
EXCLUDES = ['en', 'ca', 'fr']
|
||||||
RE_SRC = re.compile(',\[\["([\w]{2})"\]')
|
RE_SRC = re.compile(',\[\["([\w]{2})"\]')
|
||||||
|
PY3 = sys.version_info > (3, 1)
|
||||||
|
|
||||||
__agent = None
|
__agent = None
|
||||||
__headers = {
|
__headers = {
|
||||||
@ -112,9 +114,17 @@ Advanced usage:
|
|||||||
try:
|
try:
|
||||||
pron = data[0][1][-1]
|
pron = data[0][1][-1]
|
||||||
except: pass
|
except: pass
|
||||||
|
if not PY3 and isinstance(pron, unicode) and isinstance(origin, str):
|
||||||
|
origin = origin.decode('utf-8')
|
||||||
if dest in EXCLUDES and pron == origin:
|
if dest in EXCLUDES and pron == origin:
|
||||||
pron = translated
|
pron = translated
|
||||||
|
|
||||||
|
# for python 2.x compatbillity
|
||||||
|
if not PY3:
|
||||||
|
if isinstance(src, str): src = src.decode('utf-8')
|
||||||
|
if isinstance(dest, str): dest = dest.decode('utf-8')
|
||||||
|
if isinstance(translated, str): translated = translated.decode('utf-8')
|
||||||
|
|
||||||
# put final values into new Translated object
|
# put final values into new Translated object
|
||||||
result = Translated(src=src, dest=dest, origin=origin,
|
result = Translated(src=src, dest=dest, origin=origin,
|
||||||
text=translated, pronunciation=pron)
|
text=translated, pronunciation=pron)
|
||||||
|
Loading…
Reference in New Issue
Block a user