Merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Translator into lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party

Proposed by Eduardo Mucelli Rezende Oliveira
Status: Merged
Merged at revision: 129
Proposed branch: lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Translator
Merge into: lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party
Diff against target: 101 lines (+29/-22)
4 files modified
Translator/Changelog.txt (+1/-0)
Translator/Translator (+25/-19)
Translator/Translator.conf (+1/-1)
Translator/auto-load.conf (+2/-2)
To merge this branch: bzr merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Translator
Reviewer Review Type Date Requested Status
Matthieu Baerts Approve
Review via email: mp+46413@code.launchpad.net

Commit message

Added the Web Page translation. Entering a URL, the translated page is loaded in the current web browser.

Description of the change

Added the Web Page translation.

To post a comment you must log in.
Revision history for this message
Matthieu Baerts (matttbe) :
review: Approve
129. By Eduardo Mucelli Rezende Oliveira

Added the Web Page translation. Entering a URL, the translated page is loaded in the current web browser

Revision history for this message
Matthieu Baerts (matttbe) wrote :

@ Eduardo: I've just replaced the icon "stock_new" by "stock_refresh" (because 'stock_new' isn't available in so many icons themes)

BTW Thank you for this new version ;)

Revision history for this message
Eduardo Mucelli Rezende Oliveira (eduardo-mucelli) wrote :

@ Matttbe: Ok, perfect. Thanks for your modification.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
10.1.7:(January/16/2011): Added the Web Page translation. Entering a URL, the translated page is loaded in the current web browser.
10.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.20.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.
20.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]30.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]
30.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.40.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.
45
=== 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 @@
31# * Press Ctrl + Alt + W, type the text, and press Enter31# * Press Ctrl + Alt + W, type the text, and press Enter
32# Translated text will be shown as a dialog and be available in the clipboard, just press Ctrl+v to have it32# Translated text will be shown as a dialog and be available in the clipboard, just press Ctrl+v to have it
3333
34import gobject, dbus, os, urllib, gtk, ConfigParser34import gobject, dbus, os, urllib, gtk, ConfigParser, webbrowser
35from dbus.mainloop.glib import DBusGMainLoop35from dbus.mainloop.glib import DBusGMainLoop
36from dbus import glib36from dbus import glib
37from sgmllib import SGMLParser37from sgmllib import SGMLParser
@@ -315,28 +315,34 @@
315 def translate(self, sentence, source, destiny):315 def translate(self, sentence, source, destiny):
316 self.inform_start_of_waiting_process()316 self.inform_start_of_waiting_process()
317317
318 interface = Interface(sentence) # alimenta o tradutor com o sentence a ser traduzida318 # Translate URL
319 translated, dictionary = interface.translate_it(source, destiny) # texto traduzido e o resultado do dicionario319 if sentence.startswith(("http://", "https://", "www.")): # barely checking if user is trying to translate a web page
320320 url = "http://translate.google.com/translate?sl=%s&tl=%s&u=%s" % (source, destiny, sentence)
321 if len(sentence.split()) == 1: # Just one word, dictionary was returned321 webbrowser.open(url)
322 message = ""322 log("Translated URL %s" % sentence)
323 for category, words in dictionary.iteritems():
324 message += "<i>%s</i>\n\n" % category
325 message += "%s\n\n" % "\n".join(words[1:]) # array of words com with the category name in first position
326 else: # Sentence, only the translation was returned
327 message = translated
328 try:
329 self.icon.PopupDialog({'message':message, "use-markup":True, "buttons":"cancel;stock_refresh;stock_edit"}, {})
330 except Exception:
331 log("Error caused PopupDialog not be shown, ShowDialog was used instead")
332 self.icon.ShowDialog(message, self.dialog_active_time)
333 else:323 else:
334 log("PopupDialog succesfully shown")324 # Translate one word, or sentence
335 self.set_to_clipboard(translated) # coloca o resultado na area de transferencia325 interface = Interface(sentence) # alimenta o tradutor com o sentence a ser traduzida
326 translated, dictionary = interface.translate_it(source, destiny) # texto traduzido e o resultado do dicionario
327 if len(sentence.split()) == 1: # just one word, dictionary was returned
328 message = ""
329 for category, words in dictionary.iteritems():
330 message += "<i>%s</i>\n\n" % category
331 message += "%s\n\n" % "\n".join(words[1:]) # array of words with categoy name as the first position, chop
332 log("Translated with dictionary %s" % message)
333 else: # sentence, only the translation was returned
334 message = translated
335 log ("Translated sentence %s" % message)
336
337 try:
338 self.icon.PopupDialog({'message':message, "use-markup":True, "buttons":"cancel;stock_new;stock_edit"}, {})
339 except Exception:
340 self.icon.ShowDialog(message, self.dialog_active_time) # PopupDialog could not be shown, ShowDialog was used instead
341
342 self.set_to_clipboard(translated) # coloca o resultado na area de transferencia
336 # apenas a primeira palavra no caso do dicionario343 # apenas a primeira palavra no caso do dicionario
337 self.inform_end_of_waiting_process()344 self.inform_end_of_waiting_process()
338 self.inform_current_destiny_language()345 self.inform_current_destiny_language()
339 log ("Translated: %s" % message)
340346
341 def ask_text(self, default=""):347 def ask_text(self, default=""):
342 label = "Translate from %s to %s:" % (self.source.name, self.destiny.name)348 label = "Translate from %s to %s:" % (self.source.name, self.destiny.name)
343349
=== 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 @@
1#!en;0.1.61#!en;0.1.7
22
3#[gtk-about]3#[gtk-about]
4[Icon]4[Icon]
55
=== 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 @@
4author = Eduardo Mucelli Rezende Oliveira4author = Eduardo Mucelli Rezende Oliveira
55
6# A short description of the applet and how to use it.6# A short description of the applet and how to use it.
7description = 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 it7description = 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
88
9# Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun9# Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun
10category = 510category = 5
1111
12# 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.12# 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.
13version = 0.1.613version = 0.1.7

Subscribers

People subscribed via source and target branches