From: Bill Erickson Date: Mon, 3 Oct 2016 15:59:18 +0000 (-0400) Subject: LP#1629078 IDL2js correctly parse Accept-Language header X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f8b7a3d03b199c543ccf6d3699688946a2b7f5f5;p=working%2FEvergreen.git LP#1629078 IDL2js correctly parse Accept-Language header Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/IDL2js.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/IDL2js.pm index a7486e4f2a..cfb269deeb 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/IDL2js.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/IDL2js.pm @@ -73,7 +73,8 @@ sub handler { # if no valid locale is present in the query # string, pull it from the headers - $locale = $r->headers_in->get('Accept-Language') unless $locale; + $locale = parse_accept_lang($r->headers_in->get('Accept-Language')) + unless $locale; if (!$locale or $locale !~ /^[a-z]{2}-[A-Z]{2}$/) { $r->log->debug("Invalid IDL2js locale '$locale'; using en-US"); @@ -91,6 +92,19 @@ sub handler { return Apache2::Const::OK; } +# turn Accept-Language into something EG can understand +# TODO: try all langs, not just the first +sub parse_accept_lang { + my $al = shift; + return undef unless $al; + my ($locale) = split(/,/, $al); + ($locale) = split(/;/, $locale); + return undef unless $locale; + $locale =~ s/_/-/og; + return $locale; +} + + # loads the IDL for the provided locale. # when possible, use a cached version of the IDL. sub load_IDL {