This is a note to my and @agitator's future self and anyone to whom it may concerns.
I have a year field and Plone renders it in German as as 2.021.
My customer dislikes the dot in there.
z3c.form uses a dataconverter to localize the output of number fields, such as int, float, decimal.
At the end, the dataconverter uses the locale formatters from zope.i18n.locales and those are having inheriting XML-definitions for de or de_AT.
The definitions are loaded there.
So how to change them?
Answer:
copy the xml-file from zope.i18n.locales.data to your projects root,
for my case change the numbers group value to empty:
widgets.py
# -*- coding: utf-8 -*-
from zope.component import adapter
from zope.interface import implementer
from zope.interface import Interface
from zope.schema.interfaces import IField
from z3c.form.interfaces import IFieldWidget
from z3c.form.browser.text import TextWidget
from z3c.form.widget import FieldWidget
class IIntNoFormatWidget(Interface):
""" Marker interface for custom number field without comma formatting
"""
pass
@implementer(IIntNoFormatWidget)
class IntNoFormatWidget(TextWidget):
id = u'int-no-format-widget'
def update(self):
super(IntNoFormatWidget, self).update()
def render(self):
return super(IntNoFormatWidget, self).render()
@adapter(IField)
@implementer(IFieldWidget)
def IntNoFormatFieldWidget(field, request):
return FieldWidget(field, IntNoFormatWidget(request))
converters.py
# -*- coding: utf-8 -*-
from zope.component import provideAdapter
from zope.component import adapts
from zope.schema.interfaces import IInt
from z3c.form.interfaces import ITextWidget
from z3c.form.converter import IntegerDataConverter
from z3c.form.converter import SequenceDataConverter
from .widgets import IIntNoFormatWidget
class NoFormatIntegerDataConverter(IntegerDataConverter):
# adapts the Widget Definition above
adapts(IInt, IIntNoFormatWidget)
def toWidgetValue(self, value):
if value is self.field.missing_value:
return u''
return unicode(value)
provideAdapter(NoFormatIntegerDataConverter)
This is what I first had in mind too. Works fine for Integer! Also the approach is great for other uses cases!
But the locale customization is handy for other parts of the locale as well, like decimals/floats or fixing wrongly localized months names in Austria.