[gedit-plugins] Fixes for #794045
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins] Fixes for #794045
- Date: Sun, 4 Mar 2018 23:35:11 +0000 (UTC)
commit 78b573372625c22497fa798cd5f530cdb0b3a392
Author: Jordi Mas <jmas softcatala org>
Date: Mon Mar 5 00:34:54 2018 +0100
Fixes for #794045
plugins/translate/translate/preferences.py | 17 +++++++-
plugins/translate/translate/services/apertium.py | 5 ++-
plugins/translate/translate/services/service.py | 4 ++
plugins/translate/translate/services/yandex.py | 47 ++++++++++++---------
4 files changed, 51 insertions(+), 22 deletions(-)
---
diff --git a/plugins/translate/translate/preferences.py b/plugins/translate/translate/preferences.py
index 4686595..5c378e6 100644
--- a/plugins/translate/translate/preferences.py
+++ b/plugins/translate/translate/preferences.py
@@ -47,12 +47,21 @@ class Preferences(object):
self._ui.set_translation_domain(GETTEXT_PACKAGE)
self._ui.add_from_file(self._ui_path)
+ def _get_default_language(self):
+ service = Services.get(self._service_id)
+ selected = service.get_default_language_codes()
+ return self._get_index(selected)
+
def _populate_languages(self):
+ self._languages.set_wrap_width(3)
self._language_names, self._language_codes = self._get_languages_names_codes(self._service_id)
self._model = self._get_languages_stored_model()
self._languages.set_model(self._model)
selected = self._settings.get_language_pair()
index = self._get_index(selected)
+ if index == -1:
+ index = self._get_default_language()
+
self._languages.set_active(index)
def _init_api_entry(self):
@@ -153,11 +162,12 @@ class Preferences(object):
item = model[index]
self._service_id = item[1]
- self._settings.set_service(self._service_id)
service = Services.get(self._service_id)
if service.has_api_key() is True:
key = self._settings.get_apikey()
service.set_api_key(key)
+ else:
+ self._settings.set_service(self._service_id)
service.init()
self._update_api_key_ui(service.has_api_key())
@@ -166,6 +176,11 @@ class Preferences(object):
def _changed_apikey(self, text_entry):
text = text_entry.get_text()
self._settings.set_apikey(text)
+ if len(text) > 0:
+ self._settings.set_service(self._service_id)
+ else:
+ self._settings.set_service(Services.APERTIUM_ID)
+
def _radio_samedoc_callback(self, widget, data=None):
self._settings.set_output_document(widget.get_active())
diff --git a/plugins/translate/translate/services/apertium.py
b/plugins/translate/translate/services/apertium.py
index 77edc59..d252dd5 100644
--- a/plugins/translate/translate/services/apertium.py
+++ b/plugins/translate/translate/services/apertium.py
@@ -45,7 +45,10 @@ class Apertium(Service):
def _clean_for_ut():
Apertium.g_language_codes = []
Apertium.g_language_names = []
- Apertium.g_locales_names = {}
+ Apertium.g_locales_names = {}
+
+ def get_default_language_codes(self):
+ return 'eng|spa'
def has_api_key(self):
return False
diff --git a/plugins/translate/translate/services/service.py b/plugins/translate/translate/services/service.py
index 867bb57..c87266a 100644
--- a/plugins/translate/translate/services/service.py
+++ b/plugins/translate/translate/services/service.py
@@ -38,6 +38,10 @@ class Service(metaclass=ABCMeta):
pass
@abstractmethod
+ def get_default_language_codes(self):
+ pass
+
+ @abstractmethod
def has_api_key(self):
pass
diff --git a/plugins/translate/translate/services/yandex.py b/plugins/translate/translate/services/yandex.py
index 53150e3..4b71be2 100644
--- a/plugins/translate/translate/services/yandex.py
+++ b/plugins/translate/translate/services/yandex.py
@@ -32,7 +32,7 @@ class Yandex(Service):
"Catalan -> English",
"English -> Catalan"]
- DEFAULT_LANGUAGE_CODES = ["es-en",
+ DEFAULT_LANGUAGE_CODES = ["es|en",
"en|es",
"ca|en",
"en|ca",
@@ -49,6 +49,9 @@ class Yandex(Service):
Yandex.g_language_names = []
Yandex.g_locales_names = {}
+ def get_default_language_codes(self):
+ return 'en|es'
+
def has_api_key(self):
return True
@@ -83,25 +86,29 @@ class Yandex(Service):
def _get_remote_language_names(self):
- url = "{0}/getLangs?ui=en&key={1}".format(self.SERVER, self._key)
- response = urllib.request.urlopen(url)
- payload = json.loads(response.read().decode("utf-8"))
-
- language_codes = payload['dirs']
- language_codes = [x.replace('-', '|') for x in language_codes]
- locales_names = payload['langs']
-
- language_names = []
- for lang_pair in language_codes:
- langs = lang_pair.split('|')
- source = langs[0]
- target = langs[1]
- name = self.get_language_pair_name(source, target, locales_names)
- language_names.append(name)
-
- Yandex.g_locales_names = locales_names
- Yandex.g_language_names = language_names
- Yandex.g_language_codes = language_codes
+ try:
+ url = "{0}/getLangs?ui=en&key={1}".format(self.SERVER, self._key)
+ response = urllib.request.urlopen(url)
+ payload = json.loads(response.read().decode("utf-8"))
+
+ language_codes = payload['dirs']
+ language_codes = [x.replace('-', '|') for x in language_codes]
+ locales_names = payload['langs']
+
+ language_names = []
+ for lang_pair in language_codes:
+ langs = lang_pair.split('|')
+ source = langs[0]
+ target = langs[1]
+ name = self.get_language_pair_name(source, target, locales_names)
+ language_names.append(name)
+
+ Yandex.g_locales_names = locales_names
+ Yandex.g_language_names = language_names
+ Yandex.g_language_codes = language_codes
+
+ except Exception as e:
+ print("_get_remote_language_names exception {0}".format(e))
def translate_text(self, text, language_pair):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]