[Zope3-checkins] SVN: Zope3/trunk/ Added support for different text orientations in locale data.

Philipp von Weitershausen philikon at philikon.de
Fri Jun 10 19:57:01 EDT 2005


Log message for revision 30750:
  Added support for different text orientations in locale data.
  This is typically used for loading different webpage
  stylesheets when the locale uses right-to-left characters.
  
  The orientation of lines is typically accessed through
  ``request.locale.orientation.lines``, the orientation of
  characters within a line through
  ``request.locale.orientation.characters``.  Both variables can
   hold either value of 'left-to-right', 'right-to-left',
  'top-to-bottom', 'bottom-to-top'.
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/i18n/interfaces/locales.py
  U   Zope3/trunk/src/zope/i18n/locales/__init__.py
  U   Zope3/trunk/src/zope/i18n/locales/xmlfactory.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-06-10 23:56:17 UTC (rev 30749)
+++ Zope3/trunk/doc/CHANGES.txt	2005-06-10 23:57:01 UTC (rev 30750)
@@ -6,7 +6,7 @@
 
   For information on future releases, see ROADMAP.txt.
 
-  Some future release (Zope X3 3.1.0)
+  Some future release (Zope 3.1.0)
 
     New features
 
@@ -379,6 +379,17 @@
         like unicode strings with respect to security proxying.  This
         implementation will replace the old one in upcoming versions.
 
+      - Added support for different text orientations in locale data.
+        This is typically used for loading different webpage
+        stylesheets when the locale uses right-to-left characters.
+
+        The orientation of lines is typically accessed through
+        ``request.locale.orientation.lines``, the orientation of
+        characters within a line through
+        ``request.locale.orientation.characters``.  Both variables can
+        hold either value of 'left-to-right', 'right-to-left',
+        'top-to-bottom', 'bottom-to-top'.
+
     Restructuring
 
       - Applied changes suggested in issue 339: Improvements to generated forms

Modified: Zope3/trunk/src/zope/i18n/interfaces/locales.py
===================================================================
--- Zope3/trunk/src/zope/i18n/interfaces/locales.py	2005-06-10 23:56:17 UTC (rev 30749)
+++ Zope3/trunk/src/zope/i18n/interfaces/locales.py	2005-06-10 23:57:01 UTC (rev 30750)
@@ -498,7 +498,23 @@
     def getDefaultCurrency():
         """Get the default currency."""
 
+_orientations = [u"left-to-right", u"right-to-left",
+                 u"top-to-bottom", u"bottom-to-top"]
+class ILocaleOrientation(Interface):
+    """Information about the orientation of text."""
 
+    characters = Choice(
+        title = u"Orientation of characters",
+        values = _orientations,
+        default = u"left-to-right"
+        )
+
+    lines = Choice(
+        title = u"Orientation of characters",
+        values = _orientations,
+        default = u"top-to-bottom"
+        )
+    
 class ILocale(Interface):
     """This class contains all important information about the locale.
 
@@ -530,6 +546,10 @@
         title = u"Numbers",
         description = u"ILocaleNumbers object that contains number data.")
 
+    orientation = Field(
+        title = u"Orientation",
+        description = u"ILocaleOrientation with text orientation info.")
+
     delimiters = Dict(
         title=u"Delimiters",
         description = u"Contains various Currency data.",

Modified: Zope3/trunk/src/zope/i18n/locales/__init__.py
===================================================================
--- Zope3/trunk/src/zope/i18n/locales/__init__.py	2005-06-10 23:56:17 UTC (rev 30749)
+++ Zope3/trunk/src/zope/i18n/locales/__init__.py	2005-06-10 23:57:01 UTC (rev 30750)
@@ -26,6 +26,7 @@
 from zope.i18n.interfaces.locales import ILocaleTimeZone, ILocaleCalendar
 from zope.i18n.interfaces.locales import ILocaleCurrency, ILocaleNumbers
 from zope.i18n.interfaces.locales import ILocaleFormat, ILocaleFormatLength
+from zope.i18n.interfaces.locales import ILocaleOrientation
 from zope.i18n.format import NumberFormat, DateTimeFormat
 from zope.i18n.locales.inheritance import \
      AttributeInheritance, InheritingDictionary, NoParentException
@@ -608,6 +609,11 @@
         return NumberFormat(format.pattern, self.symbols)
 
 
+class LocaleOrientation(AttributeInheritance):
+    """Implementation of ILocaleOrientation
+    """
+    implements(ILocaleOrientation)
+
 class Locale(AttributeInheritance):
     """Implementation of the ILocale interface."""
     implements(ILocale)

Modified: Zope3/trunk/src/zope/i18n/locales/xmlfactory.py
===================================================================
--- Zope3/trunk/src/zope/i18n/locales/xmlfactory.py	2005-06-10 23:56:17 UTC (rev 30749)
+++ Zope3/trunk/src/zope/i18n/locales/xmlfactory.py	2005-06-10 23:57:01 UTC (rev 30750)
@@ -21,6 +21,7 @@
 from zope.i18n.locales import LocaleVersion, LocaleIdentity, LocaleTimeZone
 from zope.i18n.locales import LocaleCalendar, LocaleCurrency, LocaleNumbers
 from zope.i18n.locales import LocaleFormat, LocaleFormatLength, dayMapping
+from zope.i18n.locales import LocaleOrientation
 from zope.i18n.locales.inheritance import InheritingDictionary
 
 class LocaleFactory(object):
@@ -1138,6 +1139,36 @@
         return delimiters
 
 
+    def _extractOrientation(self):
+        """Extract orientation information.
+
+          >>> factory = LocaleFactory(None)
+          >>> from xml.dom.minidom import parseString
+          >>> xml = u'''
+          ... <ldml>
+          ...   <layout>
+          ...     <orientation lines="bottom-to-top" characters="right-to-left" />
+          ...   </layout>
+          ... </ldml>'''
+          >>> dom = parseString(xml)
+          >>> factory._data = parseString(xml).documentElement
+          >>> orientation = factory._extractOrientation()
+          >>> orientation.lines
+          u'bottom-to-top'
+          >>> orientation.characters
+          u'right-to-left'
+        """
+        orientation_nodes = self._data.getElementsByTagName('orientation')
+        if not orientation_nodes:
+            return
+        orientation = LocaleOrientation()
+        for name in (u'characters', u'lines'):
+            value = orientation_nodes[0].getAttribute(name)
+            if value:
+                setattr(orientation, name, value)
+        return orientation
+
+
     def __call__(self):
         """Create the Locale."""
         locale = Locale(self._extractIdentity())
@@ -1157,11 +1188,14 @@
         delimiters = self._extractDelimiters()
         if delimiters is not None:
             locale.delimiters = delimiters
+
+        orientation = self._extractOrientation()
+        if orientation is not None:
+            locale.orientation = orientation
         
         # Unmapped:
         #
         #   - <characters>
-        #   - <layout>
         #   - <measurement>
         #   - <collations>, <collation>
 



More information about the Zope3-Checkins mailing list