code
New in WebGUI::Session::Scratch
#-------------------------------------------------------------------
=head2 removeLanguageOverride()
Removes the language scratch variable from the session
=cut
sub removeLanguageOverride {
my $self = shift;
$self->session->scratch->delete('language');
}
#-------------------------------------------------------------------
=head2 getLanguageOverride ()
Retrieves the language of the session
=cut
sub getLanguageOverride {
my $self = shift;
my $languageOverride = $self->session->scratch->get('language');
return $languageOverride;
}
#----------------------------------------------------------------------
=head2 setLanguageOverride ( language )
Sets a scratch variable language in the session if the language is installed
=head3 language
The language that should be set into the session
=cut
sub setLanguageOverride {
my $self = shift;
my $language = shift;
my $i18n = WebGUI::International->new($self->session);
if($i18n->getLanguages()->{$language}) {
$self->session->scratch->set("language",$language);
return undef;
}
else {
$self->session->log->error("Language $language is not installed in this site");
return undef;
}
}
Change in WebGUI::International
line 287:
$language ||= $session->user->profileField('language');
become
$language ||= $session->scratch->getLanguageOverride() || $session->user->profileField('language');
New contentHandler WebGUI::Content::SetLanguage
package WebGUI::Content::SetLanguage;
use strict;
use WebGUI::Session;
use WebGUI::Form;
use WebGUI::International;
sub handler {
my ($session) = @_;
return undef unless $session->form->get('op') eq 'setLanguage';
my $language = $session->form->get('language');
#check whether a language has been given in the url
if (!$language) {
$session->log->error('There is no language given to this method');
return undef;
}
#make it possible to delete the language scratch variable from the session
if ($language eq 'delete' ) {
$session->scratch->removeLanguageOverride;
return undef;
}
else {
#set a scratch variable language or throw error if language is not installed
return $session->scratch->setLanguageOverride($language);
}
}
1
Added tests in Scratch.t (increase amount of tests with 4)
$scratch->setLanguageOverride('English');
is($scratch->getLanguageOverride, 'English', 'session scratch language is not correctly set');
$scratch->removeLanguageOverride;
is($scratch->getLanguageOverride, undef, 'The session scratch variable language is not removed');
$scratch->setLanguageOverride('myimmaginarylanguagethatisnotinstalled');
is($scratch->getLanguageOverride, undef, 'A non-existing language is set');
$scratch->setLanguageOverride('English');
$scratch->setLanguageOverride();
is($scratch->getLanguageOverride, 'English', 'A empty string is falsely recognised as a language');

