setlocale — Change current locale
| Attribute | Pos. | Req. | Default | Description |
|---|---|---|---|---|
| locale | Yes | |||
| currency | Yes | 0 | change currency settings only | |
| get | ||||
| persist | 0 | change locale for complete session | ||
| interpolate | 0 | interpolate output? | ||
| hide | 0 | Hide the tag return value? |
This tag changes the current locale. By default the change is only in effect for the current page.
Interchange 5.9.0:
Source: code/SystemTag/setlocale.coretag
Lines: 14
# Copyright 2002-2007 Interchange Development Group and others # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. See the LICENSE file for details. # # $Id: setlocale.coretag,v 1.4 2007-03-30 23:40:49 pajamian Exp $ UserTag setlocale Order locale currency UserTag setlocale addAttr UserTag setlocale PosNumber 2 UserTag setlocale Version $Revision: 1.4 $ UserTag setlocale MapRoutine Vend::Util::setlocale
Source: lib/Vend/Util.pm
Lines: 459
sub setlocale {
my ($locale, $currency, $opt) = @_;
#::logDebug("original locale " . (defined $locale ? $locale : 'undef') );
#::logDebug("default locale " . (defined $::Scratch->{mv_locale} ? $::Scratch->{mv_locale} \
: 'undef') );
if($opt->{get}) {
my $loc = $Vend::Cfg->{Locale_repository} or return;
my $currloc = $Vend::Cfg->{Locale} or return;
for(keys %$loc) {
return $_ if $loc->{$_} eq $currloc;
}
return;
}
$locale = $::Scratch->{mv_locale} unless defined $locale;
#::logDebug("locale is now " . (defined $locale ? $locale : 'undef') );
if ( $locale and not defined $Vend::Cfg->{Locale_repository}{$locale}) {
::logError( "attempt to set non-existant locale '%s'" , $locale );
return '';
}
if ( $currency and not defined $Vend::Cfg->{Locale_repository}{$currency}) {
::logError("attempt to set non-existant currency '%s'" , $currency);
return '';
}
if($locale) {
my $loc = $Vend::Cfg->{Locale} = $Vend::Cfg->{Locale_repository}{$locale};
for(@Vend::Config::Locale_directives_scalar) {
$Vend::Cfg->{$_} = $loc->{$_}
if defined $loc->{$_};
}
for(@Vend::Config::Locale_directives_ary) {
@{$Vend::Cfg->{$_}} = split (/\s+/, $loc->{$_})
if $loc->{$_};
}
for(@Vend::Config::Locale_directives_code) {
next unless $loc->{$_->[0]};
my ($routine, $args) = @{$_}[1,2];
if($args) {
$routine->(@$args);
}
else {
$routine->();
}
}
no strict 'refs';
for(qw/LC_COLLATE LC_CTYPE LC_TIME/) {
next unless $loc->{$_};
POSIX::setlocale(&{"POSIX::$_"}, $loc->{$_});
}
}
if ($currency) {
my $curr = $Vend::Cfg->{Currency_repository}{$currency};
for(@Vend::Config::Locale_directives_currency) {
$Vend::Cfg->{$_} = $curr->{$_}
if defined $curr->{$_};
}
for(@Vend::Config::Locale_keys_currency) {
$Vend::Cfg->{Locale}{$_} = $curr->{$_}
if defined $curr->{$_};
}
}
if(my $ref = $Vend::Cfg->{CodeDef}{LocaleChange}) {
$ref = $ref->{Routine};
if($ref->{all}) {
$ref->{all}->($locale, $opt);
}
if($ref->{lc $locale}) {
$ref->{lc $locale}->($locale, $opt);
}
}
if($opt->{persist}) {
$::Scratch->{mv_locale} = $locale if $locale;
delete $::Scratch->{mv_currency_tmp};
delete $::Scratch->{mv_currency};
$::Scratch->{mv_currency} = $currency if $currency;
}
elsif($currency) {
Vend::Interpolate::set_tmp('mv_currency_tmp')
unless defined $::Scratch->{mv_currency_tmp};
$::Scratch->{mv_currency_tmp} = $currency;
}
else {
delete $::Scratch->{mv_currency_tmp};
delete $::Scratch->{mv_currency};
}
return '';
}