support for parsing accept-language for locale
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 7 May 2009 22:00:17 +0000 (22:00 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 7 May 2009 22:00:17 +0000 (22:00 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@13098 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm

index dccf40c..840dfaa 100644 (file)
@@ -73,12 +73,23 @@ sub load_context {
     $ctx->{theme} = $cgi->cookie(OILS_HTTP_COOKIE_THEME) || 'default';
     $ctx->{locale} = 
         $cgi->cookie(OILS_HTTP_COOKIE_LOCALE) || 
-        $r->headers_in->get('Accept-Language') || 'en-US'; #  this will need some trimming
+        parse_accept_lang($r->headers_in->get('Accept-Language')) || 'en-US'; #  this will need some trimming
     $r->log->debug('skin = ' . $ctx->{skin} . ' : theme = ' . 
         $ctx->{theme} . ' : locale = ' . $ctx->{locale});
     return $ctx;
 }
 
+# turn Accept-Language into sometihng EG can understand
+sub parse_accept_lang {
+    my $al = shift;
+    return undef unless $al;
+    my ($locale) = split(/,/, $al);
+    ($locale) = split(/;/, $locale);
+    return undef unless $locale;
+    $locale =~ s/-(.*)/eval '-'.uc("$1")/e;
+    return $locale;
+}
+
 # Given a URI, finds the configured template and any extra page 
 # arguments (trailing path info).  Any extra data is returned
 # as page arguments, in the form of an array, one item per