opental-checkins
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[OpenTAL-checkins] opental/PlacelessTranslationService PlacelessTr...


From: Fernando Lalo Martins
Subject: [OpenTAL-checkins] opental/PlacelessTranslationService PlacelessTr...
Date: Tue, 29 Jul 2003 18:31:28 -0400

CVSROOT:        /cvsroot/opental
Module name:    opental
Branch:         
Changes by:     Fernando Lalo Martins <address@hidden>  03/07/29 18:31:28

Modified files:
        PlacelessTranslationService: PlacelessTranslationService.py 
                                     __init__.py 

Log message:
        now we look for i18n directories inside all products

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/PlacelessTranslationService/PlacelessTranslationService.py.diff?tr1=1.23&tr2=1.24&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/PlacelessTranslationService/__init__.py.diff?tr1=1.11&tr2=1.12&r1=text&r2=text

Patches:
Index: opental/PlacelessTranslationService/PlacelessTranslationService.py
diff -u opental/PlacelessTranslationService/PlacelessTranslationService.py:1.23 
opental/PlacelessTranslationService/PlacelessTranslationService.py:1.24
--- opental/PlacelessTranslationService/PlacelessTranslationService.py:1.23     
Tue Jul 29 17:33:39 2003
+++ opental/PlacelessTranslationService/PlacelessTranslationService.py  Tue Jul 
29 18:31:28 2003
@@ -17,10 +17,10 @@
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
 """Placeless Translation Service for providing I18n to file-based code.
 
-$Id: PlacelessTranslationService.py,v 1.23 2003/07/29 21:33:39 lalo Exp $
+$Id: PlacelessTranslationService.py,v 1.24 2003/07/29 22:31:28 lalo Exp $
 """
 
-import sys, re, zLOG, Globals
+import sys, re, zLOG, Globals, fnmatch
 from AccessControl import ClassSecurityInfo
 from OFS.Folder import Folder
 from types import DictType, StringType, UnicodeType
@@ -32,6 +32,13 @@
 except:
     def XML(v):
         return str(v)
+try:
+    True
+except NameError:
+    True=1
+    False=0
+_marker = []
+
 
 def log(msg, severity=zLOG.INFO, detail='', error=None):
     if type(msg) is UnicodeType:
@@ -66,7 +73,7 @@
     icon = 'misc_/PlacelessTranslationService/PlacelessTranslationService.png'
     # major, minor, patchlevel, internal
     # internal is always 0 on releases; if you hack this internally, increment 
it
-    _class_version = (0, 4, 0, 4)
+    _class_version = (0, 5, 0, 0)
     all_meta_types = ()
 
     security = ClassSecurityInfo()
@@ -101,6 +108,29 @@
                 pass
         self._p_changed = 1
 
+    def _load_dir(self, basepath):
+        from GettextMessageCatalog import GettextMessageCatalog
+        log('looking into ' + basepath, zLOG.BLATHER)
+        if not os.path.isdir(basepath):
+            log('it does not exist', zLOG.BLATHER)
+            return
+        names = fnmatch.filter(os.listdir(basepath), '*.mo')
+        if not names:
+            log('nothing found', zLOG.BLATHER)
+            return
+        for name in names:
+            ob = self._getOb(name, _marker)
+            try:
+                if ob is _marker:
+                    
self.addCatalog(GettextMessageCatalog(os.path.join(basepath, name)))
+                else:
+                    self.reloadCatalog(ob)
+            except ValueError:
+                log('Message Catalog has no metadata', zLOG.PROBLEM, name, 
sys.exc_info())
+            except:
+                log('Message Catalog has errors', zLOG.PROBLEM, name, 
sys.exc_info())
+        log('Initialized:', detail = repr(names) + (' from %s\n' % basepath))
+
     def manage_renameObject(self, id, new_id, REQUEST=None):
         "wrap manage_renameObject to deal with registration"
         catalog = self._getOb(id)
@@ -125,7 +155,7 @@
             self._delObject(catalog.id)
         except:
             pass
-        self._setObject(catalog.id, catalog, set_owner=0)
+        self._setObject(catalog.id, catalog, set_owner=False)
         log('adding %s: %s' % (catalog.id, catalog.title))
         self._registerMessageCatalog(catalog)
 
Index: opental/PlacelessTranslationService/__init__.py
diff -u opental/PlacelessTranslationService/__init__.py:1.11 
opental/PlacelessTranslationService/__init__.py:1.12
--- opental/PlacelessTranslationService/__init__.py:1.11        Wed Mar 26 
07:54:35 2003
+++ opental/PlacelessTranslationService/__init__.py     Tue Jul 29 18:31:28 2003
@@ -16,12 +16,12 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
 __version__ = '''
-$Id: __init__.py,v 1.11 2003/03/26 12:54:35 lalo Exp $
+$Id: __init__.py,v 1.12 2003/07/29 22:31:28 lalo Exp $
 '''.strip()
 
+from OFS.Application import get_products
 from AccessControl import ModuleSecurityInfo, allow_module, allow_class, 
allow_type
 from PlacelessTranslationService import PlacelessTranslationService, log
-from GettextMessageCatalog import GettextMessageCatalog
 from Products.PageTemplates.GlobalTranslationService import 
setGlobalTranslationService
 import os, fnmatch, zLOG, sys, Zope, Globals
 
@@ -57,8 +57,6 @@
 security.declarePublic('getLanguages')
 security.declarePublic('getLanguageName')
 
-_marker = []
-
 def make_translation_service(cp):
     from Products import PlacelessTranslationService as pkg
     # default (gettext) translation service
@@ -75,7 +73,7 @@
         make_translation_service(cp)
     pkg.translation_service = getattr(cp, cp_id)
 
-    instance_version = getattr(translation_service, '_instance_version', (0, 
4, 0, 0))
+    instance_version = getattr(translation_service, '_instance_version', (0, 
5, 0, 0))
     if instance_version < PlacelessTranslationService._class_version:
         log('outdated translation service found, recreating',
             detail = '(found %s.%s.%s.%s)\n' % instance_version)
@@ -92,24 +90,19 @@
     pkg.getLanguageName = translation_service.getLanguageName
     pkg.negotiate = translation_service.negotiate
 
-    # sweep the i18n directory
-    basepath = os.path.join(INSTANCE_HOME, 'i18n')
-    if os.path.isdir(basepath):
-        names = fnmatch.filter(os.listdir(basepath), '*.mo')
-        if not names:
-            log('no translations found!', zLOG.PROBLEM)
-        for name in names:
-            ob = ts_unwrapped._getOb(name, _marker)
-            try:
-                if ob is _marker:
-                    
translation_service.addCatalog(GettextMessageCatalog(os.path.join(basepath, 
name)))
-                else:
-                    translation_service.reloadCatalog(ob)
-            except ValueError:
-                log('Message Catalog has no metadata', zLOG.PROBLEM, name, 
sys.exc_info())
-            except:
-                log('Message Catalog has errors', zLOG.PROBLEM, name, 
sys.exc_info())
-        log('Initialized:', detail = repr(translation_service.objectIds()) + 
'\n')
+    log('products: %r' % get_products(), zLOG.BLATHER)
+    # sweep products
+    for prod in get_products():
+        # prod is a tuple in the form:
+        #(priority, dir_name, index, base_dir) for each Product directory
+        ts_unwrapped._load_dir(os.path.join(prod[3], prod[1], 'i18n'))
+
+    # sweep the i18n directory for local catalogs
+    ts_unwrapped._load_dir(os.path.join(INSTANCE_HOME, 'i18n'))
+
+    # didn't found any catalogs
+    if not ts_unwrapped.objectIds():
+        log('no translations found!', zLOG.PROBLEM)
 
     # notify anyone who needs it
     for function in notify_initialized:




reply via email to

[Prev in Thread] Current Thread [Next in Thread]