To avoid problems with localisation with custom elements, constraints and so 
on, and to ease the translation (no double entries in translation files in 
formfu and e. g. catalyst) I extended the localize function to handle an 
array of localisation classes.

New classes can be attached with add_localize_object function which expects an 
object or a class name.

The class that was added last will be looked in first, the standard formfu 
languages files (which are now also available in german ;-) will be processed 
last.

To show how to create a custom module with localization I provide some code 
further down.
At the moment I would suggest to use under each stage/element a directory for 
contributed/not standard modules. What about 'User' or 'Contributed'?

With that directory I also could write some tests.

But for now it's working fine with the custom modules I created. ;-)

Greets,
Mario

===============================================
package glue::HTML::FormFu::Constraint::WebAddress;

use strict;
use warnings;
use base 'HTML::FormFu::Constraint';

use Regexp::Common qw( WebAddress );

#__PACKAGE__->mk_accessors( qw/  / );


sub new {
    my $self = shift->SUPER::new(@_);

    
$self->form->add_localize_object( 
'glue::HTML::FormFu::Constraint::WebAddress::I18N' );

    return $self;
}


sub constrain_value {
    my ( $self, $value ) = @_;

    return 1 if !defined $value || $value eq '';

    my $ok = $value =~ /\A$RE{WebAddress}\z/;

    return $self->not ? !$ok : $ok;
}

1;
===============================================
package Regexp::Common::WebAddress;

use strict;
use warnings;

use Regexp::Common qw( pattern clean no_defaults );
use Regexp::Common::URI::RFC2396 qw( $host $port $path_segments $query 
$fragment $domainlabel $toplabel $IPv4address );


pattern  name    => [ qw( WebAddress ) ],
         create  => "(?k:(?k:https?)://)?".
                    "(?k:(($domainlabel\[.])+($toplabel\[.]?)|$IPv4address))".
                    "(?::(?k:$port))?".
                    "(?k:/(?k:(?k:$path_segments)(?:[?](?k:$query))?
(?k:#$fragment)?))?";
# original http matching code in Regexp::Common::URI::http
#          create  => "(?k:(?k:(?k:https?)://)?(?k:$host)(?::(?k:$port))?".
#                     "(?k:/(?k:(?k:$path_segments)(?:[?](?k:$query))?))?".
#                     "(?k:#$fragment)?)";

1;
===============================================
package glue::HTML::FormFu::Constraint::WebAddress::I18N;
use strict;
use warnings;

use base 'Locale::Maketext';

*loc = \&localize;

sub localize {
    my $self = shift;

    return $self->maketext(@_);
}

1;
===============================================
package glue::HTML::FormFu::Constraint::WebAddress::I18N::en;
use strict;
use warnings;

use base qw( glue::HTML::FormFu::Constraint::WebAddress::I18N );

our %Lexicon = (
    form_glue_html_formfu_constraint_webaddress_error  => 'Field must contain 
a valid webaddress',
);

1;
===============================================
END

_______________________________________________
Html-widget mailing list
Html-widget@lists.rawmode.org
http://lists.rawmode.org/cgi-bin/mailman/listinfo/html-widget

Reply via email to