[gedit-plugins/translate-server] Server
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins/translate-server] Server
- Date: Sat, 17 Oct 2020 18:49:13 +0000 (UTC)
commit 73440d14724517e44cdc55444cd0af65ebb9347d
Author: Jordi Mas <jmas softcatala org>
Date: Sat Oct 17 20:49:08 2020 +0200
Server
plugins/translate/translate/__init__.py | 39 ++++++++++++------------
plugins/translate/translate/services/apertium.py | 1 +
2 files changed, 21 insertions(+), 19 deletions(-)
---
diff --git a/plugins/translate/translate/__init__.py b/plugins/translate/translate/__init__.py
index e333254..e468add 100644
--- a/plugins/translate/translate/__init__.py
+++ b/plugins/translate/translate/__init__.py
@@ -37,6 +37,24 @@ try:
except:
_ = lambda s: s
+def _get_translation_service_shared(service_id):
+ settings = Settings()
+ service = Services.get(service_id)
+ if service.has_api_key() is True:
+ key = settings.get_apikey()
+ service.set_api_key(key)
+
+ if service_id == Services.APERTIUM_ID:
+ #server = settings.get_apertium_server()
+ server = 'https://www.apertium.com/apy'
+ print("Init:" + server)
+ service.set_server(server)
+
+ service.init()
+ return service
+
+
+
class TranslateAppActivatable(GObject.Object, Gedit.AppActivatable):
app = GObject.Property(type=Gedit.App)
@@ -93,18 +111,7 @@ class TranslateWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGt
return Services.get_name(service_id)
def _get_translation_service(self, service_id):
- settings = Settings()
- service = Services.get(service_id)
- if service.has_api_key() is True:
- key = settings.get_apikey()
- service.set_api_key(key)
-
- if service_id == Services.APERTIUM_ID:
- server = settings.get_apertium_server()
- service.set_server(server)
-
- service.init()
- return service
+ return _get_translation_service_shared(service_id)
def get_languages_names_codes(self, service_id):
service = self._get_translation_service(service_id)
@@ -184,13 +191,7 @@ class TranslateViewActivatable(GObject.Object, Gedit.ViewActivatable):
def _get_translation_service(self):
service_id = self._settings.get_service()
- service = Services.get(service_id)
- if service.has_api_key() is True:
- key = self._settings.get_apikey()
- service.set_api_key(key)
-
- service.init()
- return service
+ return _get_translation_service_shared(service_id)
def translate_text(self, document, start, end):
doc = self.view.get_buffer()
diff --git a/plugins/translate/translate/services/apertium.py
b/plugins/translate/translate/services/apertium.py
index 5da1f49..6a6bcaf 100644
--- a/plugins/translate/translate/services/apertium.py
+++ b/plugins/translate/translate/services/apertium.py
@@ -206,6 +206,7 @@ class Apertium(Service):
def translate_text(self, text, language_pair):
url = "{0}/translate?langpair={1}&markUnknown=no".format(self.server, language_pair)
url += "&q=" + urllib.parse.quote_plus(text.encode('utf-8'))
+ print(url)
response = urllib.request.urlopen(url)
data = json.loads(response.read().decode("utf-8"))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]