Skip to content

Commit

Permalink
Add a template variable for the current language, for better user fee…
Browse files Browse the repository at this point in the history
…dback. Fixes bug #11573.
  • Loading branch information
perlDreamer committed May 25, 2010
1 parent ab0204d commit c2e6978
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/changelog/7.x.x.txt
Expand Up @@ -10,6 +10,7 @@
- fixed #11580: Date not populated for Story Archive RSS feed
- fixed #11587: Thingy, no fields and undefined statement handles
- fixed #11589: Syndicated Content: Return raw text for sentence and word template variables
- fixed #11573: user has no way of knowing what they are currently using

7.9.5
- Asset->www_copy now has a progress bar
Expand Down
9 changes: 7 additions & 2 deletions lib/WebGUI/Macro/PickLanguage.pm
Expand Up @@ -45,17 +45,22 @@ sub process {
my $session = shift;
my $templateId = shift || "_aE16Rr1-bXBf8SIaLZjCg";
my $template = WebGUI::Asset::Template->new($session, $templateId);
return "Could not instanciate template with id [$templateId]" unless $template;
my $i18n = WebGUI::International->new($session);
return "Could not instanciate template with id [$templateId]" unless $template;
my $i18n = WebGUI::International->new($session);
my $languages = $i18n->getLanguages();
my $currentLanguage = $session->scratch->get('language')
? $session->scratch->get('language')
: $session->user->profileField('language');
my @lang_loop = ();
foreach my $language ( keys %$languages ) {
my $isCurrentLanguage = $currentLanguage eq $language ? 1 : 0;
push @lang_loop, {
language_url => '?op=setLanguage;language=' . $language,
language_lang => $i18n->getLanguage($language , 'label'),
language_langAbbr => $i18n->getLanguage($language, 'languageAbbreviation'),
language_langAbbrLoc => $i18n->getLanguage($language, 'locale'),
language_langEng => $language,
language_isCurrent => $isCurrentLanguage,
};
}
my %vars = (
Expand Down
7 changes: 6 additions & 1 deletion lib/WebGUI/i18n/English/Macro_PickLanguage.pm
Expand Up @@ -34,7 +34,12 @@ our $I18N = { ##hashref of hashes
message => q|The English name of the language.|,
lastUpdated => 1131394072,
context => q|A label of the language to use in the template|
},
},
'language_isCurrent' => {
message => q|A boolean which is true if this language is the current language.|,
lastUpdated => 1131394072,
context => q|A label of the language to use in the template|
},
'language_url' => {
message => q|The url that sets the WebGUI language to the selected language.|,
lastUpdated => 1131394072,
Expand Down
10 changes: 6 additions & 4 deletions t/Macro/PickLanguage.t
Expand Up @@ -50,11 +50,12 @@ $templateMock->mock('process', sub { $templateVars = $_[1]; } );
$templateVars,
{
lang_loop => [
{ 'language_url' => '?op=setLanguage;language=English',
'language_lang' => 'English',
{ 'language_url' => '?op=setLanguage;language=English',
'language_lang' => 'English',
'language_langAbbr' => 'en',
'language_langAbbrLoc' => 'US',
'language_langEng' => 'English'
'language_langEng' => 'English',
'language_isCurrent' => 1,
},
],
delete_url => '?op=setLanguage;language=delete;',
Expand Down Expand Up @@ -85,7 +86,8 @@ $templateMock->mock('process', sub { $templateVars = $_[1]; } );
'language_lang' => 'English',
'language_langAbbr' => 'en',
'language_langAbbrLoc' => 'US',
'language_langEng' => 'English'
'language_langEng' => 'English',
'language_isCurrent' => 1,
},
],
delete_url => '?op=setLanguage;language=delete;',
Expand Down

0 comments on commit c2e6978

Please sign in to comment.