Apache-LangURI
view release on metacpan or search on metacpan
("Default language '$df' is different from major '$r->{major}'.");
if (-d $fn and (@uri == 1 or $uri[-1] ne '')) {
push @uri, '';
# even if we had a language segment, we have to redirect or else
# mod_dir will eat us.
$r->{cnt} = 0;
$r->log->debug
("Modifying path to prevent counteraction with mod_dir");
}
# if the selected major cannot be found in the default language
# append the rfc3066 segment to the path if it does not contain one.
unless ($r->{cnt} == 1) {
splice(@uri, ($r->{cnt} ? $r->{pos} : -1), 0, $r->{lang});
$uri_out = join('/', @uri) . ($r->args ? '?' . $r->args : '');
$r->log->debug("Redirecting request to '$uri_out'.");
$r->headers_out->set(Location => $uri_out);
return $PARAMS{&REDIR_PERM} ?
Apache::HTTP_MOVED_PERMANENTLY : Apache::REDIRECT;
}
}
}
}
else {
$r->log->debug(FORCE_LANG . " not set. not redirecting.");
}
$r->uri($uri);
return Apache::DECLINED;
}
1;
__END__
=head1 NAME
Apache::LangURI - Rewrite Accept-Language headers from URI path and back
=head1 SYNOPSIS
# httpd.conf
PerlSetVar DefaultLanguage en
# for redirecting the url based on the top language
# in the inbound header
PerlSetVar ForceLanguage on
PerlAddVar IgnorePathRegex ^/foo
# and the opposite:
PerlAddVar IgnorePathRegex !^/foo/bar
PerlTransHandler Apache::LangURI
=head1 DESCRIPTION
Apache::LangURI will attempt to match the first segment of the path
of an http URL to an RFC3066 E<lt>majorE<gt>-E<lt>minorE<gt> language code.
It will also optionally prepend the "best" language code to the path, should
it not already be there. Language tags are normalized to a lower case major
with an upper case minor and a hyphen in between.
=head1 CONFIGURATION
=head3 DefaultLanguage
This defines the default language that will be added at a diminished quality
value after the language found in the URI path, should its major part not
match. This is to ensure that a suitable variant will always be returned when
content negotiation occurs. Defaults to 'en' if omitted.
=head3 ForceLanguage
Setting this variable to a positive (1|true|on|yes) value will cause the
server to redirect the user to a path beginning with the language code of
the highest quality value found in the Accept-Language header. This occurs
only when the URI path does not begin with an RFC3066 language code. This
directive can be omitted if this behavior is not desired.
=head3 IgnorePathRegex
Passing a regular expression (optionally prefixed by ! to denote negation)
will limit the effect of this handler to simulate <Location> blocks on a
transhandler.
=head3 RedirectPermanent
if set to a positive (1|true|on|yes) value, the server will return 301 Moved
rather than 302 Found on a successful redirection.
=head1 BUGS
Only currently does ISO639 language majors and ISO3166 country minors. No
support for constructs like "no-sami" or "x-jawa".
RFC3066 includes rules for pairings of ISO639-1/2 and ISO3166 two-character
and three-character denominations. This module does not enforce those rules.
The DefaultLanguage variable will eventually be phased out to use
Apache::Module to derive the value from mod_mime as soon as this author
manages to get it to compile.
Forms that refer to absolute URL paths may no longer function due to the
redirection process, as the POST payload will be interrupted.
=head1 SEE ALSO
Locale::Language
Locale::Country
http://www.ietf.org/rfc3066.txt
ISO 639
ISO 3166
=head1 AUTHOR
Dorian Taylor, E<lt>dorian@cpan.orgE<gt>
( run in 1.357 second using v1.01-cache-2.11-cpan-5735350b133 )