[gedit-plugins/translate] Do not thrown exception if cannot connect
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins/translate] Do not thrown exception if cannot connect
- Date: Sun, 4 Mar 2018 20:32:21 +0000 (UTC)
commit 0800b337fcdb2185f7b48312a3d5a50762820d0b
Author: Jordi Mas <jmas softcatala org>
Date: Sun Mar 4 21:31:54 2018 +0100
Do not thrown exception if cannot connect
plugins/translate/translate/services/yandex.py | 42 +++++++++++++-----------
1 files changed, 23 insertions(+), 19 deletions(-)
---
diff --git a/plugins/translate/translate/services/yandex.py b/plugins/translate/translate/services/yandex.py
index 53150e3..bde055b 100644
--- a/plugins/translate/translate/services/yandex.py
+++ b/plugins/translate/translate/services/yandex.py
@@ -83,25 +83,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]