# 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");
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 {