# HG changeset patch # User laurent # Date 1347035325 -7200 # Node ID e4f24593a758e84c6361d77ea662ba023058ff28 # Parent 5743cbdff6696b6971d34fbd7b1134769b760801 Adding support for extending internationalization to extensions diff -r 5743cbdff669 -r e4f24593a758 Beremiz.py --- a/Beremiz.py Fri Sep 07 16:45:55 2012 +0200 +++ b/Beremiz.py Fri Sep 07 18:28:45 2012 +0200 @@ -110,45 +110,24 @@ splash.SetText(text=updateinfo) wx.Yield() -# Import module for internationalization -import gettext - -# Get folder containing translation files -localedir = os.path.join(CWD,"locale") -# Get the default language -langid = wx.LANGUAGE_DEFAULT -# Define translation domain (name of translation files) -domain = "Beremiz" - -# Define locale for wx -loc = __builtin__.__dict__.get('loc', None) -if loc is None: - test_loc = wx.Locale(langid) - test_loc.AddCatalogLookupPathPrefix(localedir) - if test_loc.AddCatalog(domain): - loc = wx.Locale(langid) - else: - loc = wx.Locale(wx.LANGUAGE_ENGLISH) - __builtin__.__dict__['loc'] = loc -# Define location for searching translation files -loc.AddCatalogLookupPathPrefix(localedir) -# Define locale domain -loc.AddCatalog(domain) - -def unicode_translation(message): - return wx.GetTranslation(message).encode("utf-8") +from util.TranslationCatalogs import AddCatalog, locale +from util.BitmapLibrary import AddBitmapFolder, GetBitmap + +AddCatalog(os.path.join(CWD, "locale")) +AddBitmapFolder(os.path.join(CWD, "images")) if __name__ == '__main__': - __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation - -from util.BitmapLibrary import AddBitmapFolder, GetBitmap -AddBitmapFolder(os.path.join(CWD, "images")) - -if __name__ == '__main__': + # Import module for internationalization + import gettext + + __builtin__.__dict__['loc'] = locale + __builtin__.__dict__['_'] = wx.GetTranslation + # Load extensions for extfilename in extensions: extension_folder = os.path.split(os.path.realpath(extfilename))[0] sys.path.append(extension_folder) + AddCatalog(os.path.join(extension_folder, "locale")) AddBitmapFolder(os.path.join(extension_folder, "images")) execfile(extfilename, locals()) diff -r 5743cbdff669 -r e4f24593a758 PLCOpenEditor.py --- a/PLCOpenEditor.py Fri Sep 07 16:45:55 2012 +0200 +++ b/PLCOpenEditor.py Fri Sep 07 18:28:45 2012 +0200 @@ -27,11 +27,6 @@ CWD = os.path.split(os.path.realpath(__file__))[0] -from util.BitmapLibrary import AddBitmapFolder, GetBitmap -AddBitmapFolder(os.path.join(CWD, "images")) - -from docutil import * - __version__ = "$Revision: 1.130 $" if __name__ == '__main__': @@ -67,33 +62,20 @@ # Windows) app = wx.PySimpleApp() -# Import module for internationalization -import gettext -import __builtin__ - -# Get folder containing translation files -localedir = os.path.join(CWD,"locale") -# Get the default language -langid = wx.LANGUAGE_DEFAULT -# Define translation domain (name of translation files) -domain = "Beremiz" - -# Define locale for wx -loc = __builtin__.__dict__.get('loc', None) -if loc is None: - test_loc = wx.Locale(langid) - test_loc.AddCatalogLookupPathPrefix(localedir) - if test_loc.AddCatalog(domain): - loc = wx.Locale(langid) - else: - loc = wx.Locale(wx.LANGUAGE_ENGLISH) - __builtin__.__dict__['loc'] = loc -# Define location for searching translation files -loc.AddCatalogLookupPathPrefix(localedir) -# Define locale domain -loc.AddCatalog(domain) +from docutil import * + +from util.TranslationCatalogs import AddCatalog, locale +from util.BitmapLibrary import AddBitmapFolder, GetBitmap + +AddCatalog(os.path.join(CWD, "locale")) +AddBitmapFolder(os.path.join(CWD, "images")) if __name__ == '__main__': + # Import module for internationalization + import gettext + import __builtin__ + + __builtin__.__dict__['loc'] = locale __builtin__.__dict__['_'] = wx.GetTranslation from IDEFrame import IDEFrame, AppendMenu diff -r 5743cbdff669 -r e4f24593a758 ProjectController.py --- a/ProjectController.py Fri Sep 07 16:45:55 2012 +0200 +++ b/ProjectController.py Fri Sep 07 18:28:45 2012 +0200 @@ -14,12 +14,13 @@ import targets import connectors -from util.misc import CheckPathPerm, GetClassImporter, IECCodeViewer +from util.misc import CheckPathPerm, GetClassImporter from util.MiniTextControler import MiniTextControler from util.ProcessLogger import ProcessLogger from util.BitmapLibrary import GetBitmap from editors.FileManagementPanel import FileManagementPanel from editors.ProjectNodeEditor import ProjectNodeEditor +from editors.IECCodeViewer import IECCodeViewer from dialogs import DiscoveryDialog from PLCControler import PLCControler from plcopen.structures import IEC_KEYWORDS @@ -936,7 +937,7 @@ _ProjectFilesView = None def _OpenProjectFiles(self): - self._OpenView("Project files") + self._OpenView("Project Files") _FileEditors = {} def _OpenFileEditor(self, filepath): @@ -979,7 +980,7 @@ return self._IECRawCodeView - elif name == "Project files": + elif name == "Project Files": if self._ProjectFilesView is None: self._ProjectFilesView = FileManagementPanel(self.AppFrame.TabsOpened, self, name, self._getProjectFilesPath(), True) diff -r 5743cbdff669 -r e4f24593a758 canfestival/canfestival.py --- a/canfestival/canfestival.py Fri Sep 07 16:45:55 2012 +0200 +++ b/canfestival/canfestival.py Fri Sep 07 18:28:45 2012 +0200 @@ -1,8 +1,11 @@ import os, sys + base_folder = os.path.split(sys.path[0])[0] CanFestivalPath = os.path.join(base_folder, "CanFestival-3") sys.path.append(os.path.join(CanFestivalPath, "objdictgen")) +import wx + from nodelist import NodeList from nodemanager import NodeManager import config_utils, gen_cfile, eds_utils @@ -11,7 +14,6 @@ import canfestival_config as local_canfestival_config from ConfigTreeNode import ConfigTreeNode from commondialogs import CreateNodeDialog -import wx from SlaveEditor import SlaveEditor, MasterViewer from NetworkEditor import NetworkEditor @@ -20,6 +22,9 @@ from gnosis.xml.pickle.util import setParanoia setParanoia(0) +from util.TranslationCatalogs import AddCatalog +AddCatalog(os.path.join(CanFestivalPath, "objdictgen", "locale")) + if wx.Platform == '__WXMSW__': DEFAULT_SETTINGS = { "CAN_Driver": "can_tcp_win32", diff -r 5743cbdff669 -r e4f24593a758 dialogs/ProjectDialog.py --- a/dialogs/ProjectDialog.py Fri Sep 07 16:45:55 2012 +0200 +++ b/dialogs/ProjectDialog.py Fri Sep 07 18:28:45 2012 +0200 @@ -24,7 +24,7 @@ import wx -from controls import ProjectPropertiesPanel +from controls.ProjectPropertiesPanel import ProjectPropertiesPanel class ProjectDialog(wx.Dialog): diff -r 5743cbdff669 -r e4f24593a758 editors/FileManagementPanel.py --- a/editors/FileManagementPanel.py Fri Sep 07 16:45:55 2012 +0200 +++ b/editors/FileManagementPanel.py Fri Sep 07 18:28:45 2012 +0200 @@ -262,7 +262,7 @@ left_sizer = wx.BoxSizer(wx.VERTICAL) main_sizer.AddSizer(left_sizer, 1, border=5, flag=wx.GROW|wx.ALL) - managed_dir_label = wx.StaticText(self.Editor, label=self.TagName + ":") + managed_dir_label = wx.StaticText(self.Editor, label=_(self.TagName) + ":") left_sizer.AddWindow(managed_dir_label, border=5, flag=wx.GROW|wx.BOTTOM) self.ManagedDir = FolderTree(self.Editor, self.Folder, FILTER) @@ -333,7 +333,7 @@ self.Controler.OnCloseEditor(self) def GetTitle(self): - return self.TagName + return _(self.TagName) def SetEditableFileExtensions(self, extensions): self.EditableFileExtensions = extensions diff -r 5743cbdff669 -r e4f24593a758 editors/IECCodeViewer.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/editors/IECCodeViewer.py Fri Sep 07 18:28:45 2012 +0200 @@ -0,0 +1,9 @@ + +from editors.TextViewer import TextViewer + +class IECCodeViewer(TextViewer): + + def __del__(self): + TextViewer.__del__(self) + if getattr(self, "_OnClose"): + self._OnClose(self) \ No newline at end of file diff -r 5743cbdff669 -r e4f24593a758 editors/ProjectNodeEditor.py --- a/editors/ProjectNodeEditor.py Fri Sep 07 16:45:55 2012 +0200 +++ b/editors/ProjectNodeEditor.py Fri Sep 07 18:28:45 2012 +0200 @@ -59,7 +59,7 @@ return self.Controler.CTNName() def GetTitle(self): - fullname = self.Controler.CTNName() + fullname = _(self.Controler.CTNName()) if self.Controler.CTNTestModified(): return "~%s~" % fullname return fullname diff -r 5743cbdff669 -r e4f24593a758 util/BitmapLibrary.py --- a/util/BitmapLibrary.py Fri Sep 07 16:45:55 2012 +0200 +++ b/util/BitmapLibrary.py Fri Sep 07 18:28:45 2012 +0200 @@ -38,7 +38,7 @@ #------------------------------------------------------------------------------- def AddBitmapFolder(path): - if path not in BitmapFolders: + if os.path.exists(path) and os.path.isdir(path) and path not in BitmapFolders: BitmapFolders.append(path) def SearchBitmap(bmp_name): diff -r 5743cbdff669 -r e4f24593a758 util/TranslationCatalogs.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util/TranslationCatalogs.py Fri Sep 07 18:28:45 2012 +0200 @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os + +import wx + +# Get the default language +langid = wx.LANGUAGE_FRENCH + +# Define locale for wx +locale = wx.Locale(langid) + +def GetDomain(path): + for name in os.listdir(path): + filepath = os.path.join(path, name) + basename, fileext = os.path.splitext(name) + if os.path.isdir(filepath): + result = GetDomain(filepath) + if result is not None: + return result + elif fileext == ".mo": + return basename + return None + +def AddCatalog(locale_dir): + if os.path.exists(locale_dir) and os.path.isdir(locale_dir): + domain = GetDomain(locale_dir) + if domain is not None: + locale.AddCatalogLookupPathPrefix(locale_dir) + locale.AddCatalog(domain) diff -r 5743cbdff669 -r e4f24593a758 util/misc.py --- a/util/misc.py Fri Sep 07 16:45:55 2012 +0200 +++ b/util/misc.py Fri Sep 07 18:28:45 2012 +0200 @@ -4,8 +4,6 @@ import os,sys -from editors.TextViewer import TextViewer - # helper func to check path write permission def CheckPathPerm(path): if path is None or not os.path.isdir(path): @@ -24,10 +22,3 @@ return fac else: return classpath - -class IECCodeViewer(TextViewer): - - def __del__(self): - TextViewer.__del__(self) - if getattr(self, "_OnClose"): - self._OnClose(self) \ No newline at end of file