From b143a8db6afd2d4308cbaabbd559a335125857e9 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 15 Aug 2008 22:46:46 +0000 Subject: [PATCH] Fix a bug where looking up non-existant files croaks, instead of propagating the error back up and trapping it. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/International.pm | 15 +++++++++++++-- t/International.t | 12 +++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index d5036cad6..ed0f0b1b3 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -12,6 +12,7 @@ - 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: packages don't include archived assets + - fixed: Getting an i18n key from a file that does not exist. 7.5.20 - fixed: DataForm acknowledgement screen shows incorrect value for Date/Time fields diff --git a/lib/WebGUI/International.pm b/lib/WebGUI/International.pm index 5e38f2b73..d9dfe7fb1 100644 --- a/lib/WebGUI/International.pm +++ b/lib/WebGUI/International.pm @@ -97,13 +97,24 @@ my $safeRe = qr/[^\.\w\d\s\/]/; sub get { my ($self, $id, $namespace, $language) = @_; + my $session = $self->session; $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; $language =~ s/$safeRe//g; $namespace =~ s/$safeRe//g; 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; *table = *{"$cmd\::I18N"}; ##Create alias into symbol table my $output = $table->{$id}->{message}; diff --git a/t/International.t b/t/International.t index e1c2cf7ff..37cab41e3 100644 --- a/t/International.t +++ b/t/International.t @@ -20,7 +20,7 @@ use File::Spec; my $session = WebGUI::Test->session; 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; plan tests => $numTests; @@ -66,6 +66,16 @@ SKIP: { 'ebGUIWay', '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' + ); }