[gedit-plugins/translate] Default selection
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins/translate] Default selection
- Date: Sun, 4 Mar 2018 22:43:59 +0000 (UTC)
commit adcaedd0ad903ef925a74c592d06a7cd7bfd48ba
Author: Jordi Mas <jmas softcatala org>
Date: Sun Mar 4 23:43:44 2018 +0100
Default selection
plugins/translate/translate/preferences.py | 10 ++++++++++
plugins/translate/translate/services/apertium.py | 5 ++++-
plugins/translate/translate/services/service.py | 4 ++++
plugins/translate/translate/services/yandex.py | 3 +++
4 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/plugins/translate/translate/preferences.py b/plugins/translate/translate/preferences.py
index c44523d..bcb326f 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._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()
+ print("get_default:" + str(index))
+
self._languages.set_active(index)
def _init_api_entry(self):
@@ -135,6 +144,7 @@ class Preferences(object):
def _get_index(self, selected):
for i in range(len(self._model)):
if self._model[i][Preferences.LANG_CODE] == selected:
+ print("Selected" + str(selected))
return i
return -1
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 9c7d050..4b71be2 100644
--- a/plugins/translate/translate/services/yandex.py
+++ b/plugins/translate/translate/services/yandex.py
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]