How to use a utility in a vocabulary definition?

I am creating a vocabulary for a Add-on. This vocabulary is based on a list of unicode strings. From the list, each vocabulary term will get their title, but the token and value are going to be a (ASCII) normalized form of the title.

I thought about using the plone.i18n URLNormalizer at the vocabulary definition code. So, in my add-on configure zcml, I have this:


In the module, I have this:

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

# Get URL normalizer for language portuguese
util = queryUtility(IURLNormalizer, name="pt")

class MyVocabulary(object):


    def __call__(self,context):
        from operator import itemgetter
        newlist = sorted(list_of_strings, key=itemgetter('title'))
        items = []
        for i in newlist:
        return SimpleVocabulary(items)

The problem is that the queryUtility function is not returning the normalizer (it returns None). If I try this code with instance debug, it works correctly. The problem only happens in instance fg.

I am guessing the normalizer is being registered after the vocabulary, but I have no idea on how to investigate (or solve) that problem.

Can anyone give me a light on this?

Can't you move the util = queryUtility(IURLNormalizer, name="pt") inside the __call__?

util is loaded during import time, zcml configuration like the one that installs the utility which provides IURLNormalizer is only registered after that.

Get the utility within the call method.