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
1=== modified file 'Translator/Changelog.txt'
2--- Translator/Changelog.txt 2011-01-14 11:42:23 +0000
3+++ Translator/Changelog.txt 2011-01-16 15:45:32 +0000
4@@ -1,3 +1,4 @@
5+0.1.7:(January/16/2011): Added the Web Page translation. Entering a URL, the translated page is loaded in the current web browser.
6 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.
7 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]
8 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.
9
10=== modified file 'Translator/Translator'
11--- Translator/Translator 2011-01-15 00:50:16 +0000
12+++ Translator/Translator 2011-01-16 15:45:32 +0000
13@@ -31,7 +31,7 @@
14 # * Press Ctrl + Alt + W, type the text, and press Enter
15 # Translated text will be shown as a dialog and be available in the clipboard, just press Ctrl+v to have it
16
17-import gobject, dbus, os, urllib, gtk, ConfigParser
18+import gobject, dbus, os, urllib, gtk, ConfigParser, webbrowser
19 from dbus.mainloop.glib import DBusGMainLoop
20 from dbus import glib
21 from sgmllib import SGMLParser
22@@ -315,28 +315,34 @@
23 def translate(self, sentence, source, destiny):
24 self.inform_start_of_waiting_process()
25
26- interface = Interface(sentence) # alimenta o tradutor com o sentence a ser traduzida
27- translated, dictionary = interface.translate_it(source, destiny) # texto traduzido e o resultado do dicionario
28-
29- if len(sentence.split()) == 1: # Just one word, dictionary was returned
30- message = ""
31- for category, words in dictionary.iteritems():
32- message += "<i>%s</i>\n\n" % category
33- message += "%s\n\n" % "\n".join(words[1:]) # array of words com with the category name in first position
34- else: # Sentence, only the translation was returned
35- message = translated
36- try:
37- self.icon.PopupDialog({'message':message, "use-markup":True, "buttons":"cancel;stock_refresh;stock_edit"}, {})
38- except Exception:
39- log("Error caused PopupDialog not be shown, ShowDialog was used instead")
40- self.icon.ShowDialog(message, self.dialog_active_time)
41+ # Translate URL
42+ if sentence.startswith(("http://", "https://", "www.")): # barely checking if user is trying to translate a web page
43+ url = "http://translate.google.com/translate?sl=%s&tl=%s&u=%s" % (source, destiny, sentence)
44+ webbrowser.open(url)
45+ log("Translated URL %s" % sentence)
46 else:
47- log("PopupDialog succesfully shown")
48- self.set_to_clipboard(translated) # coloca o resultado na area de transferencia
49+ # Translate one word, or sentence
50+ interface = Interface(sentence) # alimenta o tradutor com o sentence a ser traduzida
51+ translated, dictionary = interface.translate_it(source, destiny) # texto traduzido e o resultado do dicionario
52+ if len(sentence.split()) == 1: # just one word, dictionary was returned
53+ message = ""
54+ for category, words in dictionary.iteritems():
55+ message += "<i>%s</i>\n\n" % category
56+ message += "%s\n\n" % "\n".join(words[1:]) # array of words with categoy name as the first position, chop
57+ log("Translated with dictionary %s" % message)
58+ else: # sentence, only the translation was returned
59+ message = translated
60+ log ("Translated sentence %s" % message)
61+
62+ try:
63+ self.icon.PopupDialog({'message':message, "use-markup":True, "buttons":"cancel;stock_new;stock_edit"}, {})
64+ except Exception:
65+ self.icon.ShowDialog(message, self.dialog_active_time) # PopupDialog could not be shown, ShowDialog was used instead
66+
67+ self.set_to_clipboard(translated) # coloca o resultado na area de transferencia
68 # apenas a primeira palavra no caso do dicionario
69 self.inform_end_of_waiting_process()
70 self.inform_current_destiny_language()
71- log ("Translated: %s" % message)
72
73 def ask_text(self, default=""):
74 label = "Translate from %s to %s:" % (self.source.name, self.destiny.name)
75
76=== modified file 'Translator/Translator.conf'
77--- Translator/Translator.conf 2011-01-14 11:42:23 +0000
78+++ Translator/Translator.conf 2011-01-16 15:45:32 +0000
79@@ -1,4 +1,4 @@
80-#!en;0.1.6
81+#!en;0.1.7
82
83 #[gtk-about]
84 [Icon]
85
86=== modified file 'Translator/auto-load.conf'
87--- Translator/auto-load.conf 2011-01-14 11:42:23 +0000
88+++ Translator/auto-load.conf 2011-01-16 15:45:32 +0000
89@@ -4,10 +4,10 @@
90 author = Eduardo Mucelli Rezende Oliveira
91
92 # A short description of the applet and how to use it.
93-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
94+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
95
96 # Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun
97 category = 5
98
99 # 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.
100-version = 0.1.6
101+version = 0.1.7

Subscribers

People subscribed via source and target branches