fix lookup of English language tags when translation fails
This commit is contained in:
parent
a0d3c2d17c
commit
bdb88b6c6d
5 changed files with 84 additions and 12 deletions
|
|
@ -18,7 +18,7 @@
|
|||
- fix: Using YUI to add the appropriate events when loading the Add/Edit Event
|
||||
page. Should fix the strange IE bugs.
|
||||
- RFE: Add wiki page variables to Wiki_Master.pm
|
||||
|
||||
- fix: Not translated labels no displaing
|
||||
|
||||
|
||||
7.3.0
|
||||
|
|
|
|||
|
|
@ -102,17 +102,14 @@ sub get {
|
|||
$namespace =~ s/$safeRe//g;
|
||||
my $cmd = "WebGUI::i18n::".$language."::".$namespace;
|
||||
|
||||
if (defined *{"$cmd\::I18N"}) { ##Symbol table lookup
|
||||
our $table;
|
||||
*table = *{"$cmd\::I18N"}; ##Create alias into symbol table
|
||||
return $table->{$id}->{message}; ##return key
|
||||
if (!defined *{"$cmd\::I18N"}) { ##Symbol table lookup
|
||||
my $load = "use ".$cmd;
|
||||
eval($load);
|
||||
$self->session->errorHandler->warn($cmd." failed to compile because ".$@) if ($@);
|
||||
}
|
||||
my $load = "use ".$cmd;
|
||||
eval($load);
|
||||
$self->session->errorHandler->warn($cmd." failed to compile because ".$@) if ($@);
|
||||
$cmd = "\$".$cmd."::I18N->{'".$id."'}{message}";
|
||||
my $output = eval($cmd);
|
||||
$self->session->errorHandler->warn("Couldn't get value from ".$cmd." because ".$@) if ($@);
|
||||
our $table;
|
||||
*table = *{"$cmd\::I18N"}; ##Create alias into symbol table
|
||||
my $output = $table->{$id}->{message};
|
||||
$output = $self->get($id,$namespace,"English") if ($output eq "" && $language ne "English");
|
||||
return $output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,13 @@ use lib "$FindBin::Bin/lib";
|
|||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More; # increment this value for each test you create
|
||||
use File::Copy qw(cp);
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
my $numTests = 1; ##For conditional load check
|
||||
$numTests += 9;
|
||||
my $langTests = 2; ##For language look-up tests
|
||||
$numTests += 9 + $langTests;
|
||||
|
||||
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', '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');
|
||||
}
|
||||
|
|
|
|||
27
t/supporting_collateral/PigLatin.pm
Normal file
27
t/supporting_collateral/PigLatin.pm
Normal 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;
|
||||
11
t/supporting_collateral/WebGUI.pm
Normal file
11
t/supporting_collateral/WebGUI.pm
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue