[Zope3-checkins] CVS: Zope3/src/zope/i18n/interfaces - __init__.py:1.1 locales.py:1.1

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Feb 5 17:52:24 EST 2004


Update of /cvs-repository/Zope3/src/zope/i18n/interfaces
In directory cvs.zope.org:/tmp/cvs-serv7674/src/zope/i18n/interfaces

Added Files:
	__init__.py locales.py 
Log Message:
ICU joined openi18n.org and developed a locale data XML standard called 
LDML. A result of this was that all locale files were changed to this new 
format. To stay up-to-date with the latest data, I converted the locale
parser to read the new format. While I was at it, I also changed the Locale
data structure a bit, since I wanted to keep the objects similar to the 
XML. Furthermore, the first time around I did not implement the inheritance
of object attributes and dictionaries correctly (I just faked it for the 
API calls), so I think I got it right this time. Finally I updated views 
and tests that relied on the old Locale API. Be aware that you might need
to change some of your product code as well. 


=== Added File Zope3/src/zope/i18n/interfaces/__init__.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Internationalization of content objects.

$Id: __init__.py,v 1.1 2004/02/05 22:52:22 srichter Exp $
"""
import re
from zope.interface import Interface, Attribute
from zope.schema import TextLine, Text, Int, Dict, Tuple, List
from zope.schema import Container, Datetime, Date, EnumeratedTextLine


class II18nAware(Interface):
    """Internationalization aware content object."""

    def getDefaultLanguage():
        """Return the default language."""

    def setDefaultLanguage(language):
        """Set the default language, which will be used if the language is not
        specified, or not available.
        """

    def getAvailableLanguages():
        """Find all the languages that are available."""


class IMessageCatalog(Interface):
    """A catalog (mapping) of message ids to message text strings.

    This interface provides a method for translating a message or message id,
    including text with interpolation.  The message catalog basically serves
    as a fairly simple mapping object.

    A single message catalog represents a specific language and domain.
    Therefore you will have the following constructor arguments:

    language -- The language of the returned messages.  This is a read-only
                attribute.

    domain -- The translation domain for these messages.  This is a read-only
              attribute.  See ITranslationService.

    When we refer to text here, we mean text that follows the standard Zope 3
    text representation.

    Note: The IReadMessageCatalog is the absolut minimal version required for
          the TranslationService to function.
    """

    def getMessage(msgid):
        """Get the appropriate text for the given message id.

        An exception is raised if the message id is not found.
        """

    def queryMessage(msgid, default=None):
        """Look for the appropriate text for the given message id.

        If the message id is not found, default is returned.
        """

    def getLanguage():
        """Return the language this message catalog is representing."""

    def getDomain():
        """Return the domain this message catalog is serving."""

    def getIdentifier():
        """Return a identifier for this message catalog. Note that this
        identifier does not have to be unique as several message catalog
        could serve the same domain and language.

        Also, there are no restrictions on the form of the identifier.
        """


class IGlobalMessageCatalog(IMessageCatalog):

    def reload():
        """Reload and parse .po file"""


class ITranslationService(Interface):
    """The Translation Service

    This interface provides methods for translating text, including text with
    interpolation.

    When we refer to text here, we mean text that follows the standard Zope 3
    text representation.

    Standard arguments in the methods described below:

        domain -- The domain is used to specify which translation to use.
                  Different products will often use a specific domain naming
                  translations supplied with the product.

                  A favorite example is: How do you translate "Sun"?  Is it
                  our star, the abbreviation of Sunday or the company?
                  Specifying the domain, such as "Stars" or "DaysOfWeek" will
                  solve this problem for us.

        msgid -- The id of the message that should be translated.  This may be
                 an implicit or an explicit message id.

        mapping -- The object to get the interpolation data from.

        target_language -- The language to translate to.

        context -- An object that provides contextual information for
                   determining client language preferences.  It must implement
                   or have an adapter that implements IUserPreferredLanguages.
                   It will be to determine the language to translate to if
                   target_language is not specified explicitly.

        Also note that language tags are defined by RFC 1766.
    """

    def translate(msgid, domain=None, mapping=None,
                  context=None, target_language=None,
                  default=None):
        """Return the translation for the message referred to by msgid.

        Return the default if no translation is found.

        However, the method does a little more than a vanilla translation.
        The method also looks for a possible language to translate to.
        After a translation it also replaces any $name variable variables
        inside the post-translation string.

        Note: The TranslationService interface does not support simplified
        translation methods, since it is totally hidden by ZPT and in
        Python you should use a Domain object, since it supports all
        the simplifications.
        """


class ITranslator(Interface):
    """A collaborative object which contains the domain, context, and locale.

    It is expected that object be constructed with enough information to find
    the domain, context, and target language.
    """

    def translate(msgid, mapping=None):
        """Translate the source msgid using the given mapping.

        See ITranslationService for details.
        """


class IMessageImportFilter(Interface):
    """The Import Filter for Translation Service Messages.

       Classes implementing this interface should usually be Adaptors, as
       they adapt the IEditableTranslationService interface."""


    def importMessages(domains, languages, file):
        """Import all messages that are defined in the specified domains and
           languages.

           Note that some implementations might limit to only one domain and
           one language. A good example for that is a GettextFile.
        """


class ILanguageAvailability(Interface):

    def getAvailableLanguages():
        """Return a sequence of language tags for available languages
        """


class IUserPreferredLanguages(Interface):

    """This interface provides language negotiation based on user preferences.
    """

    def getPreferredLanguages():
        """Return a sequence of user preferred languages.
        """


class IMessageExportFilter(Interface):
    """The Export Filter for Translation Service Messages.

       Classes implementing this interface should usually be Adaptors, as
       they adapt the IEditableTranslationService interface."""


    def exportMessages(domains, languages):
        """Export all messages that are defined in the specified domains and
           languages.

           Note that some implementations might limit to only one domain and
           one language. A good example for that is a GettextFile.
        """


class INegotiator(Interface):
    """A language negotiation service.
    """

    def getLanguage(langs, env):
        """Return the matching language to use.

        The decision of which language to use is based on the list of
        available languages, and the given user environment.  An
        IUserPreferredLanguages adapter for the environment is obtained and
        the list of acceptable languages is retrieved from the environment.

        If no match is found between the list of available languages and the
        list of acceptable languages, None is returned.

        Arguments:

        langs -- sequence of languages (not necessarily ordered)

        env  -- environment passed to the service to determine a sequence
                of user prefered languages
        """

        # XXX I'd like for there to be a symmetric interface method, one in
        # which an adapter is gotten for both the first arg and the second
        # arg.  I.e. getLanguage(obj, env)
        # But this isn't a good match for the ITranslationService.translate()
        # method. :(


class IUserPreferredCharsets(Interface):
    """This interface provides charset negotiation based on user preferences.
    """

    def getPreferredCharsets():
        """Return a sequence of user preferred charsets. Note that the order
           should describe the order of preference. Therefore the first
           character set in the list is the most preferred one.
        """


class IFormat(Interface):
    """A generic formatting class. It basically contains the parsing and
    construction method for the particular object the formatting class
    handles.

    The constructor will always require a pattern (specific to the object).
    """

    def setPattern(pattern):
        """Overwrite the old formatting pattern with the new one."""

    def getPattern():
        """Get the currently used pattern."""

    def parse(text, pattern=None):
        """Parse the text and convert it to an object, which is returned."""

    def format(obj, pattern=None):
        """Format an object to a string using the pattern as a rule."""



class INumberFormat(IFormat):
    u"""Specific number formatting interface. Here are the formatting
    rules (I modified the rules from ICU a bit, since I think they did not
    agree well with the real world XML formatting strings):

      posNegPattern      := ({subpattern};{subpattern} | {subpattern})
      subpattern         := {padding}{prefix}{padding}{integer}{fraction}
                            {exponential}{padding}{suffix}{padding}
      prefix             := '\u0000'..'\uFFFD' - specialCharacters *
      suffix             := '\u0000'..'\uFFFD' - specialCharacters *
      integer            := {digitField}'0'
      fraction           := {decimalPoint}{digitField}
      exponential        := E integer
      digitField         := ( {digitField} {groupingSeparator} |
                              {digitField} '0'* |
                              '0'* |
                              {optionalDigitField} )
      optionalDigitField := ( {digitField} {groupingSeparator} |
                              {digitField} '#'* |
                              '#'* )
      groupingSeparator  := ,
      decimalPoint       := .
      padding            := * '\u0000'..'\uFFFD'


    Possible pattern symbols:

      0    A digit. Always show this digit even if the value is zero.
      #    A digit, suppressed if zero
      .    Placeholder for decimal separator
      ,    Placeholder for grouping separator
      E    Separates mantissa and exponent for exponential formats
      ;    Separates formats (that is, a positive number format verses a
           negative number format)
      -    Default negative prefix. Note that the locale's minus sign
           character is used.
      +    If this symbol is specified the locale's plus sign character is
           used.
      %    Multiply by 100, as percentage
      ?    Multiply by 1000, as per mille
      \u00A4    This is the currency sign. it will be replaced by a currency
           symbol. If it is present in a pattern, the monetary decimal
           separator is used instead of the decimal separator.
      \u00A4\u00A4   This is the international currency sign. It will be replaced
           by an international currency symbol.  If it is present in a
           pattern, the monetary decimal separator is used instead of
           the decimal separator.
      X    Any other characters can be used in the prefix or suffix
      '    Used to quote special characters in a prefix or suffix
    """

    symbols = Dict(
        title=u"Number Symbols",
        key_type=EnumeratedTextLine(
            title=u"Dictionary Class",
            allowed_values=(u'decimal', u'group', u'list', u'percentSign',
                            u'nativeZeroDigit', u'patternDigit', u'plusSign',
                            u'minusSign', u'exponential', u'perMille',
                            u'infinity', u'nan')),
        value_type=TextLine(title=u"Symbol"))


class ICurrencyFormat(INumberFormat):
    """Special currency parsing class."""

    currency = Attribute("""This object must implement ILocaleCurrency. See
                            this interface's documentation for details.""")


class IDateTimeFormat(IFormat):
    """DateTime formatting and parsing interface. Here is a list of
    possible characters and their meaning:

      Symbol Meaning               Presentation      Example

      G      era designator        (Text)            AD
      y      year                  (Number)          1996
      M      month in year         (Text and Number) July and 07
      d      day in month          (Number)          10
      h      hour in am/pm (1~12)  (Number)          12
      H      hour in day (0~23)    (Number)          0
      m      minute in hour        (Number)          30
      s      second in minute      (Number)          55
      S      millisecond           (Number)          978
      E      day in week           (Text)            Tuesday
      D      day in year           (Number)          189
      F      day of week in month  (Number)          2 (2nd Wed in July)
      w      week in year          (Number)          27
      W      week in month         (Number)          2
      a      am/pm marker          (Text)            pm
      k      hour in day (1~24)    (Number)          24
      K      hour in am/pm (0~11)  (Number)          0
      z      time zone             (Text)            Pacific Standard Time
      '      escape for text
      ''     single quote                            '

    Meaning of the amount of characters:

      Text

        Four or more, use full form, <4, use short or abbreviated form if it
        exists. (for example, "EEEE" produces "Monday", "EEE" produces "Mon")

      Number

        The minimum number of digits. Shorter numbers are zero-padded to this
        amount (for example, if "m" produces "6", "mm" produces "06"). Year is
        handled specially; that is, if the count of 'y' is 2, the Year will be
        truncated to 2 digits. (for example, if "yyyy" produces "1997", "yy"
        produces "97".)

      Text and Number

        Three or over, use text, otherwise use number. (for example, "M"
        produces "1", "MM" produces "01", "MMM" produces "Jan", and "MMMM"
        produces "January".)  """

    calendar = Attribute("""This object must implement ILocaleCalendar. See
                            this interface's documentation for details.""")




=== Added File Zope3/src/zope/i18n/interfaces/locales.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Interfaces related to Locales

$Id: locales.py,v 1.1 2004/02/05 22:52:22 srichter Exp $
"""
import re
from zope.interface import Interface, Attribute
from zope.schema import \
     Field, Text, TextLine, Int, Bool, Tuple, List, Dict, Date
from zope.schema import Container, EnumeratedTextLine

class ILocaleProvider(Interface):
    """This interface is our connection to the Zope 3 service. From it
    we can request various Locale objects that can perform all sorts of
    fancy operations.

    This service will be singelton global service, since it doe not make much
    sense to have many locale facilities, especially since this one will be so
    complete, since we will the ICU XML Files as data.  """

    def loadLocale(language=None, country=None, variant=None):
        """Load the locale with the specs that are given by the arguments of
        the method. Note that the LocaleProvider must know where to get the
        locales from."""

    def getLocale(language=None, country=None, variant=None):
        """Get the Locale object for a particular language, country and
        variant."""


class ILocaleIdentity(Interface):
    """Identity information class for ILocale objects.

    Three pieces of information are required to identify a locale:

      o language -- Language in which all of the locale text information are
        returned.

      o script -- Script in which all of the locale text information are
        returned.

      o territory -- Territory for which the locale's information are
        appropriate. None means all territories in which language is spoken.

      o variant -- Sometimes there are regional or historical differences even
        in a certain country. For these cases we use the variant field. A good
        example is the time before the Euro in Germany for example. Therefore
        a valid variant would be 'PREEURO'.

    Note that all of these attributes are read-only once they are set (usually
    done in the constructor)!

    This object is also used to uniquely identify a locale.
    """

    language = TextLine(
        title = u"Language Type",
        description = u"The language for which a locale is applicable.",
        constraint = re.compile(r'[a-z]{2}').match,
        required = True,
        readonly = True)

    script = TextLine(
        title = u"Script Type",
        description = u"""The script for which the language/locale is
                       applicable.""",
        constraint = re.compile(r'[a-z]*').match)

    territory = TextLine(
        title = u"Territory Type",
        description = u"The territory for which a locale is applicable.",
        constraint = re.compile(r'[A-Z]{2}').match,
        required = True,
        readonly = True)

    variant = TextLine(
        title = u"Variant Type",
        description = u"The variant for which a locale is applicable.",
        constraint = re.compile(r'[a-zA-Z]*').match,
        required = True,
        readonly = True)

    version = Field(
        title = u"Locale Version",
        description = u"The value of this field is an ILocaleVersion object.",
        readonly = True)
        
    def __repr__(self):
        """Defines the representation of the id, which should be a compact
        string that references the language, country and variant."""


class ILocaleVersion(Interface):
    """Represents the version of a locale.

    The locale version is part of the ILocaleIdentity object.
    """
    
    number = TextLine(
        title = u"Version Number",
        description = u"The version number of the locale.",
        constraint = re.compile(r'^([0-9].)*[0-9]$').match,
        required = True,
        readonly = True)

    generationDate = Date(
        title = u"Generation Date",
        description = u"Specifies the creation date of the locale.",
        constraint = lambda date: date < datetime.now(),
        readonly = True)

    notes = Text(
        title = u"Notes",
        description = u"Some release notes for the version of this locale.",
        readonly = True)


class ILocaleDisplayNames(Interface):
    """Localized Names of common text strings.

    This object contains localized strings for many terms, including
    language, script and territory names. But also keys and types used
    throughout the locale object are localized here.
    """
    
    languages = Dict(
        title = u"Language type to translated name",
        key_type = TextLine(title=u"Language Type"),
        value_type = TextLine(title=u"Language Name"))

    scripts = Dict(
        title = u"Script type to script name",
        key_type = TextLine(title=u"Script Type"),
        value_type = TextLine(title=u"Script Name"))

    territories = Dict(
        title = u"Territory type to translated territory name",
        key_type = TextLine(title=u"Territory Type"),
        value_type = TextLine(title=u"Territory Name"))

    variants = Dict(
        title = u"Variant type to name",
        key_type = TextLine(title=u"Variant Type"),
        value_type = TextLine(title=u"Variant Name"))

    keys = Dict(
        title = u"Key type to name",
        key_type = TextLine(title=u"Key Type"),
        value_type = TextLine(title=u"Key Name"))

    types = Dict(
        title = u"Type type and key to localized name",
        key_type = Tuple(title=u"Type Type and Key"),
        value_type = TextLine(title=u"Type Name"))


class ILocaleTimeZone(Interface):
    """Represents and defines various timezone information. It mainly manages
    all the various names for a timezone and the cities contained in it.

    Important: ILocaleTimeZone objects are not intended to provide
    implementations for the standard datetime module timezone support. They
    are merily used for Locale support.
    """

    type = TextLine(
        title = u"Time Zone Type",
        description = u"Standard name of the timezone for unique referencing.",
        required = True,
        readonly = True)

    cities = List(
        title = u"Cities",
        description = u"Cities in Timezone",
        value_type = TextLine(title=u"City Name"),
        required = True,
        readonly = True)


    names = Dict(
        title = u"Time Zone Names",
        description = u"Various names of the timezone.",
        key_type = EnumeratedTextLine(
                   title = u"Time Zone Name Type",
                   allowed_values = (u'generic', u'standard', u'daylight')),
        value_type = Tuple(title=u"Time Zone Name and Abbreviation",
                           min_length=2, max_length=2),
        required = True,
        readonly = True)


class ILocaleFormat(Interface):
    """Specifies a format for a particular type of data."""

    type = TextLine(
        title=u"Format Type",
        description=u"The name of the format",
        required = False,
        readonly = True)

    displayName = TextLine(
        title = u"Display Name",
        description = u"Name of the calendar, for example 'gregorian'.",
        required = False,
        readonly = True)

    pattern = TextLine(
        title = u"Format Pattern",
        description = u"The pattern that is used to format the object.",
        required = True,
        readonly = True)


class ILocaleFormatLength(Interface):
    """The format length describes a class of formats."""
    
    type = EnumeratedTextLine(
        title = u"Format Length Type",
        description = u"Name of the format length",
        allowed_values = (u'full', u'long', u'medium', u'short')
        )

    default = TextLine(
        title=u"Default Format",
        description=u"The name of the defaulkt format.")

    formats = Dict(
        title = u"Formats",
        description = u"Maps format types to format objects",
        key_type = TextLine(title = u"Format Type"),
        value_type = Field(
                         title = u"Format Object",
                         description = u"Values are ILocaleFormat objects."),
        required = True,
        readonly = True)


class ILocaleCalendar(Interface):
    """There is a massive amount of information contained in the calendar,
    which made it attractive to be added."""

    type = TextLine(
        title=u"Calendar Type",
        description=u"Name of the calendar, for example 'gregorian'.")

    months = Dict(
        title = u"Month Names",
        description = u"A mapping of all month names and abbreviations",
        key_type = Int(title=u"Type", min=1, max=12),
        value_type = Tuple(title=u"Month Name and Abbreviation",
                           min_length=2, max_length=2))

    days = Dict(
        title=u"Weekdays Names",
        description = u"A mapping of all month names and abbreviations",
        key_type = EnumeratedTextLine(title=u"Type",
                            allowed_values=(u'sun', u'mon', u'tue', u'wed',
                                            u'thu', u'fri', u'sat', u'sun')),
        value_type = Tuple(title=u"Weekdays Name and Abbreviation",
                           min_length=2, max_length=2))

    week = Dict(
        title=u"Week Information",
        description = u"Contains various week information",
        key_type = EnumeratedTextLine(
            title=u"Type",
            description=u"""
            Varies Week information:

              - 'minDays' is just an integer between 1 and 7.

              - 'firstDay' specifies the first day of the week by integer.

              - The 'weekendStart' and 'weekendEnd' are tuples of the form
                (weekDayNumber, datetime.time)
            """,
            allowed_values=(u'minDays', u'firstDay',
                            u'weekendStart', u'weekendEnd')))

    am = TextLine(title=u"AM String")

    pm = TextLine(title=u"PM String")

    eras = Dict(
        title = u"Era Names",
        key_type = Int(title=u"Type", min=0),
        value_type = Tuple(title=u"Era Name and Abbreviation",
                           min_length=2, max_length=2))

    defaultDateFormat = TextLine(title=u"Default Date Format Type")

    dateFormats = Dict(
        title=u"Date Formats",
        description = u"Contains various Date Formats.",
        key_type = EnumeratedTextLine(
                      title=u"Type",
                      description = u"Name of the format length",
                      allowed_values = (u'full', u'long', u'medium', u'short')),
        value_type = Field(title=u"ILocaleFormatLength object"))

    defaultTimeFormat = TextLine(title=u"Default Time Format Type")

    timeFormats = Dict(
        title=u"Time Formats",
        description = u"Contains various Time Formats.",
        key_type = EnumeratedTextLine(
                      title=u"Type",
                      description = u"Name of the format length",
                      allowed_values = (u'full', u'long', u'medium', u'short')),
        value_type = Field(title=u"ILocaleFormatLength object"))

    defaultDateTimeFormat = TextLine(title=u"Default Date-Time Format Type")

    dateTimeFormats = Dict(
        title=u"Date-Time Formats",
        description = u"Contains various Date-Time Formats.",
        key_type = EnumeratedTextLine(
                      title=u"Type",
                      description = u"Name of the format length",
                      allowed_values = (u'full', u'long', u'medium', u'short')),
        value_type = Field(title=u"ILocaleFormatLength object"))

    def getMonthNames():
        """Return a list of month names."""

    def getMonthTypeFromName(name):
        """Return the type of the month with the right name."""

    def getMonthAbbreviations():
        """Return a list of month abbreviations."""

    def getMonthTypeFromAbbreviation(abbr):
        """Return the type of the month with the right abbreviation."""

    def getDayNames():
        """Return a list of weekday names."""

    def getDayTypeFromName(name):
        """Return the id of the weekday with the right name."""

    def getDayAbbr():
        """Return a list of weekday abbreviations."""

    def getDayTypeFromAbbr(abbr):
        """Return the id of the weekday with the right abbr."""

    def isWeekend(datetime):
        """Determines whether a the argument lies in a weekend."""

    def getFirstDayName():
        """Return the the type of the first day in the week.""" 


class ILocaleDates(Interface):
    """This object contains various data about dates, times and time zones."""

    localizedPatternChars = TextLine(
        title = u"Localized Pattern Characters",
        description = u"Localized pattern characters used in dates and times")

    calendars = Dict(
        title = u"Calendar type to ILocaleCalendar",
        key_type = EnumeratedTextLine(
            title=u"Calendar Type",
            allowed_values=(u'gregorian',
                            u'arabic',
                            u'chinese',
                            u'civil-arabic',
                            u'hebrew',
                            u'japanese',
                            u'thai-buddhist')),
        value_type=Field(title=u"Calendar",
                         description=u"This is a ILocaleCalendar object."))

    timezones = Dict(
        title=u"Time zone type to ILocaleTimezone",
        key_type=TextLine(title=u"Time Zone type"),
        value_type=Field(title=u"Time Zone",
                         description=u"This is a ILocaleTimeZone object."))

    def getFormatter(category, calendar='gregorian', length=None, name=None):
        """Get the ... XXX"""

class ILocaleCurrency(Interface):
    """Defines a particular currency."""

    type = TextLine(title=u'Type')

    symbol = TextLine(title=u'Symbol')

    displayName = TextLine(title=u'Official Name')

    symbolChoice = Bool(title=u'Symbol Choice') 

class ILocaleNumbers(Interface):
    """This object contains various data about numbers and currencies."""

    symbols = Dict(
        title = u"Number Symbols",
        key_type = EnumeratedTextLine(
            title = u"Format Name",
            allowed_values = (u'decimal', u'group', u'list', u'percentSign',
                              u'nativeZeroDigit', u'patternDigit', u'plusSign',
                              u'minusSign', u'exponential', u'perMille',
                              u'infinity', u'nan')),
        value_type=TextLine(title=u"Symbol"))

    defaultDecimalFormat = TextLine(title=u"Default Decimal Format Type")

    decimalFormats = Dict(
        title=u"Decimal Formats",
        description = u"Contains various Decimal Formats.",
        key_type = EnumeratedTextLine(
                      title=u"Type",
                      description = u"Name of the format length",
                      allowed_values = (u'full', u'long', u'medium', u'short')),
        value_type = Field(title=u"ILocaleFormatLength object"))

    defaultScientificFormat = TextLine(title=u"Default Scientific Format Type")

    scientificFormats = Dict(
        title=u"Scientific Formats",
        description = u"Contains various Scientific Formats.",
        key_type = EnumeratedTextLine(
                      title=u"Type",
                      description = u"Name of the format length",
                      allowed_values = (u'full', u'long', u'medium', u'short')),
        value_type = Field(title=u"ILocaleFormatLength object"))

    defaultPercentFormat = TextLine(title=u"Default Percent Format Type")

    percentFormats = Dict(
        title=u"Percent Formats",
        description = u"Contains various Percent Formats.",
        key_type = EnumeratedTextLine(
                      title=u"Type",
                      description = u"Name of the format length",
                      allowed_values = (u'full', u'long', u'medium', u'short')),
        value_type = Field(title=u"ILocaleFormatLength object"))

    defaultCurrencyFormat = TextLine(title=u"Default Currency Format Type")

    currencyFormats = Dict(
        title=u"Currency Formats",
        description = u"Contains various Currency Formats.",
        key_type = EnumeratedTextLine(
                      title=u"Type",
                      description = u"Name of the format length",
                      allowed_values = (u'full', u'long', u'medium', u'short')),
        value_type = Field(title=u"ILocaleFormatLength object"))

    currencies = Dict(
        title=u"Currencies",
        description = u"Contains various Currency data.",
        key_type = TextLine(
                      title=u"Type",
                      description = u"Name of the format length"),
        value_type = Field(title=u"ILocaleCurrency object"))


    def getFormatter(category, length=None, name=u''):
        """Get the NumberFormat based on the category, length and name of the
        format.

        The 'category' specifies the type of number format you would like to
        have. The available options are: 'decimal', 'percent', 'scientific',
        'currency'.

        The 'length' specifies the output length of the number. The allowed
        values are: 'short', 'medium', 'long' and 'full'. If no length was
        specified, the default length is chosen.

        Every length can have actually several formats. In this case these
        formats are named and you can specify the name here. If no name was
        specified, the first unnamed format is chosen.
        """

    def getDefaultCurrency():
        """Get the default currency."""


class ILocale(Interface):
    """This class contains all important information about the locale.

    Usually a Locale is identified using a specific language, country and
    variant.  However, the country and variant are optional, so that a lookup
    hierarchy develops.  It is easy to recognize that a locale that is missing
    the variant is more general applicable than the one with the variant.
    Therefore, if a specific Locale does not contain the required information,
    it should look one level higher.  There will be a root locale that
    specifies none of the above identifiers.
    """

    id = Field(
        title = u"Locale identity",
        description = u"ILocaleIdentity object identifying the locale.",
        required = True,
        readonly = True)

    displayNames = Field(
        title = u"Display Names",
        description = u"""ILocaleDisplayNames object that contains localized
                        names.""")

    dates = Field(
        title = u"Dates",
        description = u"ILocaleDates object that contains date/time data.")

    numbers = Field(
        title = u"Numbers",
        description = u"ILocaleNumbers object that contains number data.")

    delimiters = Dict(
        title=u"Delimiters",
        description = u"Contains various Currency data.",
        key_type = EnumeratedTextLine(
            title=u"Delimiter Type",
            description = u"Delimiter name.",
            allowed_values=(u'quotationStart', u'quotationEnd',
                            u'alternateQuotationStart',
                            u'alternateQuotationEnd')),
        value_type = Field(title=u"Delimiter symbol"))

    def getLocaleID():
        """Return a locale id as specified in the LDML specification"""


class ILocaleInheritance(Interface):
    """Locale inheritance support.

    Locale-related objects implementing this interface are able to ask for its
    inherited self. For example, 'en_US.dates.monthNames' can call on itself
    'getInheritedSelf()' and get the value for 'en.dates.monthNames'. 
    """

    __parent__ = Attribute("The parent in the location hierarchy")

    __name__ = TextLine(
        title = u"The name within the parent",
        description=u"""The parent can be traversed with this name to get
                      the object.""")

    def getInheritedSelf():
        """Return itself but in the next higher up Locale."""


class IAttributeInheritance(ILocaleInheritance):
    """Provides inheritance properties for attributes"""

    def __setattr__(name, value):
        """Set a new attribute on the object.

        When a value is set on any inheritance-aware object and the value
        also implements ILocaleInheritance, then we need to set the
        '__parent__' and '__name__' attribute on the value.
        """

    def __getattributes__(name):
        """Return the value of the attribute with the specified name.

        If an attribute is not found or is None, the next higher up Locale
        object is consulted."""


class IDictionaryInheritance(ILocaleInheritance):
    """Provides inheritance properties for dictionary keys"""

    def __setitem__(key, value):
        """Set a new item on the object.

        Here we assume that the value does not require any inheritance, so
        that we do not set '__parent__' or '__name__' on the value.
        """

    def __getitem__(key):
        """Return the value of the item with the specified name.

        If an key is not found or is None, the next higher up Locale
        object is consulted.
        """




More information about the Zope3-Checkins mailing list