From: Christian H. <ti...@us...> - 2004-09-05 19:33:52
|
Update of /cvsroot/collective/PlacelessTranslationService In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20442 Modified Files: GettextMessageCatalog.py PlacelessTranslationService.py Log Message: Added support for RTL to PTS Index: PlacelessTranslationService.py =================================================================== RCS file: /cvsroot/collective/PlacelessTranslationService/PlacelessTranslationService.py,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- PlacelessTranslationService.py 15 Jul 2004 09:19:19 -0000 1.38 +++ PlacelessTranslationService.py 5 Sep 2004 19:33:38 -0000 1.39 @@ -30,7 +30,11 @@ from OFS.Folder import Folder from ZPublisher.HTTPRequest import HTTPRequest -from GettextMessageCatalog import BrokenMessageCatalog, GettextMessageCatalog, translationRegistry, getMessage +from GettextMessageCatalog import BrokenMessageCatalog +from GettextMessageCatalog import GettextMessageCatalog +from GettextMessageCatalog import translationRegistry +from GettextMessageCatalog import rtlRegistry +from GettextMessageCatalog import getMessage from Negotiator import negotiator from Domain import Domain from utils import log, Registry, INFO, BLATHER, PROBLEM @@ -425,7 +429,7 @@ # cache catalog names to speed up because this method is called # for every msgid - cache_name = 'PTS_catalog_names_%s_%s' % (domain, target_language or 'none') + cache_name = '_pts_catalog_names_%s_%s' % (domain, target_language or 'none') cached_catalog_names = context.get(cache_name, None) if cached_catalog_names: return [translationRegistry[name] for name in cached_catalog_names] @@ -461,7 +465,14 @@ # in the request. It may cause reference circles and cause memory leaks context.set(cache_name, catalog_names) - return [translationRegistry[name] for name in catalog_names ] + # test for right to left language + context.set('PTS_Is_RTL', False) + for name in catalog_names: + if rtlRegistry.get(name): + context.set('PTS_Is_RTL', True) + break + + return [translationRegistry[name] for name in catalog_names] security.declarePrivate('setLanguageFallbacks') def setLanguageFallbacks(self, fallbacks=None): Index: GettextMessageCatalog.py =================================================================== RCS file: /cvsroot/collective/PlacelessTranslationService/GettextMessageCatalog.py,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- GettextMessageCatalog.py 18 Jul 2004 18:33:07 -0000 1.25 +++ GettextMessageCatalog.py 5 Sep 2004 19:33:38 -0000 1.26 @@ -68,6 +68,8 @@ translationRegistry = Registry() registerTranslation = translationRegistry.register +rtlRegistry = Registry() +registerRTL = rtlRegistry.register def getMessage(catalog, id, orig_text=None): """get message from catalog @@ -234,7 +236,19 @@ self.preferred_encodings = tro._info.get('preferred-encodings', '').split() self.name = unicode(tro._info.get('language-name', ''), tro._charset) self.default_zope_data_encoding = tro._charset + translationRegistry[self.getId()] = self._v_tro = tro + + # right to left support + is_rtl = tro._info.get('X-Is-RTL', 'no').strip().lower() + if is_rtl in ('yes', 'y', 'true', '1'): + self._is_rtl = True + elif is_rtl in ('no', 'n', 'false', '0'): + self._is_rtl = False + else: + raise ValueError, 'Unsupported value for X-Is-RTL' % is_rtl + rtlRegistry[self.getId()] = self.isRTL() + missingFileName = self._pofile[:-3] + '.missing' if os.access(missingFileName, os.W_OK): tro.add_fallback(MissingIds(missingFileName, self._v_tro._charset)) @@ -317,6 +331,11 @@ """ self._prepareTranslations() return self._v_tro._info.get(name, None) + + def isRTL(self): + """ + """ + return self._is_rtl security.declareProtected(view_management_screens, 'Title') def Title(self): |