zope.i18n API Reference¶
zope.i18n¶
i18n support.
-
zope.i18n.
negotiate
(context)[source]¶ Negotiate language.
This only works if the languages are set globally, otherwise each message catalog needs to do the language negotiation.
If no languages are set, this always returns None:
>>> import zope.i18n as i18n >>> from zope.component import queryUtility >>> old_allowed_languages = i18n.ALLOWED_LANGUAGES >>> i18n.ALLOWED_LANGUAGES = None >>> i18n.negotiate('anything') is None True
If languages are set, but there is no
INegotiator
utility, this returns None:>>> i18n.ALLOWED_LANGUAGES = ('en',) >>> queryUtility(i18n.INegotiator) is None True >>> i18n.negotiate('anything') is None True
-
zope.i18n.
translate
(msgid, domain=None, mapping=None, context=None, target_language=None, default=None, msgid_plural=None, default_plural=None, number=None)[source]¶ Translate text.
First setup some test components:
>>> from zope import component, interface >>> import zope.i18n.interfaces
>>> @interface.implementer(zope.i18n.interfaces.ITranslationDomain) ... class TestDomain: ... ... def __init__(self, **catalog): ... self.catalog = catalog ... ... def translate(self, text, *_, **__): ... return self.catalog[text]
Normally, the translation system will use a domain utility:
>>> component.provideUtility(TestDomain(eek=u"ook"), name='my.domain') >>> print(translate(u"eek", 'my.domain')) ook
If no domain is given, or if there is no domain utility for the given domain, then the text isn’t translated:
>>> print(translate(u"eek")) eek
Moreover the text will be converted to unicode:
>>> not isinstance(translate('eek', 'your.domain'), bytes) True
A fallback domain factory can be provided. This is normally used for testing:
>>> def fallback(domain=u""): ... return TestDomain(eek=u"test-from-" + domain) >>> interface.directlyProvides( ... fallback, ... zope.i18n.interfaces.IFallbackTranslationDomainFactory, ... )
>>> component.provideUtility(fallback)
>>> print(translate(u"eek")) test-from-
>>> print(translate(u"eek", 'your.domain')) test-from-your.domain
If no target language is provided, but a context is and we were able to find a translation domain, we will use the
negotiate
function to attempt to determine the language to translate to:>>> def test_negotiate(context): ... print("Negotiating for %r" % (context,)) ... return 'en' >>> i18n.negotiate = test_negotiate >>> print(translate('eek', 'your.domain', context='context')) Negotiating for 'context' test-from-your.domain
-
zope.i18n.
interpolate
(text, mapping=None)[source]¶ Insert the data passed from mapping into the text.
First setup a test mapping:
>>> mapping = {"name": "Zope", "version": 3}
In the text we can use substitution slots like $varname or ${varname}:
>>> print(interpolate(u"This is $name version ${version}.", mapping)) This is Zope version 3.
Interpolation variables can be used more than once in the text:
>>> print(interpolate( ... u"This is $name version ${version}. ${name} $version!", mapping)) This is Zope version 3. Zope 3!
In case if the variable wasn’t found in the mapping or ‘$$’ form was used no substitution will happens:
>>> print(interpolate( ... u"This is $name $version. $unknown $$name $${version}.", mapping)) This is Zope 3. $unknown $$name $${version}.
>>> print(interpolate(u"This is ${name}")) This is ${name}
If a mapping value is a message id itself it is interpolated, too:
>>> from zope.i18nmessageid import Message >>> print(interpolate(u"This is $meta.", ... mapping={'meta': Message(u"$name $version", ... mapping=mapping)})) This is Zope 3.
zope.i18n.config¶
-
zope.i18n.config.
COMPILE_MO_FILES_KEY
= 'zope_i18n_compile_mo_files'¶ The environment variable that is consulted when this module is imported to determine the value of
COMPILE_MO_FILES
. Simply set this to a non-empty string to make it True.
-
zope.i18n.config.
COMPILE_MO_FILES
= '__unset__'¶ Whether or not the ZCML directives will attempt to compile translation files. Defaults to False.
-
zope.i18n.config.
ALLOWED_LANGUAGES_KEY
= 'zope_i18n_allowed_languages'¶ The environment variable that is consulted when this module is imported to determine the value of
ALLOWED_LANGUAGES
. If set, this should be a comma-separated list of language names.
-
zope.i18n.config.
ALLOWED_LANGUAGES
= None¶ A set of languages that
zope.i18n.negotiate
will pass to thezope.i18n.interfaces.INegotiator
utility. If this is None, no utility will be used.
zope.i18n.compile¶
zope.i18n.format¶
Basic Object Formatting
This module implements basic object formatting functionality, such as date/time, number and money formatting.
-
zope.i18n.format.
roundHalfUp
(n)[source]¶ Works like round() in python2.x
Implementation of round() was changed in python3 - it rounds halfs to nearest even number, so that round(0.5) == 0. This function is here to unify behaviour between python 2.x and 3.x for the purposes of this module.
-
exception
zope.i18n.format.
DateTimeParseError
[source]¶ Bases:
Exception
Error is raised when parsing of datetime failed.
-
class
zope.i18n.format.
DateTimeFormat
(pattern=None, calendar=None)[source]¶ Bases:
object
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 and Number) 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”.)
-
exception
zope.i18n.format.
NumberParseError
[source]¶ Bases:
Exception
Error that can be raised when smething unexpected happens during the number parsing process.
-
class
zope.i18n.format.
NumberFormat
(pattern=None, symbols=())[source]¶ Bases:
object
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
-
exception
zope.i18n.format.
DateTimePatternParseError
[source]¶ Bases:
Exception
DateTime Pattern Parse Error
-
zope.i18n.format.
parseDateTimePattern
(pattern, DATETIMECHARS='aGyMdEDFwWhHmsSkKz')[source]¶ This method can handle everything: time, date and datetime strings.
-
zope.i18n.format.
buildDateTimeParseInfo
(calendar, pattern)[source]¶ This method returns a dictionary that helps us with the parsing. It also depends on the locale of course.
-
zope.i18n.format.
buildDateTimeInfo
(dt, calendar, pattern)[source]¶ Create the bits and pieces of the datetime object that can be put together.
zope.i18n.gettextmessagecatalog¶
A simple implementation of a Message Catalog.
-
zope.i18n.gettextmessagecatalog.
plural_formatting
(func)[source]¶ This decorator interpolates the possible formatting marker. This interpolation marker is usally present for plurals. Example:
There are %d apples
orThey have %s pies.
Please note that the interpolation can be done, alternatively, using the mapping. This is only present as a conveniance.
zope.i18n.interfaces¶
Internationalization of content objects.
-
interface
zope.i18n.interfaces.
II18nAware
[source]¶ Internationalization aware content object.
-
getDefaultLanguage
()¶ Return the default language.
-
setDefaultLanguage
(language)¶ Set the default language, which will be used if the language is not specified, or not available.
-
getAvailableLanguages
()¶ Find all the languages that are available.
-
-
interface
zope.i18n.interfaces.
IMessageCatalog
[source]¶ 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.
-
getMessage
(msgid)¶ Get the appropriate text for the given message id.
An exception is raised if the message id is not found.
-
queryMessage
(msgid, default=None)¶ Look for the appropriate text for the given message id.
If the message id is not found, default is returned.
-
getPluralMessage
(singular, plural, n)¶ Get the appropriate text for the given message id and the plural id.
An exception is raised if nothing was found.
-
queryPluralMessage
(singular, plural, n, dft1=None, dft2=None)¶ Look for the appropriate text for the given message id and the plural id.
If
n
is evaluated as a singular and the id is not found,dft1
is returned. Ifn
is evaluated as a plural and the plural id is not found,dft2
is returned.
-
language
¶ Language
The language the catalog translates to.
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
domain
¶ Domain
The domain the catalog is registered for.
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
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.
-
interface
zope.i18n.interfaces.
ITranslationDomain
[source]¶ The Translation Domain utility
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.
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.
Standard arguments in the methods described below:
- 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.
msgid_plural – The id of the plural message that should be translated.
number – The number of items linked to the plural of the message.
- 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.
-
domain
¶ Domain Name
The name of the domain this object represents.
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
translate
(msgid, mapping=None, context=None, target_language=None, default=None, msgid_plural=None, default_plural=None, number=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 with data from
mapping
. If a value ofmapping
is a Message it is also translated before interpolation.
-
interface
zope.i18n.interfaces.
IFallbackTranslationDomainFactory
[source]¶ Factory for creating fallback translation domains
Fallback translation domains are primarily used for testing or debugging i18n.
-
__call__
(domain_id='')¶ Return a fallback translation domain for the given domain id.
-
-
interface
zope.i18n.interfaces.
ITranslator
[source]¶ 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.
-
translate
(msgid, mapping=None, default=None, msgid_plural=None, default_plural=None, number=None)¶ Translate the source msgid using the given mapping.
See ITranslationService for details.
-
-
interface
zope.i18n.interfaces.
IMessageImportFilter
[source]¶ The Import Filter for Translation Service Messages.
Classes implementing this interface should usually be Adaptors, as they adapt the IEditableTranslationService interface.
-
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.
-
-
interface
zope.i18n.interfaces.
IUserPreferredLanguages
[source]¶ This interface provides language negotiation based on user preferences.
See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
-
getPreferredLanguages
()¶ Return a sequence of user preferred languages.
The sequence is sorted in order of quality, with the most preferred languages first.
-
-
interface
zope.i18n.interfaces.
IMessageExportFilter
[source]¶ The Export Filter for Translation Service Messages.
Classes implementing this interface should usually be Adaptors, as they adapt the IEditableTranslationService interface.
-
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.
-
-
interface
zope.i18n.interfaces.
INegotiator
[source]¶ A language negotiation service.
-
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
-
-
interface
zope.i18n.interfaces.
IUserPreferredCharsets
[source]¶ This interface provides charset negotiation based on user preferences.
-
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.
-
-
interface
zope.i18n.interfaces.
IFormat
[source]¶ 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).
-
setPattern
(pattern)¶ Overwrite the old formatting pattern with the new one.
-
getPattern
()¶ Get the currently used pattern.
-
parse
(text, pattern=None)¶ Parse the text and convert it to an object, which is returned.
-
format
(obj, pattern=None)¶ Format an object to a string using the pattern as a rule.
-
-
interface
zope.i18n.interfaces.
INumberFormat
[source]¶ Extends:
zope.i18n.interfaces.IFormat
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
-
type
¶ Type
The type into which a string is parsed. If
None
, thenint
will be used for whole numbers andfloat
for decimals.Implementation: zope.schema.Field
Read Only: False Required: False Default Value: None
-
symbols
¶ Number Symbols
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Dictionary Class
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
Symbol
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
-
interface
zope.i18n.interfaces.
IDateTimeFormat
[source]¶ Extends:
zope.i18n.interfaces.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 and Number) 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
¶ This object must implement ILocaleCalendar. See this interface’s documentation for details.
-
Interfaces related to Locales
-
interface
zope.i18n.interfaces.locales.
ILocaleProvider
[source]¶ 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.
-
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.
-
getLocale
(language=None, country=None, variant=None)¶ Get the Locale object for a particular language, country and variant.
-
-
interface
zope.i18n.interfaces.locales.
ILocaleIdentity
[source]¶ 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
¶ Language Type
The language for which a locale is applicable.
Implementation: zope.schema.TextLine
Read Only: True Required: True Default Value: None Allowed Type: str
-
script
¶ Script Type
The script for which the language/locale is applicable.
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
territory
¶ Territory Type
The territory for which a locale is applicable.
Implementation: zope.schema.TextLine
Read Only: True Required: True Default Value: None Allowed Type: str
-
variant
¶ Variant Type
The variant for which a locale is applicable.
Implementation: zope.schema.TextLine
Read Only: True Required: True Default Value: None Allowed Type: str
-
version
¶ Locale Version
The value of this field is an ILocaleVersion object.
Implementation: zope.schema.Field
Read Only: True Required: True Default Value: None
-
__repr__
(self)¶ Defines the representation of the id, which should be a compact string that references the language, country and variant.
-
interface
zope.i18n.interfaces.locales.
ILocaleVersion
[source]¶ Represents the version of a locale.
The locale version is part of the ILocaleIdentity object.
-
number
¶ Version Number
The version number of the locale.
Implementation: zope.schema.TextLine
Read Only: True Required: True Default Value: None Allowed Type: str
-
generationDate
¶ Generation Date
Specifies the creation date of the locale.
Implementation: zope.schema.Date
Read Only: True Required: True Default Value: None Allowed Type: datetime.date
-
-
interface
zope.i18n.interfaces.locales.
ILocaleDisplayNames
[source]¶ 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
¶ Language type to translated name
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Language Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
Value Type
Language Name
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
scripts
¶ Script type to script name
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Script Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
Value Type
Script Name
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
territories
¶ Territory type to translated territory name
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Territory Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
Value Type
Territory Name
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
variants
¶ Variant type to name
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Variant Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
Value Type
Variant Name
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
keys
¶ Key type to name
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Key Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
Value Type
Key Name
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
types
¶ Type type and key to localized name
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type Type and Key
Implementation: zope.schema.Tuple
Read Only: False Required: True Default Value: None Allowed Type: tuple
Value Type
Type Name
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
-
interface
zope.i18n.interfaces.locales.
ILocaleTimeZone
[source]¶ 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
¶ Time Zone Type
Standard name of the timezone for unique referencing.
Implementation: zope.schema.TextLine
Read Only: True Required: True Default Value: None Allowed Type: str
-
cities
¶ Cities
Cities in Timezone
Implementation: zope.schema.List
Read Only: True Required: True Default Value: None Allowed Type: list
Value Type
City Name
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
names
¶ Time Zone Names
Various names of the timezone.
Implementation: zope.schema.Dict
Read Only: True Required: True Default Value: None Allowed Type: dict
Key Type
Time Zone Name Type
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
Time Zone Name and Abbreviation
Implementation: zope.schema.Tuple
Read Only: False Required: True Default Value: None Allowed Type: tuple
-
-
interface
zope.i18n.interfaces.locales.
ILocaleFormat
[source]¶ Specifies a format for a particular type of data.
-
type
¶ Format Type
The name of the format
Implementation: zope.schema.TextLine
Read Only: True Required: False Default Value: None Allowed Type: str
-
-
interface
zope.i18n.interfaces.locales.
ILocaleFormatLength
[source]¶ The format length describes a class of formats.
-
type
¶ Format Length Type
Name of the format length
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None
-
default
¶ Default Format
The name of the defaulkt format.
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
formats
¶ Formats
Maps format types to format objects
Implementation: zope.schema.Dict
Read Only: True Required: True Default Value: None Allowed Type: dict
Key Type
Format Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
Value Type
Format Object
Values are ILocaleFormat objects.
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
-
interface
zope.i18n.interfaces.locales.
ILocaleMonthContext
[source]¶ Specifices a usage context for month names
-
type
¶ Month context type
Name of the month context, format or stand-alone.
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
defaultWidth
¶ Default month name width
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: ‘wide’ Allowed Type: str
-
months
¶ Month Names
A mapping of month name widths to a mapping ofcorresponding month names.
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Width type
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
Month name
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Implementation: zope.schema.Int
Read Only: False Required: True Default Value: None Allowed Type: int
Value Type
Month Name
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
-
interface
zope.i18n.interfaces.locales.
ILocaleDayContext
[source]¶ Specifices a usage context for days names
-
type
¶ Day context type
Name of the day context, format or stand-alone.
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
defaultWidth
¶ Default day name width
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: ‘wide’ Allowed Type: str
-
days
¶ Day Names
A mapping of day name widths to a mapping ofcorresponding day names.
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Width type
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
Day name
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
Day Name
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
-
interface
zope.i18n.interfaces.locales.
ILocaleCalendar
[source]¶ There is a massive amount of information contained in the calendar, which made it attractive to be added.
-
type
¶ Calendar Type
Name of the calendar, for example ‘gregorian’.
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
defaultMonthContext
¶ Default month context
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: ‘format’ Allowed Type: str
-
monthContexts
¶ Month Contexts
A mapping of month context types to ILocaleMonthContext objects
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
ILocaleMonthContext object
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
months
¶ Month Names
A mapping of all month names and abbreviations
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Implementation: zope.schema.Int
Read Only: False Required: True Default Value: None Allowed Type: int
Value Type
Month Name and Abbreviation
Implementation: zope.schema.Tuple
Read Only: False Required: True Default Value: None Allowed Type: tuple
-
defaultDayContext
¶ Default day context
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: ‘format’ Allowed Type: str
-
dayContexts
¶ Day Contexts
A mapping of day context types to ILocaleDayContext objects
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
ILocaleDayContext object
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
days
¶ Weekdays Names
A mapping of all month names and abbreviations
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
Weekdays Name and Abbreviation
Implementation: zope.schema.Tuple
Read Only: False Required: True Default Value: None Allowed Type: tuple
-
week
¶ Week Information
Contains various week information
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
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)
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None
-
am
¶ AM String
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
pm
¶ PM String
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
eras
¶ Era Names
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Implementation: zope.schema.Int
Read Only: False Required: True Default Value: None Allowed Type: int
Value Type
Era Name and Abbreviation
Implementation: zope.schema.Tuple
Read Only: False Required: True Default Value: None Allowed Type: tuple
-
defaultDateFormat
¶ Default Date Format Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
dateFormats
¶ Date Formats
Contains various Date Formats.
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Name of the format length
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
ILocaleFormatLength object
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
defaultTimeFormat
¶ Default Time Format Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
timeFormats
¶ Time Formats
Contains various Time Formats.
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Name of the format length
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
ILocaleFormatLength object
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
defaultDateTimeFormat
¶ Default Date-Time Format Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
dateTimeFormats
¶ Date-Time Formats
Contains various Date-Time Formats.
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Name of the format length
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
ILocaleFormatLength object
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
getMonthNames
()¶ Return a list of month names.
-
getMonthTypeFromName
(name)¶ Return the type of the month with the right name.
-
getMonthAbbreviations
()¶ Return a list of month abbreviations.
-
getMonthTypeFromAbbreviation
(abbr)¶ Return the type of the month with the right abbreviation.
-
getDayNames
()¶ Return a list of weekday names.
-
getDayTypeFromName
(name)¶ Return the id of the weekday with the right name.
-
getDayAbbr
()¶ Return a list of weekday abbreviations.
-
getDayTypeFromAbbr
(abbr)¶ Return the id of the weekday with the right abbr.
-
isWeekend
(datetime)¶ Determines whether a the argument lies in a weekend.
-
getFirstDayName
()¶ Return the the type of the first day in the week.
-
-
interface
zope.i18n.interfaces.locales.
ILocaleDates
[source]¶ This object contains various data about dates, times and time zones.
-
localizedPatternChars
¶ Localized Pattern Characters
Localized pattern characters used in dates and times
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
calendars
¶ Calendar type to ILocaleCalendar
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Calendar Type
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
Calendar
This is a ILocaleCalendar object.
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
timezones
¶ Time zone type to ILocaleTimezone
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Time Zone type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
Value Type
Time Zone
This is a ILocaleTimeZone object.
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
getFormatter
(category, length=None, name=None, calendar='gregorian')¶ Get a date/time formatter.
category
must be one of ‘date’, ‘dateTime’, ‘time’.The ‘length’ specifies the output length of the value. The allowed values are: ‘short’, ‘medium’, ‘long’ and ‘full’. If no length was specified, the default length is chosen.
-
-
interface
zope.i18n.interfaces.locales.
ILocaleCurrency
[source]¶ Defines a particular currency.
-
type
¶ Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
symbol
¶ Symbol
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
-
interface
zope.i18n.interfaces.locales.
ILocaleNumbers
[source]¶ This object contains various data about numbers and currencies.
-
symbols
¶ Number Symbols
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Format Name
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
Symbol
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
defaultDecimalFormat
¶ Default Decimal Format Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
decimalFormats
¶ Decimal Formats
Contains various Decimal Formats.
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Name of the format length
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
ILocaleFormatLength object
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
defaultScientificFormat
¶ Default Scientific Format Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
scientificFormats
¶ Scientific Formats
Contains various Scientific Formats.
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Name of the format length
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
ILocaleFormatLength object
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
defaultPercentFormat
¶ Default Percent Format Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
percentFormats
¶ Percent Formats
Contains various Percent Formats.
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Name of the format length
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
ILocaleFormatLength object
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
defaultCurrencyFormat
¶ Default Currency Format Type
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
currencyFormats
¶ Currency Formats
Contains various Currency Formats.
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Name of the format length
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
ILocaleFormatLength object
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
currencies
¶ Currencies
Contains various Currency data.
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Type
Name of the format length
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
Value Type
ILocaleCurrency object
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
getFormatter
(category, length=None, name='')¶ 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.
-
getDefaultCurrency
()¶ Get the default currency.
-
-
interface
zope.i18n.interfaces.locales.
ILocaleOrientation
[source]¶ Information about the orientation of text.
-
characters
¶ Orientation of characters
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: ‘left-to-right’
-
lines
¶ Orientation of characters
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: ‘top-to-bottom’
-
-
interface
zope.i18n.interfaces.locales.
ILocale
[source]¶ 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
¶ Locale identity
ILocaleIdentity object identifying the locale.
Implementation: zope.schema.Field
Read Only: True Required: True Default Value: None
-
displayNames
¶ Display Names
ILocaleDisplayNames object that contains localized names.
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
dates
¶ Dates
ILocaleDates object that contains date/time data.
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
numbers
¶ Numbers
ILocaleNumbers object that contains number data.
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
orientation
¶ Orientation
ILocaleOrientation with text orientation info.
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
delimiters
¶ Delimiters
Contains various Currency data.
Implementation: zope.schema.Dict
Read Only: False Required: True Default Value: None Allowed Type: dict
Key Type
Delimiter Type
Delimiter name.
Implementation: zope.schema.Choice
Read Only: False Required: True Default Value: None Value Type
Delimiter symbol
Implementation: zope.schema.Field
Read Only: False Required: True Default Value: None
-
getLocaleID
()¶ Return a locale id as specified in the LDML specification
-
-
interface
zope.i18n.interfaces.locales.
ILocaleInheritance
[source]¶ 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__
¶ The parent in the location hierarchy
-
__name__
¶ The name within the parent
The parent can be traversed with this name to get the object.
Implementation: zope.schema.TextLine
Read Only: False Required: True Default Value: None Allowed Type: str
-
getInheritedSelf
()¶ Return itself but in the next higher up Locale.
-
-
interface
zope.i18n.interfaces.locales.
IAttributeInheritance
[source]¶ Extends:
zope.i18n.interfaces.locales.ILocaleInheritance
Provides inheritance properties for attributes
-
__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.
-
__getattribute__
(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.
-
-
interface
zope.i18n.interfaces.locales.
IDictionaryInheritance
[source]¶ Extends:
zope.i18n.interfaces.locales.ILocaleInheritance
Provides inheritance properties for dictionary keys
-
__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.
-
__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.
-
-
interface
zope.i18n.interfaces.locales.
ICollator
[source]¶ Provide support for collating text strings
This interface will typically be provided by adapting a locale.
-
key
(text)¶ Return a collation key for the given text.
-
cmp
(text1, text2)¶ Compare two text strings.
The return value is negative if text1 < text2, 0 is they are equal, and positive if text1 > text2.
-