getFormProperties now also passes i18n arguments to sprintf if requested.

This commit is contained in:
Colin Kuskie 2010-02-12 11:33:23 -08:00
parent 74ccbef83f
commit d6cbcf4604
3 changed files with 29 additions and 2 deletions

View file

@ -126,6 +126,20 @@ calling subroutines for values.
Each subroutine is invoked as a method of the object, and is passed the entire set of
form properties and the name of the property.
i18n is allowed in the label, subtext and hoverHelp options, and is specified by passing
an array reference.
label => [ 'key', 'namespace' ],
If the array reference has more than two elements, getFormProperties will pass the retrieved
i18n key to sprintf, with the extra elements as arguments.
label => [ 'key', 'namespace', 'extra' ],
becomes
label => sprintf($i18n->get('label', 'namespace'), 'extra'),
=head3 $name
The name of the property to return.
@ -139,7 +153,12 @@ sub getFormProperties {
PROPERTY: while (my ($property_name, $property_value) = each %{ $form }) {
next PROPERTY unless ref $property_value;
if (($property_name eq 'label' || $property_name eq 'hoverHelp' || $property_name eq 'subtext') and ref $property_value eq 'ARRAY') {
$form->{$property_name} = WebGUI::International->new($self->session)->get(@{$property_value});
my ($label, $namespace, @arguments) = @{ $property_value };
my $text = WebGUI::International->new($self->session)->get($label, $namespace);
if (@arguments) {
$text = sprintf $text, @arguments;
}
$form->{$property_name} = $text;
}
elsif (ref $property_value eq 'CODE') {
$form->{$property_name} = $self->$property_value($property, $property_name);

View file

@ -3587,7 +3587,13 @@ LongTruncOk=1</p>
'webgui' => {
message => q|WebGUI|,
lastUpdated => 1141963573,
context => q|Test key for International macro test. DO NOT TRANSLATE|,
context => q|Test key for International macro test. DO NOT TRANSLATE OR DELETE|,
},
'webgui help %s' => {
message => q|webgui help %s|,
lastUpdated => 1266003122,
context => q|Test key for Definition::Role::Object. DO NOT TRANSLATE OR DELETE|,
},
'pages' => {

View file

@ -105,6 +105,7 @@ my $called_getProperties;
aspect 'aspect1' => 'aspect1 value';
property 'property1' => (
label => ['webgui', 'WebGUI'],
hoverHelp => ['webgui help %s', 'WebGUI', 'extra'],
options => \&property1_options,
named_url => \&named_url,
);
@ -130,6 +131,7 @@ my $called_getProperties;
$object->getFormProperties('property1'),
{
label => 'WebGUI',
hoverHelp => 'webgui help extra',
options => { one => 1, two => 2, three => 3 },
named_url => 'property1',
},