fix lookup of English language tags when translation fails

This commit is contained in:
Colin Kuskie 2006-12-13 04:47:41 +00:00
parent a0d3c2d17c
commit bdb88b6c6d
5 changed files with 84 additions and 12 deletions

View file

@ -18,7 +18,7 @@
- fix: Using YUI to add the appropriate events when loading the Add/Edit Event - fix: Using YUI to add the appropriate events when loading the Add/Edit Event
page. Should fix the strange IE bugs. page. Should fix the strange IE bugs.
- RFE: Add wiki page variables to Wiki_Master.pm - RFE: Add wiki page variables to Wiki_Master.pm
- fix: Not translated labels no displaing
7.3.0 7.3.0

View file

@ -102,17 +102,14 @@ sub get {
$namespace =~ s/$safeRe//g; $namespace =~ s/$safeRe//g;
my $cmd = "WebGUI::i18n::".$language."::".$namespace; my $cmd = "WebGUI::i18n::".$language."::".$namespace;
if (defined *{"$cmd\::I18N"}) { ##Symbol table lookup if (!defined *{"$cmd\::I18N"}) { ##Symbol table lookup
our $table; my $load = "use ".$cmd;
*table = *{"$cmd\::I18N"}; ##Create alias into symbol table eval($load);
return $table->{$id}->{message}; ##return key $self->session->errorHandler->warn($cmd." failed to compile because ".$@) if ($@);
} }
my $load = "use ".$cmd; our $table;
eval($load); *table = *{"$cmd\::I18N"}; ##Create alias into symbol table
$self->session->errorHandler->warn($cmd." failed to compile because ".$@) if ($@); my $output = $table->{$id}->{message};
$cmd = "\$".$cmd."::I18N->{'".$id."'}{message}";
my $output = eval($cmd);
$self->session->errorHandler->warn("Couldn't get value from ".$cmd." because ".$@) if ($@);
$output = $self->get($id,$namespace,"English") if ($output eq "" && $language ne "English"); $output = $self->get($id,$namespace,"English") if ($output eq "" && $language ne "English");
return $output; return $output;
} }

View file

@ -14,11 +14,13 @@ use lib "$FindBin::Bin/lib";
use WebGUI::Test; use WebGUI::Test;
use WebGUI::Session; use WebGUI::Session;
use Test::More; # increment this value for each test you create use Test::More; # increment this value for each test you create
use File::Copy qw(cp);
my $session = WebGUI::Test->session; my $session = WebGUI::Test->session;
my $numTests = 1; ##For conditional load check my $numTests = 1; ##For conditional load check
$numTests += 9; my $langTests = 2; ##For language look-up tests
$numTests += 9 + $langTests;
plan tests => $numTests; plan tests => $numTests;
@ -45,4 +47,39 @@ is($i18n->getNamespace(), 'Asset', 'getNamespace: set namespace to Asset');
is($i18n->get('topicName'), 'Assets', 'get: get English label for topicName in Asset: Assets'); is($i18n->get('topicName'), 'Assets', 'get: get English label for topicName in Asset: Assets');
is($i18n->get('topicName', 'WebGUI'), 'WebGUI', 'get: test manual namespace override'); is($i18n->get('topicName', 'WebGUI'), 'WebGUI', 'get: test manual namespace override');
installPigLatin();
my $languages = $i18n->getLanguages();
my $gotPigLatin = exists $languages->{PigLatin};
SKIP: {
skip 'No PigLatin language pack for testing', $langTests unless $gotPigLatin;
is(
$i18n->get('account','WebGUI','English'),
$i18n->get('account','WebGUI','PigLatin'),
'Language check: missing key returns English key'
);
is(
$i18n->get('webgui','WebGUI','PigLatin'),
'ebGUIWay',
'Language check: existing key returns native language key'
);
}
}
sub installPigLatin {
my $wgLib = WebGUI::Test->lib;
mkdir join('/', $wgLib, 'WebGUI/i18n/PigLatin');
cp 'supporting_collateral/WebGUI.pm', join('/', $wgLib, 'WebGUI/i18n/PigLatin/WebGUI.pm');
cp 'supporting_collateral/PigLatin.pm', join('/', $wgLib, 'WebGUI/i18n/PigLatin.pm');
}
END: {
my $wgLib = WebGUI::Test->lib;
unlink join('/', $wgLib, 'WebGUI/i18n/PigLatin/WebGUI.pm');
unlink join('/', $wgLib, 'WebGUI/i18n/PigLatin.pm');
rmdir join('/', $wgLib, 'WebGUI/i18n/PigLatin');
} }

View file

@ -0,0 +1,27 @@
package WebGUI::i18n::PigLatin;
use strict;
our $LANGUAGE = {
label => 'PigLatin',
toolbar => 'bullet',
languageAbbreviation => 'PL', # used by plugins such as javascript helpers and third-party perl modules
locale => 'US' # same as above
};
sub makeUrlCompliant {
my $value = shift;
$value =~ s/\s+$//; #removes trailing whitespace
$value =~ s/^\s+//; #removes leading whitespace
$value =~ s/ /-/g; #replaces whitespace with hyphens
$value =~ s/\.$//; #removes trailing period
$value =~ s/[^A-Za-z0-9\-\.\_\/]//g; #removes all funky characters
$value =~ s/^\///; #removes a leading /
$value =~ s/\/$//; #removes a trailing /
$value =~ s/\/\//\//g; #removes double /
return $value;
}
1;

View file

@ -0,0 +1,11 @@
package WebGUI::i18n::PigLatin::WebGUI;
our $I18N = {
'webgui' => {
message => q|ebGUIWay|,
lastUpdated => 1141963573,
context => q|Test key for International macro test. DO NOT TRANSLATE|,
},
};
1;