[gedit-plugins] Add instructions on how to get Yandex key



commit 66b584e72d9cb156c0f3d4c866799347868e6fb7
Author: Jordi Mas <jmas softcatala org>
Date:   Mon Mar 5 21:52:28 2018 +0100

    Add instructions on how to get Yandex key

 plugins/translate/translate/preferences.py       |   11 ++++++++-
 plugins/translate/translate/services/apertium.py |    3 ++
 plugins/translate/translate/services/service.py  |   12 +++++++++++
 plugins/translate/translate/services/yandex.py   |    3 ++
 plugins/translate/translate/ui/preferences.ui    |   23 +++++++++++++++++++++-
 po/POTFILES.in                                   |    1 +
 6 files changed, 50 insertions(+), 3 deletions(-)
---
diff --git a/plugins/translate/translate/preferences.py b/plugins/translate/translate/preferences.py
index 5c378e6..9b3096b 100644
--- a/plugins/translate/translate/preferences.py
+++ b/plugins/translate/translate/preferences.py
@@ -70,24 +70,31 @@ class Preferences(object):
             self._update_api_key_ui(True)
 
     def _update_api_key_ui(self, show):
+        apibox_container = self._ui.get_object('api_box_container')
         apibox = self._ui.get_object('api_box')
 
         if show is True:
+            service = Services.get(self._service_id)
             self._apilabel = Gtk.Label("API Key")
             self._apikey = Gtk.Entry(expand=True)
-
             self._apikey.connect('changed', self._changed_apikey)
             key = self._settings.get_apikey()
             self._apikey.set_text(key)
 
             apibox.add(self._apilabel)
             apibox.add(self._apikey)
-            apibox.show_all()
+
+            self._hint = Gtk.Label()
+            self._hint.set_markup(service.get_api_hint())
+            apibox_container.add(self._hint)
+            apibox_container.show_all()
         else:
             apibox.remove(self._apilabel)
             apibox.remove(self._apikey)
+            apibox_container.remove(self._hint)
             self._apilabel = None
             self._apikey = None
+            self._hint = None
 
     def _init_radiobuttons(self):
         self._radio_samedoc = self._ui.get_object('same_document')
diff --git a/plugins/translate/translate/services/apertium.py 
b/plugins/translate/translate/services/apertium.py
index d252dd5..c1a51f2 100644
--- a/plugins/translate/translate/services/apertium.py
+++ b/plugins/translate/translate/services/apertium.py
@@ -56,6 +56,9 @@ class Apertium(Service):
     def set_api_key(self, key):
         pass
 
+    def get_api_hint(self):
+        pass
+
     def init(self):
         self._get_remote_language_names_and_pairs()
 
diff --git a/plugins/translate/translate/services/service.py b/plugins/translate/translate/services/service.py
index c87266a..b9769af 100644
--- a/plugins/translate/translate/services/service.py
+++ b/plugins/translate/translate/services/service.py
@@ -19,6 +19,14 @@
 
 from abc import ABCMeta, abstractmethod
 
+try:
+    import gettext
+    gettext.bindtextdomain('gedit-plugins')
+    gettext.textdomain('gedit-plugins')
+    _ = gettext.gettext
+except:
+    _ = lambda s: s
+
 class Service(metaclass=ABCMeta):
 
     @abstractmethod
@@ -44,6 +52,10 @@ class Service(metaclass=ABCMeta):
     @abstractmethod
     def has_api_key(self):
         pass
+
+    @abstractmethod
+    def get_api_hint(self):
+        pass
     
     @abstractmethod    
     def set_api_key(self, key):
diff --git a/plugins/translate/translate/services/yandex.py b/plugins/translate/translate/services/yandex.py
index 4b71be2..1cd08ab 100644
--- a/plugins/translate/translate/services/yandex.py
+++ b/plugins/translate/translate/services/yandex.py
@@ -52,6 +52,9 @@ class Yandex(Service):
     def get_default_language_codes(self):
         return 'en|es'
 
+    def get_api_hint(self):
+        return _("You need to obtain a free API key at <a 
href='https://tech.yandex.com/translate/'>https://tech.yandex.com/translate/</a>")
+
     def has_api_key(self):
         return True
 
diff --git a/plugins/translate/translate/ui/preferences.ui b/plugins/translate/translate/ui/preferences.ui
index 96de721..8ae6823 100644
--- a/plugins/translate/translate/ui/preferences.ui
+++ b/plugins/translate/translate/ui/preferences.ui
@@ -111,9 +111,30 @@
       </packing>
     </child>
     <child>
-      <object class="GtkBox" id ="api_box">
+      <object class="GtkBox" id="api_box_container">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkBox" id="api_box">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
       </object>
       <packing>
         <property name="left_attach">0</property>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d1e143f..169c2e5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -59,6 +59,7 @@ plugins/textsize/textsize.plugin.desktop.in.in
 plugins/translate/gedit-translate.metainfo.xml.in
 plugins/translate/org.gnome.gedit.plugins.translate.gschema.xml
 plugins/translate/translate/__init__.py
+plugins/translate/translate/services/yandex.py
 plugins/translate/translate.plugin.desktop.in.in
 [type: gettext/glade]plugins/translate/translate/ui/preferences.ui
 [type: gettext/glade]plugins/wordcompletion/gedit-word-completion-configure.ui


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]