[Zope3-checkins] CVS: Zope3/src/zope/i18n - format.py:1.13
translate.py:1.9 interfaces.py:NONE
Stephan Richter
srichter at cosmos.phy.tufts.edu
Thu Feb 5 17:52:53 EST 2004
Update of /cvs-repository/Zope3/src/zope/i18n
In directory cvs.zope.org:/tmp/cvs-serv7674/src/zope/i18n
Modified Files:
format.py translate.py
Removed Files:
interfaces.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.
=== Zope3/src/zope/i18n/format.py 1.12 => 1.13 ===
--- Zope3/src/zope/i18n/format.py:1.12 Tue Sep 23 22:57:11 2003
+++ Zope3/src/zope/i18n/format.py Thu Feb 5 17:52:21 2004
@@ -89,17 +89,20 @@
# Handle months
if ('M', 3) in bin_pattern:
abbr = results[bin_pattern.index(('M', 3))]
- ordered[1] = self.calendar.getMonthIdFromAbbr(abbr)
+ ordered[1] = self.calendar.getMonthTypeFromAbbreviation(abbr)
if ('M', 4) in bin_pattern:
name = results[bin_pattern.index(('M', 4))]
- ordered[1] = self.calendar.getMonthIdFromName(name)
+ ordered[1] = self.calendar.getMonthTypeFromName(name)
# Handle AM/PM hours
for length in (1, 2):
id = ('h', length)
if id in bin_pattern:
+ hour = int(results[bin_pattern.index(id)])
ampm = self.calendar.pm == results[
bin_pattern.index(('a', 1))]
- ordered[3] = (int(results[bin_pattern.index(id)]) + 12*ampm)%24
+ if hour == 12:
+ ampm = not ampm
+ ordered[3] = (hour + 12*ampm)%24
# Shortcut for the simple int functions
dt_fields_map = {'M': 1, 'd': 2, 'H': 3, 'm': 4, 's': 5, 'S': 6}
for field in dt_fields_map.keys():
@@ -204,8 +207,10 @@
if bin_pattern[sign][EXPONENTIAL] != '':
regex += self.symbols['exponential']
min_exp_size = bin_pattern[sign][EXPONENTIAL].count('0')
- regex += '[%s]?[0-9]{%i,100}' %(self.symbols['minusSign'],
- min_exp_size)
+ pre_symbols = self.symbols['minusSign']
+ if bin_pattern[sign][EXPONENTIAL][0] == '+':
+ pre_symbols += self.symbols['plusSign']
+ regex += '[%s]?[0-9]{%i,100}' %(pre_symbols, min_exp_size)
regex +=')'
if bin_pattern[sign][PADDING3] is not None:
regex += '[' + bin_pattern[sign][PADDING3] + ']+'
@@ -270,6 +275,13 @@
if bin_pattern[EXPONENTIAL] != '':
obj_int_frac = str(obj).split('.')
+ # The exponential might have a mandatory sign; remove it from the
+ # bin_pattern and remember the setting
+ exp_bin_pattern = bin_pattern[EXPONENTIAL]
+ plus_sign = u''
+ if exp_bin_pattern.startswith('+'):
+ plus_sign = self.symbols['plusSign']
+ exp_bin_pattern = exp_bin_pattern[1:]
# We have to remove the possible '-' sign
if obj < 0:
obj_int_frac[0] = obj_int_frac[0][1:]
@@ -278,23 +290,27 @@
if len(obj_int_frac) > 1:
res = re.match('(0*)[0-9]*', obj_int_frac[1]).groups()[0]
exponent = self._format_integer(str(len(res)+1),
- bin_pattern[EXPONENTIAL])
+ exp_bin_pattern)
exponent = self.symbols['minusSign']+exponent
number = obj_int_frac[1][len(res):]
else:
# We have exactly 0
- exponent = self._format_integer('0',
- bin_pattern[EXPONENTIAL])
+ exponent = self._format_integer('0', exp_bin_pattern)
number = self.symbols['nativeZeroDigit']
else:
exponent = self._format_integer(str(len(obj_int_frac[0])-1),
- bin_pattern[EXPONENTIAL])
+ exp_bin_pattern)
number = ''.join(obj_int_frac)
number = number[0] + self._format_fraction(number[1:],
bin_pattern[FRACTION])
+
+ # We might have a plus sign in front of the exponential integer
+ if not exponent.startswith('-'):
+ exponent = plus_sign + exponent
+
pre_padding = len(bin_pattern[FRACTION]) - len(number) + 2
- post_padding = len(bin_pattern[EXPONENTIAL]) - len(exponent)
+ post_padding = len(exp_bin_pattern) - len(exponent)
number += self.symbols['exponential'] + exponent
else:
@@ -338,7 +354,8 @@
if bin_pattern[PADDING4] is not None and post_padding > 0:
text += bin_pattern[PADDING4]*post_padding
- return text
+ # XXX: Need to make sure unicode is everywhere
+ return unicode(text)
@@ -439,19 +456,20 @@
It also depends on the locale of course."""
return {
('a', 1): r'(%s|%s)' %(calendar.am, calendar.pm),
- ('G', 1): r'(%s|%s)' %(calendar.eras[0], calendar.eras[1]),
+ # XXX: works for gregorian only right now
+ ('G', 1): r'(%s|%s)' %(calendar.eras[1][1], calendar.eras[2][1]),
('y', 2): r'([0-9]{2})',
('y', 4): r'([0-9]{4})',
('M', 1): r'([0-9]{1,2})',
('M', 2): r'([0-9]{2})',
- ('M', 3): r'('+'|'.join(calendar.getMonthAbbr())+')',
+ ('M', 3): r'('+'|'.join(calendar.getMonthAbbreviations())+')',
('M', 4): r'('+'|'.join(calendar.getMonthNames())+')',
('d', 1): r'([0-9]{1,2})',
('d', 2): r'([0-9]{2})',
('E', 1): r'([0-9])',
('E', 2): r'([0-9]{2})',
- ('E', 3): r'('+'|'.join(calendar.getWeekdayAbbr())+')',
- ('E', 4): r'('+'|'.join(calendar.getWeekdayNames())+')',
+ ('E', 3): r'('+'|'.join(calendar.getDayAbbreviations())+')',
+ ('E', 4): r'('+'|'.join(calendar.getDayNames())+')',
('D', 1): r'([0-9]{1,3})',
('w', 1): r'([0-9])',
('w', 2): r'([0-9]{2})',
@@ -499,7 +517,7 @@
if h == 0:
h = 12
- weekday = (dt.weekday()+1) % 7 + 1
+ weekday = dt.weekday()+1
return {
('a', 1): ampm,
@@ -512,10 +530,10 @@
('M', 4): calendar.months[dt.month][0],
('d', 1): str(dt.day),
('d', 2): "%.2i" %dt.day,
- ('E', 1): str(dt.weekday),
- ('E', 2): "%.2i" %dt.weekday(),
- ('E', 3): calendar.weekdays[weekday][1],
- ('E', 4): calendar.weekdays[weekday][0],
+ ('E', 1): str(weekday),
+ ('E', 2): "%.2i" %weekday,
+ ('E', 3): calendar.days[weekday][1],
+ ('E', 4): calendar.days[weekday][0],
('D', 1): dt.strftime('%j'),
('w', 1): dt.strftime('%W'),
('w', 2): dt.strftime('%.2W'),
@@ -688,7 +706,7 @@
state = READ_SUFFIX
elif state == READ_EXPONENTIAL:
- if char == "#" or char == "0":
+ if char in ('0', '#', '+'):
helper += char
elif char == "*":
exponential = helper
=== Zope3/src/zope/i18n/translate.py 1.8 => 1.9 ===
--- Zope3/src/zope/i18n/translate.py:1.8 Fri Jun 6 15:29:09 2003
+++ Zope3/src/zope/i18n/translate.py Thu Feb 5 17:52:21 2004
@@ -11,11 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""
+"""Translator
$Id$
"""
-
from zope.i18n.interfaces import ITranslator
from zope.component import getService
from zope.interface import implements
=== Removed File Zope3/src/zope/i18n/interfaces.py ===
More information about the Zope3-Checkins
mailing list