Skip Menu |

This queue is for tickets about the HTML-FormFu CPAN distribution.

Report information
The Basics
Id: 42928
Status: resolved
Priority: 0/
Queue: HTML-FormFu

People
Owner: Nobody in particular
Requestors: dmaki [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.03007
Fixed in: (no value)



Subject: HTML::FormFu localization doesn't properly pick up external localization objects
calling add_localize_object() doesn't trigger proper localization for some versions of Locale::Maketext (older versions like 0.09 throws an exception on some failure cases, but newer versions simply return an empy list) the solution therefore, is to simply check if @localized_strings is populated. please find a small patch and a test. The patch also changes Makefile.PL's requirement for Locale::Maketext::Simple to Locale::Maketext, as HTML::FormFu doesn't use Locale::Maketext::Simple.
Subject: i18n.patch
=== Makefile.PL ================================================================== --- Makefile.PL (revision 99479) +++ Makefile.PL (local) @@ -29,7 +29,7 @@ requires 'HTTP::Headers' => '1.64'; requires 'List::Util'; requires 'List::MoreUtils'; -requires 'Locale::Maketext::Simple'; +requires 'Locale::Maketext'; requires 'Module::Pluggable'; requires 'Number::Format'; requires 'Readonly'; === lib/HTML/FormFu/Localize.pm ================================================================== --- lib/HTML/FormFu/Localize.pm (revision 99479) +++ lib/HTML/FormFu/Localize.pm (local) @@ -52,7 +52,7 @@ next; } - last; + last if @localized_strings; } if ( !@localized_strings ) { === t/i18n.t ================================================================== --- t/i18n.t (revision 99479) +++ t/i18n.t (local) @@ -0,0 +1,53 @@ +# BEGIN { *Locale::Maketext::DEBUG = sub() { 1 } }; + +package Test::HTML::FormFu::RegressLocalization; +use base qw(Locale::Maketext); + +sub localize { shift->maketext(@_) } + +package Test::HTML::FormFu::RegressLocalization::en; +use base qw(Test::HTML::FormFu::RegressLocalization); + +our %Lexicon = ( + foobar => "Foo blah Baz" +); + +package main; +use strict; + +use Test::More (tests => 4); +use HTML::FormFu; + +sub populate_formfu { + my $formfu = shift; + $formfu->populate({ + elements => [ + # deliberately using formfu's built-in name to trigger + # text replacement + { label_loc => "form_constraint_required" }, + + # this here can only be replaced by our own l18n handle + { label_loc => "foobar" } + ] + }); +} + +{ + my $formfu = HTML::FormFu->new(); + populate_formfu($formfu); + my $string = $formfu->render(); + like $string, qr/\bThis field is required\b/, "properly localized"; + like $string, qr/\bfoobar\b/, "properly left untouched"; +} + +{ + my $formfu = HTML::FormFu->new(); + $formfu->add_localize_object( + Test::HTML::FormFu::RegressLocalization::en->new + ); + populate_formfu($formfu); + + my $string = $formfu->render(); + like $string, qr/\bThis field is required\b/, "properly localized"; + like $string, qr/\bFoo blah Baz\b/, "properly localized (added object took effect)"; +}
Thanks - I've applied this to svn, and it'll be included in the next cpan release.