← Back to team overview

cairo-dock-team team mailing list archive

[Merge] lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Translator into lp:cairo-dock-plug-ins-extras

 

Eduardo Mucelli Rezende Oliveira has proposed merging lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Translator into lp:cairo-dock-plug-ins-extras.

Requested reviews:
  Cairo-Dock Team (cairo-dock-team)

For more details, see:
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Translator/+merge/46413

Added the Web Page translation.
-- 
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Translator/+merge/46413
Your team Cairo-Dock Team is requested to review the proposed merge of lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Translator into lp:cairo-dock-plug-ins-extras.
=== modified file 'Translator/Changelog.txt'
--- Translator/Changelog.txt	2011-01-14 11:42:23 +0000
+++ Translator/Changelog.txt	2011-01-16 15:45:32 +0000
@@ -1,3 +1,4 @@
+0.1.7:(January/16/2011): Added the Web Page translation. Entering a URL, the translated page is loaded in the current web browser.
 0.1.6:(January/14/2011): Added the dictionary functionality. If there is only one word to be translated, show the dictionary with the possible translations in categories.
 0.1.5:(October/27/2010): Added a string pre-processing to remove the possible line breaks in the text to be translated. Changed the shortcuts, both the X-server, and the Dock one were set to Ctrl+Alt[W|R]
 0.1.4:(August/24/2010): For Cairo-dock 2.2.0 or higher, the user can move from the translation result to a new translation, or edit the recently translated text.

=== modified file 'Translator/Translator'
--- Translator/Translator	2011-01-15 00:50:16 +0000
+++ Translator/Translator	2011-01-16 15:45:32 +0000
@@ -31,7 +31,7 @@
 #        * Press Ctrl + Alt + W, type the text, and press Enter
 #    Translated text will be shown as a dialog and be available in the clipboard, just press Ctrl+v to have it
 
-import gobject, dbus, os, urllib, gtk, ConfigParser
+import gobject, dbus, os, urllib, gtk, ConfigParser, webbrowser
 from dbus.mainloop.glib import DBusGMainLoop
 from dbus import glib
 from sgmllib import SGMLParser
@@ -315,28 +315,34 @@
     def translate(self, sentence, source, destiny):
         self.inform_start_of_waiting_process()
 
-        interface = Interface(sentence)                                                 # alimenta o tradutor com o sentence a ser traduzida
-        translated, dictionary = interface.translate_it(source, destiny)                # texto traduzido e o resultado do dicionario
-
-        if len(sentence.split()) == 1:                                                  # Just one word, dictionary was returned
-            message = ""
-            for category, words in dictionary.iteritems():
-                message += "<i>%s</i>\n\n" % category 
-                message += "%s\n\n" % "\n".join(words[1:])                              # array of words com with the category name in first position
-        else:                                                                           # Sentence, only the translation was returned
-            message = translated
-        try:
-            self.icon.PopupDialog({'message':message, "use-markup":True, "buttons":"cancel;stock_refresh;stock_edit"}, {})
-        except Exception:
-            log("Error caused PopupDialog not be shown, ShowDialog was used instead")
-            self.icon.ShowDialog(message, self.dialog_active_time)
+        # Translate URL
+        if sentence.startswith(("http://";, "https://";, "www.")):                        # barely checking if user is trying to translate a web page
+            url = "http://translate.google.com/translate?sl=%s&tl=%s&u=%s"; % (source, destiny, sentence)
+            webbrowser.open(url)
+            log("Translated URL %s" % sentence)
         else:
-            log("PopupDialog succesfully shown")
-        self.set_to_clipboard(translated)                                               # coloca o resultado na area de transferencia
+            # Translate one word, or sentence
+            interface = Interface(sentence)                                             # alimenta o tradutor com o sentence a ser traduzida
+            translated, dictionary = interface.translate_it(source, destiny)            # texto traduzido e o resultado do dicionario
+            if len(sentence.split()) == 1:                                              # just one word, dictionary was returned
+                message = ""
+                for category, words in dictionary.iteritems():
+                    message += "<i>%s</i>\n\n" % category 
+                    message += "%s\n\n" % "\n".join(words[1:])                          # array of words with categoy name as the first position, chop
+                log("Translated with dictionary %s" % message)
+            else:                                                                       # sentence, only the translation was returned
+                message = translated
+                log ("Translated sentence %s" % message)
+
+            try:
+                self.icon.PopupDialog({'message':message, "use-markup":True, "buttons":"cancel;stock_new;stock_edit"}, {})
+            except Exception:
+                self.icon.ShowDialog(message, self.dialog_active_time)                  # PopupDialog could not be shown, ShowDialog was used instead
+
+            self.set_to_clipboard(translated)                                           # coloca o resultado na area de transferencia
                                                                                         # apenas a primeira palavra no caso do dicionario
         self.inform_end_of_waiting_process()
         self.inform_current_destiny_language()
-        log ("Translated: %s" % message)
 
     def ask_text(self, default=""):
         label = "Translate from %s to %s:" % (self.source.name, self.destiny.name)

=== modified file 'Translator/Translator.conf'
--- Translator/Translator.conf	2011-01-14 11:42:23 +0000
+++ Translator/Translator.conf	2011-01-16 15:45:32 +0000
@@ -1,4 +1,4 @@
-#!en;0.1.6
+#!en;0.1.7
 
 #[gtk-about]
 [Icon]

=== modified file 'Translator/auto-load.conf'
--- Translator/auto-load.conf	2011-01-14 11:42:23 +0000
+++ Translator/auto-load.conf	2011-01-16 15:45:32 +0000
@@ -4,10 +4,10 @@
 author = Eduardo Mucelli Rezende Oliveira
 
 # A short description of the applet and how to use it.
-description = This applet provides a translator tool using the Google Translator service\n    Translator (formally doCkranslator) translates from lots of languages to lots of languages\n    First it is necessary to choose the languages using one of the following ways:\n        (I) Scroll up/down over the icon to choose the destination language\n        (II) Right-click on the icon -> "To", or "From"\n        (III) Right-click on the icon -> Translator -> Configuration\n    To translate you can do it using one of the following ways:\n        (I) Left-click on the icon; type your text and press Enter\n        (II) Select any text in any place, and middle click on the icon\n    The plugin also provides useful keyboard shortcuts (requires Python-Xlib, or Cairo-dock 2.2.0)\n        If you want to translate something you are reading in the foreign language you chose "From":\n        * Press Ctrl + Alt + R, type the text, and press Enter\n        If you are writing something in your native language you chose "To":\n        * Press Ctrl + Alt + W, type the text, and press Enter\n    Translated text will be shown as a dialog and be available in the clipboard, just press Ctrl+v to have it
+description = This applet provides a translator tool using the Google Translator service\n    Translator (formally doCkranslator) translates sentences, web pages, and single words showing the dictionary\n    First it is necessary to choose the languages using one of the following ways:\n        (I) Scroll up/down over the icon to choose the destination language\n        (II) Right-click on the icon -> "To", or "From"\n        (III) Right-click on the icon -> Translator -> Configuration\n    To translate you can do it using one of the following ways:\n        (I) Left-click on the icon; type your text and press Enter\n        (II) Select any text in any place, and middle click on the icon\n    The plugin also provides useful keyboard shortcuts (requires Python-Xlib, or Cairo-dock 2.2.0)\n        If you want to translate something you are reading in the foreign language you chose "From":\n        * Press Ctrl + Alt + R, type the text, and press Enter\n        If you are writing something in your native language you chose "To":\n        * Press Ctrl + Alt + W, type the text, and press Enter\n    Translated text will be shown as a dialog and be available in the clipboard, just press Ctrl+v to have it
 
 # Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun
 category = 5
 
 # Version of the applet; change it everytime you change something in the config file. Don't forget to update the version both in this file and in the config file.
-version = 0.1.6
+version = 0.1.7