Skip to content

Commit

Permalink
feat(client): set the default service url of Client to translate.goog…
Browse files Browse the repository at this point in the history
…leapis.com (possible fix for ssut#234)
  • Loading branch information
ssut authored and c-goosen committed Sep 19, 2024
1 parent f4aa28c commit 4e93fc8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
5 changes: 3 additions & 2 deletions googletrans/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from googletrans import urls, utils
from googletrans.gtoken import TokenAcquirer
from googletrans.constants import (
DEFAULT_CLIENT_SERVICE_URLS,
DEFAULT_USER_AGENT, LANGCODES, LANGUAGES, SPECIAL_CASES,
DEFAULT_RAISE_EXCEPTION, DUMMY_DATA
)
Expand Down Expand Up @@ -51,7 +52,7 @@ class Translator:
:type raise_exception: boolean
"""

def __init__(self, service_urls=None, user_agent=DEFAULT_USER_AGENT,
def __init__(self, service_urls=DEFAULT_CLIENT_SERVICE_URLS, user_agent=DEFAULT_USER_AGENT,
raise_exception=DEFAULT_RAISE_EXCEPTION,
proxies: typing.Dict[str, httpcore.SyncHTTPTransport] = None,
timeout: Timeout = None,
Expand Down Expand Up @@ -87,7 +88,7 @@ def __init__(self, service_urls=None, user_agent=DEFAULT_USER_AGENT,
self.client_type = 'webapp'
self.token_acquirer = TokenAcquirer(
client=self.client, host=self.service_urls[0])

self.raise_exception = raise_exception

def _pick_service_url(self):
Expand Down
38 changes: 21 additions & 17 deletions googletrans/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
DEFAULT_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'

DEFAULT_CLIENT_SERVICE_URLS = (
'translate.googleapis.com',
)

DEFAULT_SERVICE_URLS = ('translate.google.ac', 'translate.google.ad', 'translate.google.ae',
'translate.google.al', 'translate.google.am', 'translate.google.as',
'translate.google.at', 'translate.google.az', 'translate.google.ba',
Expand All @@ -21,21 +25,21 @@
'translate.google.com.ai', 'translate.google.com.ar', 'translate.google.com.au',
'translate.google.com.bd', 'translate.google.com.bh', 'translate.google.com.bn',
'translate.google.com.bo', 'translate.google.com.br', 'translate.google.com.bz',
'translate.google.com.co', 'translate.google.com.cu', 'translate.google.com.cy',
'translate.google.com.do', 'translate.google.com.ec', 'translate.google.com.eg',
'translate.google.com.et', 'translate.google.com.fj', 'translate.google.com.gh',
'translate.google.com.gi', 'translate.google.com.gt', 'translate.google.com.hk',
'translate.google.com.jm', 'translate.google.com.kh', 'translate.google.com.kw',
'translate.google.com.lb', 'translate.google.com.ly', 'translate.google.com.mm',
'translate.google.com.mt', 'translate.google.com.mx', 'translate.google.com.my',
'translate.google.com.na', 'translate.google.com.ng', 'translate.google.com.ni',
'translate.google.com.np', 'translate.google.com.om', 'translate.google.com.pa',
'translate.google.com.pe', 'translate.google.com.pg', 'translate.google.com.ph',
'translate.google.com.pk', 'translate.google.com.pr', 'translate.google.com.py',
'translate.google.com.qa', 'translate.google.com.sa', 'translate.google.com.sb',
'translate.google.com.sg', 'translate.google.com.sl', 'translate.google.com.sv',
'translate.google.com.tj', 'translate.google.com.tr', 'translate.google.com.tw',
'translate.google.com.ua', 'translate.google.com.uy', 'translate.google.com.vc',
'translate.google.com.co', 'translate.google.com.cu', 'translate.google.com.cy',
'translate.google.com.do', 'translate.google.com.ec', 'translate.google.com.eg',
'translate.google.com.et', 'translate.google.com.fj', 'translate.google.com.gh',
'translate.google.com.gi', 'translate.google.com.gt', 'translate.google.com.hk',
'translate.google.com.jm', 'translate.google.com.kh', 'translate.google.com.kw',
'translate.google.com.lb', 'translate.google.com.ly', 'translate.google.com.mm',
'translate.google.com.mt', 'translate.google.com.mx', 'translate.google.com.my',
'translate.google.com.na', 'translate.google.com.ng', 'translate.google.com.ni',
'translate.google.com.np', 'translate.google.com.om', 'translate.google.com.pa',
'translate.google.com.pe', 'translate.google.com.pg', 'translate.google.com.ph',
'translate.google.com.pk', 'translate.google.com.pr', 'translate.google.com.py',
'translate.google.com.qa', 'translate.google.com.sa', 'translate.google.com.sb',
'translate.google.com.sg', 'translate.google.com.sl', 'translate.google.com.sv',
'translate.google.com.tj', 'translate.google.com.tr', 'translate.google.com.tw',
'translate.google.com.ua', 'translate.google.com.uy', 'translate.google.com.vc',
'translate.google.com.vn', 'translate.google.com', 'translate.google.cv',
'translate.google.cz', 'translate.google.de', 'translate.google.dj',
'translate.google.dk', 'translate.google.dm', 'translate.google.dz',
Expand Down Expand Up @@ -65,9 +69,9 @@
'translate.google.st', 'translate.google.td', 'translate.google.tg',
'translate.google.tk', 'translate.google.tl', 'translate.google.tm',
'translate.google.tn', 'translate.google.to', 'translate.google.tt',
'translate.google.us', 'translate.google.vg', 'translate.google.vu',
'translate.google.us', 'translate.google.vg', 'translate.google.vu',
'translate.google.ws')

SPECIAL_CASES = {
'ee': 'et',
}
Expand Down

0 comments on commit 4e93fc8

Please sign in to comment.