[Zope] dtml-var "fmt" question

Rob Page rob.page@digicool.com
Thu, 22 Jul 1999 10:09:06 -0400


Hi Jens:

> maybe someone has done this before and could advise me: i 
> want to format a
> floating point variable so it comes out using the european 
> decimal point
> notation. so instead of 12.5 i would like it to say 12,5 etc.
> 
> the DTML guide offers some nice built-in formats (like 
> "dollars-and-cents"),
> i wonder if someone had an idea about maybe doing a 
> "euros-and-cents" one,
> with the right decimal punctuation and a euro sign ;)

In DT_Var.py you'll find:

special_formats={
    'whole-dollars': whole_dollars,
    'dollars-and-cents': dollars_and_cents,
    'collection-length': len_format,
    'structured-text': structured_text,

    # The rest are depricated:
    'sql-quote': sql_quote,
    'html-quote': html_quote,
    'url-quote': url_quote,
    'multi-line': newline_to_br,
    'comma-numeric': thousands_commas,
    'dollars-with-commas': whole_dollars_with_commas,
    'dollars-and-cents-with-commas': dollars_and_cents_with_commas,
    }


AND 

def dollars_and_cents(v, name='(Unknown name)', md={}):
    try: return "$%.2f" % v
    except: return ''


So, the short answer is that, in your DT_Var.py you could add a special
format called euros-and-cents and then define the simple method for
rendering it per the examples above.  Of course the challenge is the
need to constantly repatch the file(s) when you get new versions of
Zope.  This is a problem...

The longer answer is being contemplated in the Zope Internationalization
Project (ZIP) list.  As you might imagine, this is NOT  unique example.
In fact, it crosses currency, time and date issue boundaries.  I have
raised the issue internally that we need to "modularize" these special
format definitions so that people can separately install, use and
maintain formatting configurations.  I am slowly working on a proposal
(which I'll make to the ZIP list) to refactor/reinvent Zope's
international extensibility (probably mimicking Un*x' LOCALE stuff).  If
you have any particular ideas on the subject I'd love to hear them!

HTH,
--Rob