Fix a bug where looking up non-existant files croaks, instead of propagating

the error back up and trapping it.
This commit is contained in:
Colin Kuskie 2008-08-15 22:46:46 +00:00
parent 69ca406b38
commit b143a8db6a
3 changed files with 25 additions and 3 deletions

View file

@ -12,6 +12,7 @@
- fixed: Gallery album thumbnail titles now link to the image info rather than back to the album. - fixed: Gallery album thumbnail titles now link to the image info rather than back to the album.
- fixed again: The bug enigmatically named "product". - fixed again: The bug enigmatically named "product".
- fixed: packages don't include archived assets - fixed: packages don't include archived assets
- fixed: Getting an i18n key from a file that does not exist.
7.5.20 7.5.20
- fixed: DataForm acknowledgement screen shows incorrect value for Date/Time fields - fixed: DataForm acknowledgement screen shows incorrect value for Date/Time fields

View file

@ -97,13 +97,24 @@ my $safeRe = qr/[^\.\w\d\s\/]/;
sub get { sub get {
my ($self, $id, $namespace, $language) = @_; my ($self, $id, $namespace, $language) = @_;
my $session = $self->session;
$namespace = $namespace || $self->{_namespace} || "WebGUI"; $namespace = $namespace || $self->{_namespace} || "WebGUI";
$language = $language || $self->{_language} || $self->session->user->profileField("language") || "English"; $language = $language || $self->{_language} || $session->user->profileField("language") || "English";
$id =~ s/$safeRe//g; $id =~ s/$safeRe//g;
$language =~ s/$safeRe//g; $language =~ s/$safeRe//g;
$namespace =~ s/$safeRe//g; $namespace =~ s/$safeRe//g;
my $cmd = "WebGUI::i18n::".$language."::".$namespace; my $cmd = "WebGUI::i18n::".$language."::".$namespace;
WebGUI::Pluggable::load($cmd); eval { WebGUI::Pluggable::load($cmd); };
if ($@) {
if ($language eq 'English') {
$session->log->error('Unable to load $cmd');
return '';
}
else {
my $output = $self->get($id, $namespace, 'English');
return $output;
}
}
our $table; our $table;
*table = *{"$cmd\::I18N"}; ##Create alias into symbol table *table = *{"$cmd\::I18N"}; ##Create alias into symbol table
my $output = $table->{$id}->{message}; my $output = $table->{$id}->{message};

View file

@ -20,7 +20,7 @@ use File::Spec;
my $session = WebGUI::Test->session; my $session = WebGUI::Test->session;
my $numTests = 1; ##For conditional load check my $numTests = 1; ##For conditional load check
my $langTests = 2; ##For language look-up tests my $langTests = 4; ##For language look-up tests
$numTests += 11 + $langTests; $numTests += 11 + $langTests;
plan tests => $numTests; plan tests => $numTests;
@ -66,6 +66,16 @@ SKIP: {
'ebGUIWay', 'ebGUIWay',
'Language check: existing key returns native language key' 'Language check: existing key returns native language key'
); );
is(
$i18n->get('104','Asset','PigLatin'),
$i18n->get('104', 'WebGUI', 'English'),
'Language check: key from missing file return English key'
);
is(
$i18n->get('neverAValidKey','notAValidFile','PigLatin'),
'',
'Language check: key from non-existant file returns an empty string'
);
} }