Back to index

plone3  3.1.7
de.py
Go to the documentation of this file.
00001 # -*- coding: UTF-8 -*-
00002 
00003 from plone.i18n.normalizer.interfaces import INormalizer
00004 from zope.interface import implements
00005 from plone.i18n.normalizer.base import mapUnicode
00006 
00007 # German character mapping
00008 mapping = {
00009     196 : 'AE', 198 : 'AE', 214 : 'OE', 220 : 'UE', 223 : 'ss', 224 : 'a',
00010     228 : 'ae', 230 : 'ae', 246 : 'oe', 252 : 'ue'
00011 }
00012 
00013 class Normalizer(object):
00014     """
00015     This normalizer can normalize any unicode string and returns a version
00016     that only contains of ASCII characters.
00017 
00018     Let's make sure that this implementation actually fulfills the API.
00019 
00020       >>> from zope.interface.verify import verifyClass
00021       >>> verifyClass(INormalizer, Normalizer)
00022       True
00023 
00024       >>> norm = Normalizer()
00025       >>> norm.normalize(u'\xe4')
00026       'ae'
00027     """
00028     implements(INormalizer)
00029 
00030     def normalize(self, text, locale=None, max_length=None):
00031         """
00032         Returns a normalized text. text has to be a unicode string.
00033         """
00034         return mapUnicode(text, mapping=mapping)
00035 
00036 normalizer = Normalizer()