Commits

Vladimir Kolev committed 055ec38

Added translation support and bulgarian localisation

Comments (0)

Files changed (2)

data/pysnippy.conf

 api_key = d67dff3670f8b8adf820
 
 # Mode for working offline/online
-mode = 0
+mode = 1
 except:
     print "You need to install python-gtksourceview2"
     
+import gettext
+import locale
+
+APP = 'pysnippy'
+DIR = './locale'
+
+print locale.getlocale()[0]
+
+locale.setlocale(locale.LC_ALL, '')
+gettext.bindtextdomain(APP, DIR)
+gettext.textdomain(APP)
+_ = gettext.gettext
+
+print gettext.find(APP)
+
 from lib import pysnipfuncs as psf
 import base64
 
         def __init__(self):
                 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
                 self.window.set_size_request(700, 450)
-                self.window.set_title("PySnippy")
+                self.window.set_title(_("PySnippy"))
                 winicon = gtk.gdk.pixbuf_new_from_file('icons/pysnippy_22x22.png')
                 self.window.set_icon(winicon)
                 self.window.connect('delete_event', self.destroy)
                 swb.add(self.browser)
                 self.vbox2 = gtk.VBox()
                 self.expander = gtk.Expander()
-                self.expander.set_label("Comment: ")
+                self.expander.set_label(_("Comment: "))
                 self.expander.set_expanded(True)
                 self.comment_label = gtk.Label()
                 self.comment_label.set_line_wrap(True)
         def create_columns(self, treeView):
                 """docstring for create_columns"""
                 rendererText = gtk.CellRendererText()
-                column = gtk.TreeViewColumn("Name", rendererText, text=0)
+                column = gtk.TreeViewColumn(_("Name"), rendererText, text=0)
                 column.set_max_width(150)
                 column.set_sort_column_id(0)
                 treeView.append_column(column)
 
                 rendererText = gtk.CellRendererText()
-                column = gtk.TreeViewColumn("Language", rendererText, text=1)
+                column = gtk.TreeViewColumn(_("Language"), rendererText, text=1)
                 column.set_sort_column_id(1)
                 
                 treeView.append_column(column)
         def add_snippet(self, button):
                 self.addsnip = gtk.Dialog()
                 self.addsnip.set_icon(gtk.gdk.pixbuf_new_from_file('icons/pysnippy_22x22.png'))
-                self.addsnip.set_title("Add snippet")
+                self.addsnip.set_title(_("Add snippet"))
                 self.addsnip.set_size_request(500, 350)
                 self.snipbuff = gtk.TextBuffer()
-                catlabel = gtk.Label("Select category: ")
+                catlabel = gtk.Label(_("Select category: "))
                 catlabel.set_alignment(0, 1)
                 self.categcombo = gtk.combo_box_new_text()
                 results = psf.get_cats()
                 for cat in results:
                     self.categcombo.append_text(cat[0])
-                titlabel = gtk.Label("Enter title: ")
+                titlabel = gtk.Label(_("Enter title: "))
                 titlabel.set_alignment(0, 1)
                 self.titentry = gtk.Entry()
-                sniplabel = gtk.Label("Enter your snippet: ")
+                sniplabel = gtk.Label(_("Enter your snippet: "))
                 sniplabel.set_alignment(0, 1)
                 sw = gtk.ScrolledWindow()
                 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
                 self.snip = gtk.TextView(self.snipbuff)
                 sw.add(self.snip)
-                langlabel = gtk.Label("Select snippet language: ")
+                langlabel = gtk.Label(_("Select snippet language: "))
                 langlabel.set_alignment(0, 1)
                 self.langcombo = gtk.combo_box_new_text()
                 
-                desclabel = gtk.Label("Enter description: ")
+                desclabel = gtk.Label(_("Enter description: "))
                 desclabel.set_alignment(0, 1)
                 self.descentry = gtk.Entry()
                 langs = psf.get_langs()
                 self.addsnip.vbox.pack_start(desclabel, False, False, 0)
                 self.addsnip.vbox.pack_start(self.descentry, False, False, 0)
                 
-                closebut = gtk.Button(gtk.STOCK_CLOSE, "Close")
+                closebut = gtk.Button(gtk.STOCK_CLOSE, _("Close"))
                 closebut.connect('clicked', self.close)
-                savebut = gtk.Button(gtk.STOCK_SAVE, "Save")
+                savebut = gtk.Button(gtk.STOCK_SAVE, _("Save"))
                 savebut.connect('clicked', self.store_to_db)
                 
                 self.addsnip.action_area.pack_start(closebut, False, False, 0)
                 if psf.storedb(catid, title, snippet, language, description) == 1:
                     pass
                 else:
-                    self.show_error(gtk.MESSAGE_ERROR, "Error storing to the databse")
+                    self.show_error(gtk.MESSAGE_ERROR, _("Error storing to the databse"))
                 self.addsnip.destroy()
             else:
                 title = self.titentry.get_text()
                 try:
                     sniplr.post(title, base64.decodestring(snippet), tags="PySnippy", language="%s" % language)
                 except:
-                    show_error(gtk.MESSAGE_ERROR, "Problem storing your snippet in snipplr.com")
+                    show_error(gtk.MESSAGE_ERROR, _("Problem storing your snippet in snipplr.com"))
                 self.addsnip.destroy()
             
         def close(self, button):
                 """docstring for del_snippet"""
                 if config['mode'] == "online":
                     self.show_error(gtk.MESSAGE_INFO,
-                                    "Deleting is only possible in offline mode!")
+                                    _("Deleting is only possible in offline mode!"))
                 else:
                     selection = self.tree.get_selection()
                     model, itern = selection.get_selected()
                     if itern == None:
                         self.show_error(gtk.MESSAGE_WARNING,
-                                        "You have to select something\nin order to delete it!")
+                                        _("You have to select something\nin order to delete it!"))
                     else:
                         snipid = model.get_value(itern, 0)
                         askdiag = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, 
                                                     gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, 
-                                                    "Are you sure you want to delete the snippet?")
-                        askdiag.format_secondary_markup("Snippet: <b><i>%s</i></b>" % snipid)
+                                                    _("Are you sure you want to delete the snippet?"))
+                        askdiag.format_secondary_markup(_("Snippet: <b><i>%s</i></b>") % snipid)
                         answer = askdiag.run()
                         if answer == gtk.RESPONSE_YES:
                             if psf.delete_snip(snipid) == 1:
-                                print "Snippet %s deleted" % snipid
+                                print _("Snippet %s deleted") % snipid
                             else:
-                                self.show_error(gtk.MESSAGE_ERROR, "Problem deleting snippet")
+                                self.show_error(gtk.MESSAGE_ERROR, _("Problem deleting snippet"))
                                 
                         else:
                             askdiag.destroy()
                         snipid = model.get_value(itern, 0)
                         catdiag = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                                                     gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK)
-                        catdiag.set_markup('Please select a <b>category</b>')
+                        catdiag.set_markup(_('Please select a <b>category</b>'))
                         combo = gtk.combo_box_new_text()
                         results = psf.get_cats()
                         for cat in results:
                             combo.append_text(cat[0])
                         combo.set_active(0)
                         hbox = gtk.HBox()
-                        hbox.pack_start(gtk.Label("Category: "), False, 5, 5)
+                        hbox.pack_start(gtk.Label(_("Category: ")), False, 5, 5)
                         hbox.pack_start(combo)
-                        catdiag.format_secondary_markup("Default is <i>scripts</i>")
+                        catdiag.format_secondary_markup(_("Default is <i>scripts</i>"))
                         catdiag.vbox.pack_start(hbox, True, True, 0)
                         catdiag.show_all()
                         catdiag.run()
                         try:
                             psf.storedb(catid, sniptitle, snipsource, sniplang, snipcomment)
                         except:
-                            self.show_error(gtk.MESSAGE_ERROR, "Error storing data to the database")
+                            self.show_error(gtk.MESSAGE_ERROR, _("Error storing data to the database"))
                                                 
                     else:
-                        self.show_error(gtk.MESSAGE_INFO, "Nothing to download!")
+                        self.show_error(gtk.MESSAGE_INFO, _("Nothing to download!"))
                 else:
                    self.show_error(gtk.MESSAGE_INFO,
-                                   "You can't download snippet when\nyou are using PySnippy in offline mode!")
+                                   _("You can't download snippet when\nyou are using PySnippy in offline mode!"))
 
         def exec_snipp(self, button):                
                 """docstring for exec_snipp"""
                 selection = self.tree.get_selection()
                 model, itern = selection.get_selected()
                 if itern == None:
-                    self.show_error(gtk.MESSAGE_WARNING, "Sorry, there is nothing to execute!")
+                    self.show_error(gtk.MESSAGE_WARNING, _("Sorry, there is nothing to execute!"))
                 else:
                     snipid = model.get_value(itern, 0)
                     if int(config['mode']) == 0:
                                 try:
                                     exec base64.decodestring(result[0])
                                 except:
-                                    self.show_error(gtk.MESSAGE_ERROR, "Can't execute script")                                                        
+                                    self.show_error(gtk.MESSAGE_ERROR, _("Can't execute script"))                                                        
                             else:
-                                self.show_error(gtk.MESSAGE_WARNING, "Only python scripts can be executed!")
+                                self.show_error(gtk.MESSAGE_WARNING, _("Only python scripts can be executed!"))
                     else:
                         if sniplr.get(snipid)['language'] == "python":
                             print "Executing python script"
                         else:
-                            self.show_error(gtk.MESSAGE_INFO, "Only python scripts can be executed!")
+                            self.show_error(gtk.MESSAGE_INFO, _("Only python scripts can be executed!"))
                     
         def gen_snip_name(self):
             sampling = "".join(random.sample(string.letters + string.digits, 6))
 
         def show_preferences(self, button):
                 """docstring for show_preferences"""
-                prefs = gtk.Dialog("Preferences", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
+                prefs = gtk.Dialog(_("Preferences"), None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_APPLY, gtk.RESPONSE_ACCEPT))
                 hbox1 = gtk.HBox()
-                apilab = gtk.Label("Snipplr.com API_KEY: ")
+                apilab = gtk.Label(_("Snipplr.com API_KEY: "))
                 apient = gtk.Entry()
                 apient.set_text(config['api_key'])
                 hbox1.pack_start(apilab, True, False)
                 hbox1.pack_start(apient, False, False)
                 hbox2 = gtk.HBox()
-                modelab = gtk.Label("Working mode: ")
-                modechk = gtk.CheckButton("Online")
+                modelab = gtk.Label(_("Working mode: "))
+                modechk = gtk.CheckButton(_("Online"))
                 modechk.set_active(int(config['mode']))
                 hbox2.pack_start(modelab, False, False)
                 hbox2.pack_start(modechk, True, False)
                 """docstring for show_about"""
                 about = gtk.AboutDialog()
                 about.set_icon(gtk.gdk.pixbuf_new_from_file('icons/pysnippy_22x22.png'))
-                about.set_program_name("PySnippy")
+                about.set_program_name(_("PySnippy"))
                 about.set_version(__revision__)
                 about.set_logo(gtk.gdk.pixbuf_new_from_file('icons/pysnippy_128x128.png'))
-                about.set_comments("PySnippy is a gtk application for managing your snippet localy and on snipplr.com")
+                about.set_comments(_("PySnippy is a gtk application for managing your snippet localy and on snipplr.com"))
                 about.set_website('https://bitbucket.org/vkolev/pysnippy')
                 about.set_authors(__author__)
-                about.set_copyright("Licensed under MIT License")
+                about.set_copyright(_("Licensed under MIT License"))
                 try:
                         f = open('LICENSE', 'r')
                         about.set_license(f.read())
                         f.close()
                 except:
-                        self.show_error(gtk.MESSAGE_ERROR, "Problem reading the LICENSE file")
+                        self.show_error(gtk.MESSAGE_ERROR, _("Problem reading the LICENSE file"))
                 about.run()
                 about.destroy()