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:
<utility
factory=".vocabularies.MyVocabulary"
name="my.product.vocabulary"
/>
In the vocabularies.py 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):
implements(IVocabularyFactory)
def __call__(self,context):
from operator import itemgetter
newlist = sorted(list_of_strings, key=itemgetter('title'))
items = []
for i in newlist:
title=i['title']
token=util.normalize(title)
value=token
items.append(SimpleTerm(value,token,title))
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?