Improve localization support in etherlab (mostly)
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Wed, 03 Oct 2018 12:43:35 +0300
changeset 2423 2c7b7ae24d57
parent 2422 45aa510d7a2a
child 2424 dc5554f0c12c
Improve localization support in etherlab (mostly)
dialogs/SFCStepNameDialog.py
etherlab/CommonEtherCATFunction.py
etherlab/EtherCATManagementEditor.py
etherlab/EthercatMaster.py
--- a/dialogs/SFCStepNameDialog.py	Wed Oct 03 12:07:56 2018 +0300
+++ b/dialogs/SFCStepNameDialog.py	Wed Oct 03 12:43:35 2018 +0300
@@ -34,7 +34,7 @@
 
 class SFCStepNameDialog(wx.TextEntryDialog):
 
-    def __init__(self, parent, message, caption="Please enter text", defaultValue="",
+    def __init__(self, parent, message, caption=_("Please enter text"), defaultValue="",
                  style=wx.OK | wx.CANCEL | wx.CENTRE, pos=wx.DefaultPosition):
         wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
 
--- a/etherlab/CommonEtherCATFunction.py	Wed Oct 03 12:07:56 2018 +0300
+++ b/etherlab/CommonEtherCATFunction.py	Wed Oct 03 12:43:35 2018 +0300
@@ -28,7 +28,7 @@
         return int(value.replace("#", "0"), 16)
 
     except Exception:
-        raise ValueError("Invalid value for HexDecValue \"%s\"" % value)
+        raise ValueError(_("Invalid value for HexDecValue \"%s\"") % value)
 
 
 def ExtractName(names, default=None):
@@ -1578,7 +1578,7 @@
             number_of_lines = return_val.split("\n")
             if len(number_of_lines) <= 2:  # No slave connected to the master controller
                 if not cyclic_flag:
-                    self.CreateErrorDialog('No connected slaves')
+                    self.CreateErrorDialog(_('No connected slaves'))
                 return False
 
             elif len(number_of_lines) > 2:
@@ -1586,7 +1586,7 @@
         else:
             # The master controller is not connected to Beremiz host
             if not cyclic_flag:
-                self.CreateErrorDialog('PLC not connected!')
+                self.CreateErrorDialog(_('PLC not connected!'))
             return False
 
     def CreateErrorDialog(self, mention):
@@ -1596,7 +1596,7 @@
         """
         app_frame = self.Controler.GetCTRoot().AppFrame
         dlg = wx.MessageDialog(app_frame, mention,
-                               ' Warning...',
+                               _(' Warning...'),
                                wx.OK | wx.ICON_INFORMATION)
         dlg.ShowModal()
         dlg.Destroy()
--- a/etherlab/EtherCATManagementEditor.py	Wed Oct 03 12:07:56 2018 +0300
+++ b/etherlab/EtherCATManagementEditor.py	Wed Oct 03 12:43:35 2018 +0300
@@ -247,7 +247,7 @@
                     self.Controler.CommonMethod.RequestSlaveState("OP")
                     self.TextCtrlDic["TargetState"].SetValue("OP")
                 else:
-                    self.Controler.CommonMethod.CreateErrorDialog("PLC is Not Started")
+                    self.Controler.CommonMethod.CreateErrorDialog(_("PLC is Not Started"))
 
     def GetCurrentState(self, event):
         """
@@ -358,7 +358,7 @@
         @return True or False
         """
 
-        slaveSDO_progress = wx.ProgressDialog("Slave SDO Monitoring", "Now Uploading...",
+        slaveSDO_progress = wx.ProgressDialog(_("Slave SDO Monitoring"), _("Now Uploading..."),
                                               maximum=len(self.SDOs.splitlines()),
                                               parent=self,
                                               style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME |
@@ -645,11 +645,11 @@
 
                         self.SetCellValue(event.GetRow(), event.GetCol(), hex(int(dlg.GetValue(), 0)))
                     else:
-                        self.Controler.CommonMethod.CreateErrorDialog('You cannot SDO download this state')
+                        self.Controler.CommonMethod.CreateErrorDialog(_('You cannot SDO download this state'))
                 # Error occured process of "int(variable)"
                 # User input is not hex, dec value
                 except ValueError:
-                    self.Controler.CommonMethod.CreateErrorDialog('You can input only hex, dec value')
+                    self.Controler.CommonMethod.CreateErrorDialog(_('You can input only hex, dec value'))
 
 
 # -------------------------------------------------------------------------------
@@ -925,7 +925,7 @@
                         self.Controler.CommonMethod.SiiData = self.SiiBinary
                         self.SetEEPROMData()
                     except Exception:
-                        self.Controler.CommonMethod.CreateErrorDialog('The file does not exist!')
+                        self.Controler.CommonMethod.CreateErrorDialog(_('The file does not exist!'))
                         dialog.Destroy()
 
     def ReadFromEEPROM(self, event):
@@ -1317,7 +1317,7 @@
                 self.SiiGrid.SetValue(self.HexCode)
                 self.SiiGrid.Update()
             except Exception:
-                self.Controler.CommonMethod.CreateErrorDialog('The file does not exist!')
+                self.Controler.CommonMethod.CreateErrorDialog(_('The file does not exist!'))
 
         dialog.Destroy()
 
@@ -1961,8 +1961,8 @@
             """
         # user can enter a value in case that user double-clicked 'Dec' or 'Hex' value.
         if event.GetCol() == 1 or event.GetCol() == 2:
-            dlg = wx.TextEntryDialog(self, "Enter hex(0xnnnn) or dec(n) value",
-                                     "Register Modify Dialog", style=wx.OK | wx.CANCEL)
+            dlg = wx.TextEntryDialog(self, _("Enter hex(0xnnnn) or dec(n) value"),
+                                     _("Register Modify Dialog"), style=wx.OK | wx.CANCEL)
 
             # Setting value in initial dialog value
             start_value = self.GetCellValue(event.GetRow(), event.GetCol())
@@ -1996,10 +1996,10 @@
                         self.SetCellValue(event.GetRow(), 3, char_data)
 
                     else:
-                        self.Controler.CommonMethod.CreateErrorDialog('You can\'t modify it. This register is read-only or it\'s not connected.')
+                        self.Controler.CommonMethod.CreateErrorDialog(_('You can\'t modify it. This register is read-only or it\'s not connected.'))
 
                 except ValueError:
-                    self.Controler.CommonMethod.CreateErrorDialog('You entered wrong value. You can enter dec or hex value only.')
+                    self.Controler.CommonMethod.CreateErrorDialog(_('You entered wrong value. You can enter dec or hex value only.'))
 
 
 # -------------------------------------------------------------------------------
@@ -2157,4 +2157,4 @@
                     else:
                         self.TextCtrl[key].SetValue(self.MasterState[key][0])
         else:
-            self.Controler.CommonMethod.CreateErrorDialog('PLC not connected!')
+            self.Controler.CommonMethod.CreateErrorDialog(_('PLC not connected!'))
--- a/etherlab/EthercatMaster.py	Wed Oct 03 12:07:56 2018 +0300
+++ b/etherlab/EthercatMaster.py	Wed Oct 03 12:43:35 2018 +0300
@@ -294,12 +294,12 @@
         return "Ethercat"
 
     def GetContextualMenuItems(self):
-        return [("Add Ethercat Slave", "Add Ethercat Slave to Master", self.OnAddEthercatSlave)]
+        return [(_("Add Ethercat Slave"), _("Add Ethercat Slave to Master"), self.OnAddEthercatSlave)]
 
     def OnAddEthercatSlave(self, event):
         app_frame = self.GetCTRoot().AppFrame
         dialog = BrowseValuesLibraryDialog(app_frame,
-                                           "Ethercat Slave Type",
+                                           _("Ethercat Slave Type"),
                                            self.GetSlaveTypesLibrary())
         if dialog.ShowModal() == wx.ID_OK:
             type_infos = dialog.GetValueInfos()
@@ -460,7 +460,7 @@
         if execute:
             error, returnVal = self.RemoteExec(SCAN_COMMAND, returnVal=None)
             if error != 0:
-                dialog = wx.MessageDialog(app_frame, returnVal, "Error", wx.OK | wx.ICON_ERROR)
+                dialog = wx.MessageDialog(app_frame, returnVal, _("Error"), wx.OK | wx.ICON_ERROR)
                 dialog.ShowModal()
                 dialog.Destroy()
             elif returnVal is not None: