summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rwxr-xr-xutil/vndb.pl20
1 files changed, 16 insertions, 4 deletions
diff --git a/util/vndb.pl b/util/vndb.pl
index 4752c274..32e1bdb4 100755
--- a/util/vndb.pl
+++ b/util/vndb.pl
@@ -52,11 +52,23 @@ YAWF::init(
sub reqinit {
my $self = shift;
- $self->{l10n} = VNDB::L10N->get_handle($self->reqParam('l10n') || $self->reqCookie('l10n') || ());
- my $lang = $self->{l10n}->language_tag();
- $self->resHeader('Set-Cookie', "l10n=$lang; expires=Sat, 01-Jan-2030 00:00:00 GMT; path=/; domain=$self->{cookie_domain}")
- if $lang ne ($self->reqCookie('l10n')||'');
+ # Determine language
+ # if the cookie or parameter "l10n" is set, use that.
+ # otherwise, interpret the Accept-Language header or fall back to English
+ # if the cookie is set and is the same as either the Accept-Language header or the fallback, remove it
+ my $conf = $self->reqParam('l10n') || $self->reqCookie('l10n');
+ $conf = '' if !$conf || !grep $_ eq $conf, VNDB::L10N::languages;
+
+ $self->{l10n} = VNDB::L10N->get_handle(); # this uses I18N::LangTags::Detect
+ if($self->{l10n}->language_tag() eq $conf && $self->reqCookie('l10n')) {
+ $self->resHeader('Set-Cookie', "l10n= ; expires=Sat, 01-Jan-2000 00:00:00 GMT; path=/; domain=$self->{cookie_domain}");
+ } elsif($self->reqParam('l10n') && $conf && $conf ne ($self->reqCookie('l10n')||'') && $self->{l10n}->language_tag() ne $conf) {
+ $self->resHeader('Set-Cookie', "l10n=$conf; expires=Sat, 01-Jan-2030 00:00:00 GMT; path=/; domain=$self->{cookie_domain}");
+ }
+ $self->{l10n} = VNDB::L10N->get_handle($conf) if $conf && $self->{l10n}->language_tag() ne $conf;
+
+ # check authentication cookies
$self->authInit;
# check for IE6