[Catalyst] L10N + FormBuilder/HTMLWidget

Carl Franks fireartist at gmail.com
Mon Feb 19 22:33:16 GMT 2007


Chris,

On 19/02/07, Christopher H. Laco <claco at chrislaco.com> wrote:
> Is anyone doing complete localization using FormBuilder or HTML::Widget?
> I'm stuggling with probably the same things everyone struggles with when
> it comes to forms.
>
> FormBuilder is nice when it comes to localizing the messages via
> messages.$lang. It totally sucks when it comes to localizing the form
> labels themselves. It looks like I either have to manually loop through
> teh fields and localize the labels, or use a different .frm config for
> each language...which means duplicating major parts of the config.
>
> HTML::Widget seems to be even worse at getting its config from an
> external source rather than creating forms in code.
>
> What is the sanest way people have found to do localization without
> having to do it in 2-3 different places (code to alter labels,
> messages.$lang, etc)?
>
> It seems that forms suck, and form tools really haven't quite gotten
> over the hurdle yet in situations like this.

I haven't yet publicised this anywhere than the html-widget list, but
I've been working on a html-widget replacement, named HTML::FormFu.
The main reason I've been quiet is mainly because, of the little
documentation there is, some is now incorrect and most still refers to
html-widget. - So consider the code and test suite the primary
documentation for now.

I've just added L10N to it, using Locale::Maketext, but you can
provide your own L10N object or class if you wish.
At the moment, it only has an en.pm locale file.
To localise labels, comments etc, I would suggest using the same
technique as you would to localise anything else:
    $field->label( $c->loc('name') );
instead of:
    $field->label('name');
To organise the L10N texts, you could either let formfu localise error
messages, etc from it's own locale files and set your own labels using
`$c->loc`.
Or you could merge the contents of formfu's own locale files into your
own, then tell formfu to use Cat's own localize() method. (assuming
you're using the Catalyst-Plugin-I18N).
The catalyst controller has an option for handling this automatically
`localize_from_context`.
If you want formfu to use it's own L10N files, you can set the
controller option `localize_from_context` to tell it to get the
language from `$c->languages`.

The formfu code should be considered alpha, as it's still changing to
an extent, but it is working and I'm using it in a few different
projects and enjoying using it.
The code is in svn at:
http://html-formfu.googlecode.com/svn/trunk/

The Cat controller / actions
http://catalyst-controller-html-formfu.googlecode.com/svn/trunk/

DBIx::Class integration (replacement for DBIx::Class::HTMLWidget)
http://dbix-class-formfu.googlecode.com/svn/

A couple of extra form elements which use the Dojo library:
http://html-formfu-dojo.googlecode.com/svn/trunk/

There's also an application which lets you test different css
stylesheets again forms, to quickly prototype different layouts:
http://www.fireartist.com/html-formfu-cssapp/

In a very quick summary, I would describe it's main advantages over
html-widget as being:
* uses TT templates, so you can easily change the rendered xhtml on a
per-project basis
* set $field->filename() to override the rendering on a per-field basis
* the old result objects are broken out into seperate result + render
object to allow a backend other than TT to be used
* more seperation of form fields and other non-field 'elements', such
as fieldsets
* load form settings / elements / constraints / filters from config
files, allowing easy setting of global defaults, and allows forms to
be changed without touching code
* cleaner xhtml, more customisable dom id generation, cleaner css classnames
* can set element default values, form-wide, for individual field types, e.g.
    $form->element_defaults({ Textarea => { cols => 20 }, Text => {
size => 20 } });
will automatically pass these defaults when the relevant element type
is created.
And of course, these can be set via a config file.
...well, that's all I can think of off-hand

If you're interested in experimenting with it, you're welcome to ask
questions on the html-widget list.

Cheers,
Carl



More information about the Catalyst mailing list