diff options
author | Yorhel <git@yorhel.nl> | 2010-01-10 11:49:53 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2010-01-10 11:49:53 +0100 |
commit | 5e94bb07336d692ce8184a81ef4745367ec70c64 (patch) | |
tree | 312d7a001d73e18725f8fd30e3f266d48ab4a1a5 | |
parent | 2b7e95b01b33fbf5d289b063460a6e318e4f4c5a (diff) |
L10N: Determine language from Accept-Language header
So that people with correctly configured browsers don't have to manually
choose their language of choice with the language switcher, and so that
most people will have one cookie less. (The 'l10n' cookie is removed if
it matches the Accept-Header language -- or the fallback)
More info @
http://www.w3.org/International/questions/qa-lang-priorities
-rw-r--r-- | ChangeLog | 1 | ||||
-rwxr-xr-x | util/vndb.pl | 20 |
2 files changed, 17 insertions, 4 deletions
@@ -17,6 +17,7 @@ git - ? - Rewrote POE::Filter::VNDBAPI to be more generic - Highlight opened VN/producer in relation graphs - Added revision insertion abstraction functions in SQL + - Determine interface language from Accept-Language header 2.9 - 2009-11-16 - Fixed another bug with the calculation of tags_vn_bayesian.spoiler 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 |