OSDN Git Service

增加i18n支持,lang.pot为中文原文件
authortanyuliang <tanyuliang2@gmail.com>
Mon, 27 Jul 2015 07:15:50 +0000 (15:15 +0800)
committertanyuliang <tanyuliang2@gmail.com>
Mon, 27 Jul 2015 07:15:50 +0000 (15:15 +0800)
FriendList.py
LoginGui.py
Talk.py

index be514df..257dee6 100644 (file)
@@ -10,8 +10,8 @@ class MyFrame(wx.Frame):
         Talk.myapp(user_name=self.tree.GetItemText(event.GetItem()),un=un)
     def OnClose(self, event,un):
         dlg = wx.MessageDialog(self, 
-            "Do you really want to close this application?",
-            "Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
+            _("Do you really want to close this application?"),
+            _("Confirm Exit"), wx.OK|wx.CANCEL|wx.ICON_QUESTION)
         result = dlg.ShowModal()
         dlg.Destroy()
         if result == wx.ID_OK:
index 928ae73..4c3678f 100644 (file)
@@ -11,6 +11,11 @@ from Crypto.Cipher import AES
 from binascii import b2a_hex, a2b_hex
 import MySQLdb
 import simplejson as json
+import gettext
+import locale
+if locale.getdefaultlocale()[0] == 'zh_CN':
+    gettext.install('messages', './locale', unicode=False)
+    gettext.translation('messages', './locale', languages=['cn']).install(True)
 class prpcrypt():
     def __init__(self, key):
         self.key = key
@@ -24,14 +29,14 @@ class LoginFrame(wx.Frame):
         wx.Frame.__init__(self, parent, id, title)
         self.SetSize(size)
         self.Center()
-        self.passWordLabel = wx.StaticText(self, label = "UserName", pos = (10, 50), size = (120, 25))
-        self.userNameLabel = wx.StaticText(self, label = "Password", pos = (40, 100), size = (120, 25))
-        self.userName = wx.TextCtrl(self, pos = (120, 47), size = (150, 25))
-        self.passWord= wx.TextCtrl(self, pos = (120, 97), size = (150, 25),style=wx.TE_PASSWORD)
-        self.loginButton = wx.Button(self, label = 'Login', pos = (80, 145), size = (130, 30))
-        self.loginButton.Bind(wx.EVT_BUTTON, self.login)
+        self.passWordLabel = wx.StaticText(self, label = _("UserName"), pos = (30, 50), size = (120, 25))
+        self.userNameLabel = wx.StaticText(self, label = _("Password"), pos = (30, 100), size = (120, 25))
+        self.userName = wx.TextCtrl(self, pos = (100, 47), size = (150, 25))
+        self.passWord= wx.TextCtrl(self, pos = (100, 97), size = (150, 25),style=wx.TE_PASSWORD)
+        self.loginButton = wx.Button(self, label = _('Login'), pos = (80, 145), size = (130, 30))
+        self.loginButton.Bind(wx.EVT_BUTTON,self.login)
         self.Show()
-    def login(self, event):
+    def login(self,evt):
             db = MySQLdb.connect("db4free.net","tylchat","22842218","tylchat" )
             cursor = db.cursor()
             sql = "SELECT password FROM user WHERE name = '%s' LIMIT 1"%(self.userName.GetValue())
@@ -41,18 +46,13 @@ class LoginFrame(wx.Frame):
                for row in results:
                  password = row[0]
             except:
-                wx.MessageBox('Unable to fecth data', 'Try it again'
+                wx.MessageBox(_('Unable to fecth data'), _('Try it again')
                 wx.OK | wx.ICON_ERROR)      
             #db.close()
             passwd0 = pc.decrypt(password)
             if self.passWord.GetValue()==passwd0:
                     try:
-                        #conn = MySQLdb.connect("db4free.net","tylchat","22842218","tylchat");
-                        #cursor = conn.cursor()
                         cursor.execute("SELECT Data FROM friendlist WHERE name = '%s' LIMIT 1"%(self.userName.GetValue()))
-                        #fout = open(self.userName.GetValue() + '.xml', 'wb')
-                        #fout.write(cursor.fetchone()[0])
-                        #fout.close()
                         data = json.loads(cursor.fetchone()[0])
                         cursor.close()
                         #conn.close()
@@ -61,16 +61,16 @@ class LoginFrame(wx.Frame):
                           wx.MessageBox('Error %d: %s' % (e.args[0], e.args[1]), 'Try it again', 
                           wx.OK | wx.ICON_ERROR)
                     #urllib2.urlopen('http://chat-tyl.coding.io/user_log?info=User___'+self.userName.GetValue()+'___Login')
-                    wx.MessageBox('Login Successful', 'Information'
+                    wx.MessageBox(_('Login Successful'), _('Information')
                     wx.OK | wx.ICON_INFORMATION)
                     self.Hide()
-                    frame = FriendList.MyFrame(None, id=-1, title=self.userName.GetValue() + "'s Friend List",user=data,un=self.userName.GetValue())
+                    frame = FriendList.MyFrame(None, id=-1, title=_("Friend List"),user=data,un=self.userName.GetValue())
                     frame.Show(True)
             else:
-                    wx.MessageBox('Your Password is wrong', 'Try it again'
+                    wx.MessageBox(_('Your Password is wrong'), _('Try it again')
                     wx.OK | wx.ICON_ERROR)         
 if __name__ == '__main__':
     pc = prpcrypt('keyskeyskeyskeys')
     app = wx.App()
-    LoginFrame(None, -1, title = "Login", size = (280, 200))
+    LoginFrame(None, -1, title = _("Login"), size = (280, 200))
     app.MainLoop()
\ No newline at end of file
diff --git a/Talk.py b/Talk.py
index 4015c07..0be6126 100644 (file)
--- a/Talk.py
+++ b/Talk.py
@@ -7,7 +7,7 @@ import simplejson as json
 from time import sleep
 class myapp(wx.App):
     def __init__(self,user_name,un):
-        frame = wx.Frame(None,title="With " + user_name + " Talking",pos = (100,50),size = (400,300))
+        frame = wx.Frame(None,title=_("With ") + user_name + _(" Talking"),pos = (100,50),size = (400,300))
         global username
         username=user_name
         self.bkg = wx.Panel(frame)
@@ -15,7 +15,7 @@ class myapp(wx.App):
         un_g=un
         self.tshow = wx.TextCtrl(self.bkg,style = wx.TE_MULTILINE|wx.HSCROLL|wx.TE_READONLY)
         self.tinput = wx.TextCtrl(self.bkg)
-        self.bt = wx.Button(self.bkg,label = "Send")      
+        self.bt = wx.Button(self.bkg,label = _("Send"))      
         self.box1 = wx.BoxSizer()
         self.box1.Add(self.tinput,proportion = 1,flag = wx.EXPAND)
         self.box1.Add(self.bt,proportion = 0)        
@@ -30,7 +30,7 @@ class myapp(wx.App):
     def btaction(self,evt):
         now = datetime.datetime.now()
         self.tshow.SetDefaultStyle(wx.TextAttr("GREEN"))
-        self.tshow.AppendText("I:"+now.strftime('%Y-%m-%d %H:%M:%S')+"\n")
+        self.tshow.AppendText(_("I:")+now.strftime('%Y-%m-%d %H:%M:%S')+"\n")
         self.tshow.SetDefaultStyle(wx.TextAttr("BLACK"))
         self.tshow.AppendText(self.tinput.GetValue() + "\n")
         rc = redis.Redis(host='pub-redis-19834.us-east-1-4.5.ec2.garantiadata.com',port=19834,password='22842218')
@@ -56,7 +56,7 @@ class myapp(wx.App):
                    if text_json['user'] == un_g: 
                        now = datetime.datetime.now()
                        self.tshow.SetDefaultStyle(wx.TextAttr("BLUE"))
-                       wx.CallAfter(self.tshow.AppendText, "User:"+now.strftime('%Y-%m-%d %H:%M:%S')+"\n")
+                       wx.CallAfter(self.tshow.AppendText, _("User:")+now.strftime('%Y-%m-%d %H:%M:%S')+"\n")
                        sleep(0.1)
                        self.tshow.SetDefaultStyle(wx.TextAttr("BLACK"))
                        wx.CallAfter(self.tshow.AppendText, text_json['content'] + "\n")