Normalizing ids

Normalizers turns arbitary string (with unicode letters) to machine friendly ASCII ids. Plone provides different id normalizers.

E.g:

åland -> aland

Plone has conversion utilies for

  • For URIs and URLs (plone.i18n.normalizer.interfaces.IURLNormalizer)
  • For filenames
  • For HTML ids and CSS

Normalization depends on the locale. E.g. in English “Š” will be normalized as “ae” but in Finnish it will be normalized “å” -> “a”.

See`plone.i18n.normalizers package <http://svn.plone.org/svn/plone/plone.i18n/trunk/plone/i18n/normalizer/__init__.py>`_.

Examples

Simple example for CSS id:

from zope.component import getUtility
from plone.i18n.normalizer.interfaces import IIDNormalizer

normalizer = getUtility(IIDNormalizer)
id = "portlet-static-%s" % normalizer.normalize(header)

Hard-coded id localizer which directly uses class instance and does not allow override by utility configuration. You can use normalizers this way also when getUtility() is not available (e.g. start up code):

from plone.i18n.normalizer import idnormalizer

id = idnormalizer.normalize(u"ÅÄÖrjy")

Language specific example for URL:

from zope.component import getUtility
from plone.i18n.normalizer.interfaces import IURLNormalizer

util = queryUtility(IURLNormalizer, name="el")

To see available language specific localizers, see the source code of plone.i18n.normalizers package.

More examples:

Creating ids programmatically

If you are creating content programmatically using invokeFactory() you need to provide the id yourself. Below is an example how to generate id from a title.

Table Of Contents

Previous topic

Dynamic views

Next topic

Behaviors

This Page