[Zope3-checkins] CVS: Zope3/src/zope/i18n - interfaces.py:1.18 locales.py:1.16

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Sep 16 18:06:43 EDT 2003


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

Modified Files:
	interfaces.py locales.py 
Log Message:
Made currencies usable.


=== Zope3/src/zope/i18n/interfaces.py 1.17 => 1.18 ===
--- Zope3/src/zope/i18n/interfaces.py:1.17	Tue Aug 12 15:11:11 2003
+++ Zope3/src/zope/i18n/interfaces.py	Tue Sep 16 18:06:42 2003
@@ -535,8 +535,11 @@
 
     def getNumberFormatter(name):
         """Get the NumberFormat object called 'name'. The following names are
-        recognized: decimal, percent, scientific, currency."""
+        recognized: decimal, percent, scientific."""
 
+    def getCurrencyFormatter(name=None):
+        """Get a specific currecny formatter object. If name is None, choose
+        the default currency formatter."""
 
 
 class IFormat(Interface):


=== Zope3/src/zope/i18n/locales.py 1.15 => 1.16 ===
--- Zope3/src/zope/i18n/locales.py:1.15	Sat Jul 26 09:11:14 2003
+++ Zope3/src/zope/i18n/locales.py	Tue Sep 16 18:06:42 2003
@@ -461,10 +461,35 @@
 
         return NumberFormat(pattern, symbols)
 
-    def getDateFormat(self, name):
-        """Get the DateFormat object called 'name'. The following names are
-        recognized: full, long, medium, short."""
-        raise NotImplementedError
+
+    def getCurrencyFormatter(self, name=None):
+        "See ZopeProducts.LocaleProvider.interfaces.ILocale"
+        if name is not None:
+            try:
+                currency = self.currencies[name]
+            except (AttributeError, KeyError):
+                currency = None
+        else:
+            currency = self.getDefaultCurrency()
+
+        if currency is None:
+            return self._getNextLocale().getCurrencyFormatter(name)
+
+        symbols = {}
+        for id in ((None, None, None),
+                   (self.id.language, None, None),
+                   (self.id.language, self.id.country, None),
+                   (self.id.language, self.id.country,
+                    self.id.variant)):
+            try:
+                format = locales.getLocale(*id).getDefaultNumberFormat()
+                symbols.update(format.symbols)
+            except (AttributeError, KeyError):
+                pass # Locale has no number format information
+        if currency.decimal:
+            symbols['decimal'] = currency.decimal
+
+        return NumberFormat(currency.pattern, symbols)
 
 
 class XMLLocaleFactory:




More information about the Zope3-Checkins mailing list