Back to index

plone3  3.1.7
el.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 # Greek character mapping
00008 mapping = {
00009     902: 'A', 904: 'E', 905: 'H', 906: 'I', 908: 'O', 910: 'Y', 911: 'O',
00010     912: 'i', 913: 'A', 914: 'B', 915: 'G', 916: 'D', 917: 'E', 918: 'Z',
00011     919: 'I', 920: 'Th', 921: 'I', 922: 'K', 923: 'L', 924: 'M', 925: 'N',
00012     926: 'Ks', 927: 'O', 928: 'P', 929: 'R', 931: 'S', 932: 'T', 933: 'Y',
00013     934: 'F', 935: 'Ch', 936: 'Ps', 937: 'O', 938: 'I', 939: 'Y', 940: 'a', 
00014     941: 'e', 942: 'i', 943: 'i', 944: 'y', 945: 'a', 946: 'b', 947: 'g', 
00015     948: 'd', 949: 'e', 950: 'z', 951: 'i', 952: 'th', 953: 'i', 954: 'k', 
00016     955: 'l', 956: 'm', 957: 'n', 958: 'ks', 959: 'o', 960: 'p', 961: 'r', 
00017     962: 's', 963: 's', 964: 't', 965: 'y', 966: 'f', 967:'ch', 968: 'ps', 
00018     969: 'o', 970: 'i', 971: 'y', 972: 'o', 973: 'y', 974: 'o',
00019 }
00020 
00021 class Normalizer(object):
00022     """
00023     This normalizer can normalize any unicode string and returns a version
00024     that only contains of ASCII characters.
00025 
00026     Let's make sure that this implementation actually fulfills the API.
00027 
00028       >>> from zope.interface.verify import verifyClass
00029       >>> verifyClass(INormalizer, Normalizer)
00030       True
00031 
00032       >>> norm = Normalizer()
00033       >>> norm.normalize(u'\u03b9')
00034       'i'
00035     """
00036     implements(INormalizer)
00037 
00038     def normalize(self, text, locale=None, max_length=None):
00039         """
00040         Returns a normalized text. text has to be a unicode string.
00041         """
00042         return mapUnicode(text, mapping=mapping)
00043 
00044 normalizer = Normalizer()