[Zope3-checkins] CVS: Zope3/src/zope/i18n - negotiator.py:1.7

Sidnei da Silva sidnei at x3ng.com.br
Fri Feb 27 12:49:13 EST 2004


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

Modified Files:
	negotiator.py 
Log Message:
Merge fixes for Negotiator handling of available languages check against preferred languages


=== Zope3/src/zope/i18n/negotiator.py 1.6 => 1.7 ===
--- Zope3/src/zope/i18n/negotiator.py:1.6	Fri Jun  6 15:29:09 2003
+++ Zope3/src/zope/i18n/negotiator.py	Fri Feb 27 12:48:42 2004
@@ -21,6 +21,21 @@
 from zope.component import getAdapter
 from zope.interface import implements
 
+def normalize_lang(lang):
+    lang = lang.strip().lower()
+    lang = lang.replace('_', '-')
+    lang = lang.replace(' ', '')
+    return lang
+
+def normalize_langs(langs):
+    # Make a mapping from normalized->original
+    # so we keep can match the normalized lang
+    # and return the original string.
+    n_langs = {}
+    for l in langs:
+        n_langs[normalize_lang(l)] = l
+    return n_langs
+
 class Negotiator:
 
     implements(INegotiator)
@@ -30,9 +45,10 @@
         userlangs = envadapter.getPreferredLanguages()
         # Prioritize on the user preferred languages.  Return the first user
         # preferred language that the object has available.
+        langs = normalize_langs(langs)
         for lang in userlangs:
             if lang in langs:
-                return lang
+                return langs.get(lang)
         return None
 
 




More information about the Zope3-Checkins mailing list