zopefoundation / zope.configuration

Extensible system for supporting various kinds of configurations
https://zopeconfiguration.readthedocs.io
Other
1 stars 6 forks source link

MessageID broken for Python 3; produces byte domains which can't find utilities #17

Closed jamadden closed 7 years ago

jamadden commented 7 years ago

As discovered in zope.app.form, when reading a MessageID field out of a ZCML file, the domain will be a byte string under Python 3 (e.g., b'zope'). But zope.i18n registers ITranslationDomain utilities with normal str names. Since no byte string can ever equal a str on Python 3, the utilities will never be found and translation will not happen.

It seems to me that either MessageID should ensure that the domain is a str (decoding from...utf-8?) or the context itself could ensure that its i18n_domain is a str. I think I like the latter better.

jamadden commented 7 years ago

It looks like the IZopeConfigure schema defines i18n_domain as a BytesLine because it's meant to deal with the filesystem. That's probably not really correct on Python 3, when paths changed to be decoded strs (though bytes are often still accepted by the path APIs).

So it seems the simplest change will be to handle this in MessageID, and use sys.getfilesystemencoding to handle the decoding.