Hi all,
This has been an issue for quite some time now: localization for numeric fields doesn't really work for laguages that use different separators. At this point in version 3.1 Zend Format is used to validate input against the current locale settings, so the default en_US format will be displayed but never validate, and the localized version wil validate, but isn't displayed and cannot be parsed...
People have written workarounds and modules and posted issues (
https://github.com/silverstripe/silverstripe-framework/issues/2161) but it isn't really solved. So I was working on a new set of DBFields, FormFields and templates based on and hopefully one day to replace the following classes:
- Float
- Decimal
- Currency
- NumericField
- CurrencyField
I have a basic working set ready, building further on Zend Format, and I hope people would be willing to look at it. I just have a few questions:
1. In the Currency field, the CurrencySymbol should be placed not in, but befiore the actual input field (now it isn't visible at all)
2. The current CurrencyField is quite complex - but it looks like the NumericField is used for Currency instead. So could we start by rebasing the CurrencyField on the NumericField, with a bit of extended functionality?
3. PHP's setlocale() function should not be used. Setting the current locale the SilverStripe way and using Zend Format should do the trick I think
4. The Currency class supports a set of (template) functions Nice and Whole, where Whole is basically round():
- Nice : €2,95
- Whole: €3,00
I was wondering what other special ways of formatting currency would be used. For instance we use €2,- for whole numbers. Nice/Whole might support parameters to enable this?
5. The euro uses two decimals (the currency default) Are there currencies that use one or three or even six? Because at this point the number of decimals is set for the DBField, on creation only. We can use multiple Currency symbols for, say, a translatable site, but we cannot use different precision settings for
displaying the values. We could offer a parameter for that - or create config, or. Does anyone know if Zend Locale 'knows' these defaults?
At this point I haven't looked at the Money field yet, but I suppose it won't be much different... All comments are appreciated. If you're interested I can put on GitHub the fields I now have in a module but they obviously aren't quite finished yet...
Thanks, Martine