CGI-Lingua
view release on metacpan or search on metacpan
"Can't determine country from LAN connection X"
"Can't determine country from loopback connection X"
"cache contains a numeric country: N"
"IP matches to a numeric country"
## locale
HTTP doesn't have a way of transmitting a browser's localisation information
which would be useful for default currency, date formatting, etc.
This method attempts to detect the information, but it is a best guess
and is not 100% reliable. But it's better than nothing ;-)
Returns a [Locale::Object::Country](https://metacpan.org/pod/Locale%3A%3AObject%3A%3ACountry) object.
### API SPECIFICATION
Input: none beyond $self
Returns: Locale::Object::Country | undef
## time\_zone
lib/CGI/Lingua.pm view on Meta::CPAN
} else {
$self->{_geoip} = Geo::IP->new(0);
}
}
=head2 locale
HTTP doesn't have a way of transmitting a browser's localisation information
which would be useful for default currency, date formatting, etc.
This method attempts to detect the information, but it is a best guess
and is not 100% reliable. But it's better than nothing ;-)
Returns a L<Locale::Object::Country> object.
=head3 API SPECIFICATION
Input: none beyond $self
Returns: Locale::Object::Country | undef
=cut
$ENV{'HTTP_ACCEPT_LANGUAGE'} = 'en-029';
$ENV{'REMOTE_ADDR'} = '201.229.32.134';
my $l = new_ok('CGI::Lingua' => [
supported => ['en', 'nl', 'fr', 'fr-fr', 'de', 'id', 'il', 'ja', 'ko', 'pt', 'ru', 'es', 'tr', 'es-419'],
]);
ok(defined $l);
ok($l->isa('CGI::Lingua'));
SKIP: {
skip 'Tests require Internet access', 4 unless(-e 't/online.enabled');
ok(defined($l->country()));
# Sometimes in aw sometimes in uy. I guess the databases out
# there aren't consistent
ok(($l->country() eq 'aw') || ($l->country() eq 'uy'));
ok($l->language_code_alpha2() eq 'en');
ok($l->language() eq 'English');
}
ok(defined($l->requested_language()));
TODO: {
local $TODO = "sublanguage doesn't handle 3 characters";
ok(defined($l->sublanguage()));
$ENV{'HTTP_ACCEPT_LANGUAGE'} = 'es-419,es;q=0.8';
$ENV{'REMOTE_ADDR'} = '201.213.196.117';
my $l = new_ok('CGI::Lingua' => [
supported => ['en', 'nl', 'fr', 'fr-fr', 'de', 'id', 'il', 'ja', 'ko', 'pt', 'ru', 'es', 'tr', 'es-419'],
]);
ok(defined $l);
ok($l->isa('CGI::Lingua'));
SKIP: {
skip 'Tests require Internet access', 5 unless(-e 't/online.enabled');
ok(defined($l->country()));
# Sometimes in ar sometimes in uy. I guess the databases out
# there aren't consistent
ok(($l->country() eq 'ar') || ($l->country() eq 'uy'));
ok($l->language_code_alpha2() eq 'es');
ok($l->language() eq 'Spanish');
ok(defined($l->requested_language()));
}
TODO: {
local $TODO = "sublanguage doesn't handle 3 characters";
SKIP: {
( run in 1.161 second using v1.01-cache-2.11-cpan-7fcb06a456a )