Trees | Index | Help |
|
---|
Package zope :: Package i18n :: Package locales :: Module xmlfactory :: Class LocaleFactory |
|
object
--+
|
LocaleFactory
Method Summary | |
---|---|
Initialize factory. | |
Create the Locale. | |
Extract all calendars and their specific information from the Locale's DOM tree. | |
Extract all currency definitions and their information from the Locale's DOM tree. | |
Extract all date information from the DOM tree | |
Extract all day entries from cal_node and store them in calendar. | |
Extract all delimiter entries from the DOM tree. | |
Extract all display names from the DOM tree. | |
Extract all era entries from cal_node and store them in calendar. | |
Extract all format entries from formats_node and return a tuple of the form (defaultFormatType, [LocaleFormatLength, ...]). | |
Extract the Locale's identity object based on info from the DOM tree. | |
Extract all month entries from cal_node and store them in calendar. | |
Extract all number formats from the numbers_node and save the data in numbers. | |
Extract all number information from the DOM tree | |
Extract orientation information. | |
Extract all week entries from cal_node and store them in calendar. | |
Extract all timezone information for the locale from the DOM tree. | |
Extract all types from the names_node. | |
Extract the Locale's version info based on data from the DOM tree. | |
Extract all week entries from cal_node and store them in calendar. | |
_getText(self,
nodelist)
| |
Inherited from object | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
x.__hash__() <==> hash(x) | |
T.__new__(S, ...) -> a new object with type S, a subtype of T | |
helper for pickle | |
helper for pickle | |
x.__repr__() <==> repr(x) | |
x.__setattr__('name', value) <==> x.name = value | |
x.__str__() <==> str(x) |
Method Details |
---|
__init__(self,
path)
Initialize factory.
|
__call__(self)
Create the Locale.
|
_extractCalendars(self, dates_node)Extract all calendars and their specific information from the Locale's DOM tree. Example:>>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <dates> ... <calendars> ... <calendar type="gregorian"> ... <monthNames> ... <month type="1">January</month> ... <month type="12">December</month> ... </monthNames> ... <monthAbbr> ... <month type="1">Jan</month> ... <month type="12">Dec</month> ... </monthAbbr> ... <dayNames> ... <day type="sun">Sunday</day> ... <day type="sat">Saturday</day> ... </dayNames> ... <dayAbbr> ... <day type="sun">Sun</day> ... <day type="sat">Sat</day> ... </dayAbbr> ... <week> ... <minDays count="1"/> ... <firstDay day="sun"/> ... </week> ... <am>AM</am> ... <pm>PM</pm> ... <eras> ... <eraAbbr> ... <era type="0">BC</era> ... <era type="1">AD</era> ... </eraAbbr> ... </eras> ... <dateFormats> ... <dateFormatLength type="full"> ... <dateFormat> ... <pattern>EEEE, MMMM d, yyyy</pattern> ... </dateFormat> ... </dateFormatLength> ... </dateFormats> ... <timeFormats> ... <default type="medium"/> ... <timeFormatLength type="medium"> ... <timeFormat> ... <pattern>h:mm:ss a</pattern> ... </timeFormat> ... </timeFormatLength> ... </timeFormats> ... <dateTimeFormats> ... <dateTimeFormatLength> ... <dateTimeFormat> ... <pattern>{0} {1}</pattern> ... </dateTimeFormat> ... </dateTimeFormatLength> ... </dateTimeFormats> ... </calendar> ... <calendar type="thai-buddhist"> ... <eras> ... <era type="0">BE</era> ... </eras> ... </calendar> ... </calendars> ... </dates>''' >>> dom = parseString(xml) >>> calendars = factory._extractCalendars(dom.documentElement) >>> keys = calendars.keys() >>> keys.sort() >>> keys [u'gregorian', u'thai-buddhist'] |
_extractCurrencies(self, numbers_node)Extract all currency definitions and their information from the Locale's DOM tree. Example:>>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <numbers> ... <currencies> ... <currency type="USD"> ... <displayName>Dollar</displayName> ... <symbol>$</symbol> ... </currency> ... <currency type ="JPY"> ... <displayName>Yen</displayName> ... <symbol>Y</symbol> ... </currency> ... <currency type ="INR"> ... <displayName>Rupee</displayName> ... <symbol choice="true">0<=Rf|1<=Ru|1<Rf</symbol> ... </currency> ... <currency type="PTE"> ... <displayName>Escudo</displayName> ... <symbol>$</symbol> ... </currency> ... </currencies> ... </numbers>''' >>> dom = parseString(xml) >>> currencies = factory._extractCurrencies(dom.documentElement) >>> keys = currencies.keys() >>> keys.sort() >>> keys [u'INR', u'JPY', u'PTE', u'USD'] >>> currencies['USD'].symbol u'$' >>> currencies['USD'].displayName u'Dollar' >>> currencies['USD'].symbolChoice False |
_extractDates(self)Extract all date information from the DOM tree |
_extractDays(self, cal_node, calendar)Extract all day entries from cal_node and store them in calendar. Example:>>> class CalendarStub(object): ... days = None >>> calendar = CalendarStub() >>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <calendar type="gregorian"> ... <dayNames> ... <day type="sun">Sonntag</day> ... <day type="mon">Montag</day> ... <day type="tue">Dienstag</day> ... <day type="wed">Mittwoch</day> ... <day type="thu">Donnerstag</day> ... <day type="fri">Freitag</day> ... <day type="sat">Samstag</day> ... </dayNames> ... <dayAbbr> ... <day type="sun">So</day> ... <day type="mon">Mo</day> ... <day type="tue">Di</day> ... <day type="wed">Mi</day> ... <day type="thu">Do</day> ... <day type="fri">Fr</day> ... <day type="sat">Sa</day> ... </dayAbbr> ... </calendar>''' >>> dom = parseString(xml) >>> factory._extractDays(dom.documentElement, calendar) >>> names = [calendar.days.get(type, (None, None))[0] ... for type in range(1, 8)] >>> names[:4] [u'Montag', u'Dienstag', u'Mittwoch', u'Donnerstag'] >>> names[4:] [u'Freitag', u'Samstag', u'Sonntag'] >>> abbrs = [calendar.days.get(type, (None, None))[1] ... for type in range(1, 8)] >>> abbrs [u'Mo', u'Di', u'Mi', u'Do', u'Fr', u'Sa', u'So'] |
_extractDelimiters(self)Extract all delimiter entries from the DOM tree. Example:>>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <ldml> ... <delimiters> ... <quotationStart>``</quotationStart> ... <quotationEnd>''</quotationEnd> ... <alternateQuotationStart>`</alternateQuotationStart> ... <alternateQuotationEnd>'</alternateQuotationEnd> ... </delimiters> ... </ldml>''' >>> dom = parseString(xml) >>> factory._data = parseString(xml).documentElement >>> delimiters = factory._extractDelimiters() >>> delimiters[u'quotationStart'] u'``' >>> delimiters[u'quotationEnd'] u"''" >>> delimiters[u'alternateQuotationStart'] u'`' >>> delimiters[u'alternateQuotationEnd'] u"'" Escape: "'" |
_extractDisplayNames(self)Extract all display names from the DOM tree. Example:>>> from xml.dom.minidom import parseString >>> xml = u''' ... <ldml> ... <localeDisplayNames> ... <languages> ... <language type="Fallback"></language> ... <language type="aa">aa</language> ... <language type="ab">ab</language> ... </languages> ... <scripts> ... <script type="Arab">Arab</script> ... <script type="Armn">Armn</script> ... </scripts> ... <territories> ... <territory type="AD">AD</territory> ... <territory type="AE">AE</territory> ... </territories> ... <variants> ... <variant type="Fallback"></variant> ... <variant type="POSIX">POSIX</variant> ... </variants> ... <keys> ... <key type="calendar">CALENDAR</key> ... <key type="collation">COLLATION</key> ... </keys> ... <types> ... <type type="buddhist" key="calendar">BUDDHIST</type> ... <type type="stroke" key="collation">STROKE</type> ... </types> ... </localeDisplayNames> ... </ldml>''' >>> factory = LocaleFactory(None) >>> factory._data = parseString(xml).documentElement >>> names = factory._extractDisplayNames() >>> keys = names.languages.keys() >>> keys.sort() >>> keys [u'Fallback', u'aa', u'ab'] >>> names.languages[u'aa'] u'aa' >>> keys = names.scripts.keys() >>> keys.sort() >>> keys [u'Arab', u'Armn'] >>> names.scripts[u'Arab'] u'Arab' >>> keys = names.territories.keys() >>> keys.sort() >>> keys [u'AD', u'AE'] >>> names.territories[u'AD'] u'AD' >>> keys = names.variants.keys() >>> keys.sort() >>> keys [u'Fallback', u'POSIX'] >>> names.variants[u'Fallback'] u'' >>> keys = names.keys.keys() >>> keys.sort() >>> keys [u'calendar', u'collation'] >>> names.keys[u'calendar'] u'CALENDAR' >>> names.types[(u'stroke', u'collation')] u'STROKE' |
_extractEras(self, cal_node, calendar)Extract all era entries from cal_node and store them in calendar. Example:>>> class CalendarStub(object): ... days = None >>> calendar = CalendarStub() >>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <calendar type="gregorian"> ... <eras> ... <eraAbbr> ... <era type="0">BC</era> ... <era type="1">AD</era> ... </eraAbbr> ... <eraName> ... <era type="0">Before Christ</era> ... </eraName> ... </eras> ... </calendar>''' >>> dom = parseString(xml) >>> factory._extractEras(dom.documentElement, calendar) >>> names = [calendar.eras.get(type, (None, None))[0] ... for type in range(2)] >>> names [u'Before Christ', None] >>> abbrs = [calendar.eras.get(type, (None, None))[1] ... for type in range(2)] >>> abbrs [u'BC', u'AD'] |
_extractFormats(self, formats_node, lengthNodeName, formatNodeName)Extract all format entries from formats_node and return a tuple of the form (defaultFormatType, [LocaleFormatLength, ...]). Example:>>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <dateFormats> ... <default type="medium"/> ... <dateFormatLength type="full"> ... <dateFormat> ... <pattern>EEEE, MMMM d, yyyy</pattern> ... </dateFormat> ... </dateFormatLength> ... <dateFormatLength type="medium"> ... <default type="DateFormatsKey2"/> ... <dateFormat type="DateFormatsKey2"> ... <displayName>Standard Date</displayName> ... <pattern>MMM d, yyyy</pattern> ... </dateFormat> ... <dateFormat type="DateFormatsKey3"> ... <pattern>MMM dd, yyyy</pattern> ... </dateFormat> ... </dateFormatLength> ... </dateFormats>''' >>> dom = parseString(xml) >>> default, lengths = factory._extractFormats( ... dom.documentElement, 'dateFormatLength', 'dateFormat') >>> default u'medium' >>> lengths[u'full'].formats[None].pattern u'EEEE, MMMM d, yyyy' >>> lengths[u'medium'].default u'DateFormatsKey2' >>> lengths[u'medium'].formats['DateFormatsKey3'].pattern u'MMM dd, yyyy' >>> lengths[u'medium'].formats['DateFormatsKey2'].displayName u'Standard Date' |
_extractIdentity(self)Extract the Locale's identity object based on info from the DOM tree. Example:>>> from xml.dom.minidom import parseString >>> xml = u''' ... <ldml> ... <identity> ... <version number="1.0"/> ... <generation date="2003-12-19" /> ... <language type="en" /> ... <territory type="US" /> ... <variant type="POSIX" /> ... </identity> ... </ldml>''' >>> factory = LocaleFactory(None) >>> factory._data = parseString(xml).documentElement >>> id = factory._extractIdentity() >>> id.language u'en' >>> id.script is None True >>> id.territory u'US' >>> id.variant u'POSIX' >>> id.version.number u'1.0' |
_extractMonths(self, cal_node, calendar)Extract all month entries from cal_node and store them in calendar. Example:>>> class CalendarStub(object): ... months = None >>> calendar = CalendarStub() >>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <calendar type="gregorian"> ... <monthNames> ... <month type="1">Januar</month> ... <month type="2">Februar</month> ... <month type="3">Maerz</month> ... <month type="4">April</month> ... <month type="5">Mai</month> ... <month type="6">Juni</month> ... <month type="7">Juli</month> ... <month type="8">August</month> ... <month type="9">September</month> ... <month type="10">Oktober</month> ... <month type="11">November</month> ... <month type="12">Dezember</month> ... </monthNames> ... <monthAbbr> ... <month type="1">Jan</month> ... <month type="2">Feb</month> ... <month type="3">Mrz</month> ... <month type="4">Apr</month> ... <month type="5">Mai</month> ... <month type="6">Jun</month> ... <month type="7">Jul</month> ... <month type="8">Aug</month> ... <month type="9">Sep</month> ... <month type="10">Okt</month> ... <month type="11">Nov</month> ... <month type="12">Dez</month> ... </monthAbbr> ... </calendar>''' >>> dom = parseString(xml) >>> factory._extractMonths(dom.documentElement, calendar) >>> names = [calendar.months.get(type, (None, None))[0] ... for type in range(1, 13)] >>> names[:7] [u'Januar', u'Februar', u'Maerz', u'April', u'Mai', u'Juni', u'Juli'] >>> names[7:] [u'August', u'September', u'Oktober', u'November', u'Dezember'] >>> abbrs = [calendar.months.get(type, (None, None))[1] ... for type in range(1, 13)] >>> abbrs[:6] [u'Jan', u'Feb', u'Mrz', u'Apr', u'Mai', u'Jun'] >>> abbrs[6:] [u'Jul', u'Aug', u'Sep', u'Okt', u'Nov', u'Dez'] |
_extractNumberFormats(self, numbers_node, numbers)Extract all number formats from the numbers_node and save the data in numbers. Example:>>> class Numbers(object): ... defaultDecimalFormat = None ... decimalFormats = None ... defaultScientificFormat = None ... scientificFormats = None ... defaultPercentFormat = None ... percentFormats = None ... defaultCurrencyFormat = None ... currencyFormats = None >>> numbers = Numbers() >>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <numbers> ... <decimalFormats> ... <decimalFormatLength type="long"> ... <decimalFormat> ... <pattern>#,##0.###</pattern> ... </decimalFormat> ... </decimalFormatLength> ... </decimalFormats> ... <scientificFormats> ... <default type="long"/> ... <scientificFormatLength type="long"> ... <scientificFormat> ... <pattern>0.000###E+00</pattern> ... </scientificFormat> ... </scientificFormatLength> ... <scientificFormatLength type="medium"> ... <scientificFormat> ... <pattern>0.00##E+00</pattern> ... </scientificFormat> ... </scientificFormatLength> ... </scientificFormats> ... <percentFormats> ... <percentFormatLength type="long"> ... <percentFormat> ... <pattern>#,##0%</pattern> ... </percentFormat> ... </percentFormatLength> ... </percentFormats> ... <currencyFormats> ... <currencyFormatLength type="long"> ... <currencyFormat> ... <pattern>$ #,##0.00;($ #,##0.00)</pattern> ... </currencyFormat> ... </currencyFormatLength> ... </currencyFormats> ... </numbers>''' >>> dom = parseString(xml) >>> factory._extractNumberFormats(dom.documentElement, numbers) >>> numbers.decimalFormats[u'long'].formats[None].pattern u'#,##0.###' >>> numbers.defaultScientificFormat u'long' >>> numbers.scientificFormats[u'long'].formats[None].pattern u'0.000###E+00' >>> numbers.scientificFormats[u'medium'].formats[None].pattern u'0.00##E+00' >>> numbers.percentFormats[u'long'].formats[None].pattern u'#,##0%' >>> numbers.percentFormats.get(u'medium', None) is None True >>> numbers.currencyFormats[u'long'].formats[None].pattern u'$ #,##0.00;($ #,##0.00)' >>> numbers.currencyFormats.get(u'medium', None) is None True |
_extractNumbers(self)Extract all number information from the DOM tree |
_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' |
_extractSymbols(self, numbers_node)Extract all week entries from cal_node and store them in calendar. Example:>>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <numbers> ... <symbols> ... <decimal>.</decimal> ... <group>,</group> ... <list>;</list> ... <percentSign>%</percentSign> ... <nativeZeroDigit>0</nativeZeroDigit> ... <patternDigit>#</patternDigit> ... <plusSign>+</plusSign> ... <minusSign>-</minusSign> ... <exponential>E</exponential> ... <perMille>o/oo</perMille> ... <infinity>oo</infinity> ... <nan>NaN</nan> ... </symbols> ... </numbers>''' >>> dom = parseString(xml) >>> symbols = factory._extractSymbols(dom.documentElement) >>> symbols['list'] u';' >>> keys = symbols.keys() >>> keys.sort() >>> keys[:5] [u'decimal', u'exponential', u'group', u'infinity', u'list'] >>> keys[5:9] [u'minusSign', u'nan', u'nativeZeroDigit', u'patternDigit'] >>> keys[9:] [u'perMille', u'percentSign', u'plusSign'] |
_extractTimeZones(self, dates_node)Extract all timezone information for the locale from the DOM tree. Example:>>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <dates> ... <timeZoneNames> ... <zone type="America/Los_Angeles" > ... <long> ... <generic>Pacific Time</generic> ... <standard>Pacific Standard Time</standard> ... <daylight>Pacific Daylight Time</daylight> ... </long> ... <short> ... <generic>PT</generic> ... <standard>PST</standard> ... <daylight>PDT</daylight> ... </short> ... <exemplarCity>San Francisco</exemplarCity> ... </zone> ... <zone type="Europe/London"> ... <long> ... <generic>British Time</generic> ... <standard>British Standard Time</standard> ... <daylight>British Daylight Time</daylight> ... </long> ... <exemplarCity>York</exemplarCity> ... </zone> ... </timeZoneNames> ... </dates>''' >>> dom = parseString(xml) >>> zones = factory._extractTimeZones(dom.documentElement) >>> keys = zones.keys() >>> keys.sort() >>> keys [u'America/Los_Angeles', u'Europe/London'] >>> zones[u'Europe/London'].names[u'generic'] (u'British Time', None) >>> zones[u'Europe/London'].cities [u'York'] >>> zones[u'America/Los_Angeles'].names[u'generic'] (u'Pacific Time', u'PT') |
_extractTypes(self, names_node)Extract all types from the names_node. Example:>>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <displayNames> ... <types> ... <type type="Fallback" key="calendar"></type> ... <type type="buddhist" key="calendar">BUDDHIST</type> ... <type type="chinese" key="calendar">CHINESE</type> ... <type type="gregorian" key="calendar">GREGORIAN</type> ... <type type="stroke" key="collation">STROKE</type> ... <type type="traditional" key="collation">TRADITIONAL</type> ... </types> ... </displayNames>''' >>> dom = parseString(xml) >>> types = factory._extractTypes(dom.documentElement) >>> keys = types.keys() >>> keys.sort() >>> keys[:2] [(u'Fallback', u'calendar'), (u'buddhist', u'calendar')] >>> keys[2:4] [(u'chinese', u'calendar'), (u'gregorian', u'calendar')] >>> keys[4:] [(u'stroke', u'collation'), (u'traditional', u'collation')] >>> types[(u'chinese', u'calendar')] u'CHINESE' >>> types[(u'stroke', u'collation')] u'STROKE' |
_extractVersion(self, identity_node)Extract the Locale's version info based on data from the DOM tree. Example:>>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <identity> ... <version number="1.0">Some notes</version> ... <generation date="2003-12-19" /> ... <language type="de" /> ... <territory type="DE" /> ... </identity>''' >>> dom = parseString(xml) >>> version = factory._extractVersion(dom.documentElement) >>> version.number u'1.0' >>> version.generationDate datetime.date(2003, 12, 19) >>> version.notes u'Some notes' |
_extractWeek(self, cal_node, calendar)Extract all week entries from cal_node and store them in calendar. Example:>>> class CalendarStub(object): ... week = None >>> calendar = CalendarStub() >>> factory = LocaleFactory(None) >>> from xml.dom.minidom import parseString >>> xml = u''' ... <calendar type="gregorian"> ... <week> ... <minDays count="1"/> ... <firstDay day="sun"/> ... <weekendStart day="fri" time="18:00"/> ... <weekendEnd day="sun" time="18:00"/> ... </week> ... </calendar>''' >>> dom = parseString(xml) >>> factory._extractWeek(dom.documentElement, calendar) >>> calendar.week['minDays'] 1 >>> calendar.week['firstDay'] 7 >>> calendar.week['weekendStart'] (5, datetime.time(18, 0)) >>> calendar.week['weekendEnd'] (7, datetime.time(18, 0)) |
Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Fri Jun 24 12:01:22 2005 | http://epydoc.sf.net |