automatically translate label and hoverHelp property elements for assets
This commit is contained in:
parent
25931b67d4
commit
0e94b4a783
2 changed files with 68 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ use strict;
|
|||
use warnings;
|
||||
use 5.010;
|
||||
use base qw(WebGUI::Definition);
|
||||
use WebGUI::International;
|
||||
|
||||
our $VERSION = '0.0.1';
|
||||
|
||||
|
|
@ -40,5 +41,21 @@ sub import {
|
|||
goto $next;
|
||||
}
|
||||
|
||||
sub _gen_getProperty {
|
||||
my $class = shift;
|
||||
my $superGetProperty = $class->next::method(@_);
|
||||
return sub {
|
||||
my $self = shift;
|
||||
my $property = $self->$superGetProperty(@_);
|
||||
for my $element (qw(label hoverHelp)) {
|
||||
if ($property->{$element} && ref $property->{$element} eq 'ARRAY') {
|
||||
$property->{$element}
|
||||
= WebGUI::International->new($self->session)->get(@{$property->{$element}});
|
||||
}
|
||||
}
|
||||
return $property;
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
51
t/Definition/Asset.t
Normal file
51
t/Definition/Asset.t
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
no warnings qw(uninitialized);
|
||||
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
|
||||
use Test::More 'no_plan'; #tests => 1;
|
||||
use WebGUI::Test;
|
||||
|
||||
{
|
||||
package WGT::Class;
|
||||
use WebGUI::Definition::Asset (
|
||||
attribute1 => 'attribute 1 value',
|
||||
properties => [
|
||||
showInForms => {
|
||||
label => ['show in forms'],
|
||||
},
|
||||
confirmChange => {
|
||||
label => ['confirm change', 'Asset'],
|
||||
},
|
||||
noTrans => {
|
||||
label => 'this label will not be translated',
|
||||
},
|
||||
],
|
||||
);
|
||||
|
||||
sub session {
|
||||
return WebGUI::Test->session;
|
||||
}
|
||||
}
|
||||
|
||||
my $object = WGT::Class->instantiate;
|
||||
|
||||
is_deeply $object->getProperty('showInForms')->{label}, 'Show In Forms?',
|
||||
'getProperty internationalizes label';
|
||||
is_deeply $object->getProperty('confirmChange')->{label}, 'Are you sure?',
|
||||
'getProperty internationalizes label with namespace';
|
||||
is_deeply $object->getProperty('noTrans')->{label}, 'this label will not be translated',
|
||||
q{getProperty doesn't internationalize plain scalars};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue