Author: spadkins
Date: Thu Feb 5 19:35:02 2009
New Revision: 12476
Modified:
p5ee/trunk/App-Context/lib/App/UserAgent.pm
Log:
modified lang parsing
Modified: p5ee/trunk/App-Context/lib/App/UserAgent.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/UserAgent.pm (original)
+++ p5ee/trunk/App-Context/lib/App/UserAgent.pm Thu Feb 5 19:35:02 2009
@@ -82,29 +82,19 @@
my ($context) = @_;
$self->{context} = $context;
- if (defined $context) {
- $self->{http_user_agent} = $context->get_option("http_user_agent");
- }
- else {
- $self->{http_user_agent} =
- (defined $ENV{HTTP_USER_AGENT}) ?
- $ENV{HTTP_USER_AGENT} :
- "unknown";
- }
-
- my ($uatype, $uaver, $ostype, $osver, $arch, $ualang, $lang);
- ($uatype, $uaver, $ostype, $osver, $arch, $ualang) =
- $self->parse($self->{http_user_agent});
+ $self->{http_user_agent} = (defined $ENV{HTTP_USER_AGENT}) ?
$ENV{HTTP_USER_AGENT} : "unknown";
- if (defined $context) {
- $lang = $context->get_option("http_user_agent");
- }
- elsif (defined $ENV{HTTP_ACCEPT_LANGUAGE}) {
+ my ($lang);
+ if (defined $ENV{HTTP_ACCEPT_LANGUAGE}) {
$lang = lc($ENV{HTTP_ACCEPT_LANGUAGE});
- $lang =~ s/[ ,].*//;
+ $lang =~ s/[ ,].*//; # trim off everything after the first comma or
space
}
+ my ($uatype, $uaver, $ostype, $osver, $arch, $ualang) =
+ $self->parse($self->{http_user_agent});
+ $lang = $ualang if (!$lang && $ualang);
+
$self->{uatype} = $uatype;
$self->{uaver} = $uaver;
$self->{ostype} = $ostype;
@@ -324,7 +314,7 @@
$ostype = "unknown"; # Windows, Macintosh, Linux, FreeBSD, HP-UX, SunOS
$osver = "unknown"; # 16, 3.1, 95, 98, 2000, ME, CE, NT 5.1
$arch = "unknown"; # i386, i586, i686, PPC
- $lang = "en"; # en, en-US, ja, de
+ $lang = ""; # en, en-US, ja, de
$ua = $http_user_agent;
$ua =~ s/\+/ /g;
@@ -376,6 +366,8 @@
}
# lang
+ # NOTE: This is woefully inadequate. Thankfully, the ACCEPT-LANGUAGE
header exists
+ # so this is really not needed.
if ($http_user_agent =~ /\[([a-zA-Z]{2})\]/) {
$lang = $1;
}