Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10798/spambayes

Modified Files:
        i18n.py 
Log Message:
Get things working when we are running frozen.

Basically this handles the move where the languages directory became a 
subpackage
 of spambayes.

Index: i18n.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/i18n.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** i18n.py     20 Jan 2005 03:49:33 -0000      1.3
--- i18n.py     7 Apr 2005 04:19:45 -0000       1.4
***************
*** 30,63 ****
  ## Set language environment for gettext and for dynamic load of dialogs.
  ##
! ## Our directory layout is:
  ##   spambayes
! ##       spambayes
! ##           i18n.py             <--- this file
! ##       languages               <--- the directory for lang packs
  ##           es                  <-- generic language data
! ##               DIALOGS
! ##               LC_MESSAGES
! ##               __init__.py     <-- resourcepackage __init__.py
! ##              ui.html          <-- web interface translation
  ##           es_ES               <-- specific language/country data.
! ##               DIALOGS         <-- resource dialogs
! ##               LC_MESSAGES     <-- gettext messages files
! ##               __init__.py     <-- resourcepackage __init__.py
! ##              ui.html          <-- web interface translation
  ##           zn
  ##           zn_TW
- ##       Outlook2000
- ##       utilities
  ##       ..etc..
  
  
  class LanguageManager:
!     def __init__(self, directory=os.path.dirname(__file__)):
!         """Initialisation.
! 
!         'directory' is the parent directory of the 'languages'
!         directory.  It defaults to the directory of this module."""
          self.current_langs_codes = []
-         self.local_dir = os.path.join(directory, "..", "languages")
          self._sys_path_modifications = []
  
--- 30,102 ----
  ## Set language environment for gettext and for dynamic load of dialogs.
  ##
! ## Our directory layout with source is:
  ##   spambayes
! ##       spambayes (or spambayes.modules with the binary)
! ##           i18n.py                 <-- this file
! ##           languages               <-- the directory for lang packs
! ##               es                  <-- generic language data
! ##                   DIALOGS
! ##                   LC_MESSAGES     <-- gettext message files
! ##                   __init__.py     <-- resourcepackage __init__.py
! ##                  ui.html          <-- web interface translation
! ##               es_ES               <-- specific language/country data.
! ##                   DIALOGS         <-- resource dialogs
! ##                   LC_MESSAGES     <-- gettext message files
! ##                   __init__.py     <-- resourcepackage __init__.py
! ##                  ui.html          <-- web interface translation
! ##               zn
! ##               zn_TW
! ##       Outlook2000
! ##       utilities
! ##       ..etc..
! ##
! ## Our directory layout with the binaries is:
! ##   lib
! ##       spambayes.modules
! ##           i18n.py                 <-- this file
! ##           languages               <-- the directory for lang packs
! ##               es                  <-- generic language data
! ##                   DIALOGS
! ##                   __init__.py     <-- resourcepackage __init__.py
! ##                  ui.html          <-- web interface translation
! ##               es_ES               <-- specific language/country data.
! ##                   DIALOGS         <-- resource dialogs
! ##                   __init__.py     <-- resourcepackage __init__.py
! ##                  ui.html          <-- web interface translation
! ##               zn
! ##               zn_TW
! ##       languages
  ##           es                  <-- generic language data
! ##               LC_MESSAGES     <-- gettext message files
  ##           es_ES               <-- specific language/country data.
! ##               LC_MESSAGES     <-- gettext message files
  ##           zn
  ##           zn_TW
  ##       ..etc..
+ ##
+ ## A distutils installation will not currently work.  I don't know
+ ## where to put the .mo files, so setup.py ignores them.
  
+ if hasattr(sys, "frozen"):
+     # LC_MESSAGES are harder to find.
+     if sys.frozen == "dll":
+         # Outlook
+         import win32api
+         this_filename = win32api.GetModuleFileName(sys.frozendllhandle)
+     else:
+         # Not Outlook
+         this_filename = __file__
+     LC_DIR = os.path.dirname(os.path.dirname(this_filename))
+ else:
+     try:
+         this_filename = os.path.abspath(__file__)
+     except NameError: # no __file__ - means Py2.2 and __name__=='__main__'
+         this_filename = os.path.abspath(sys.argv[0])
+     LC_DIR = os.path.dirname(this_filename)
+     
  
  class LanguageManager:
!     def __init__(self):
          self.current_langs_codes = []
          self._sys_path_modifications = []
  
***************
*** 99,105 ****
          current language."""
          for language in self.current_langs_codes:
!             moduleName = 'languages.%s.i18n_ui_html' % (language, )
              try:
!                 module = __import__(moduleName, {}, {}, ('languages',
                                                           language))
              except ImportError:
--- 138,144 ----
          current language."""
          for language in self.current_langs_codes:
!             moduleName = 'spambayes.languages.%s.i18n_ui_html' % (language, )
              try:
!                 module = __import__(moduleName, {}, {}, 
('spambayes.languages',
                                                           language))
              except ImportError:
***************
*** 115,119 ****
      def _install_gettext(self):
          """Set the gettext specific environment."""
!         lang = translation("messages", self.local_dir,
                              self.current_langs_codes, fallback=True)
          lang.install()
--- 154,158 ----
      def _install_gettext(self):
          """Set the gettext specific environment."""
!         lang = translation("messages", LC_DIR,
                              self.current_langs_codes, fallback=True)
          lang.install()
***************
*** 127,134 ****
          self._clear_syspath()
          for lcode in self.current_langs_codes:
!             code_and_country = os.path.join(self.local_dir, lcode,
                                              'DIALOGS')
!             code_only = os.path.join(self.local_dir, lcode.split("_")[0],
!                                      'DIALOGS')
              if code_and_country not in sys.path:
                  sys.path.append(code_and_country)
--- 166,172 ----
          self._clear_syspath()
          for lcode in self.current_langs_codes:
!             code_and_country = os.path.join(LC_DIR, "languages", lcode,
                                              'DIALOGS')
!             code_only = os.path.join(LC_DIR, lcode.split("_")[0], 'DIALOGS')
              if code_and_country not in sys.path:
                  sys.path.append(code_and_country)

_______________________________________________
Spambayes-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/spambayes-checkins

Reply via email to