PGXN-Site
view release on metacpan or search on metacpan
lib/PGXN/Site/Locale.pm view on Meta::CPAN
'Search for PostgreSQL Extension Network users' => 'Search for PostgreSQL Extension Network users',
'A list of PGXN extensions tagged "[_1]"' => 'A list of PGXN extensions tagged â[_1]â',
'PGXN [_1] search results for "[_2]"' => 'PGXN [_1] search results for â[_2]â',
'Submit feedback to PGXN or join the mail list' => 'Submit feedback to PGXN or join the mail list',
'Background on PGXN' => 'All about PGXN, what itâs for, what it contains, who made it, and why',
'donor description' => 'Many thanks to these fine organizations and people who contributed support to make the develpoment of PGXN possible',
'identity description' => 'All about the PGXN identity: who created it, its license, and downloadable assets',
'faq description' => 'Frequently asked questions about the PostgreSQL Extension Network',
'mirroring description' => 'Step-by-step instructions for mirroring PGXN on your own server',
'Recent PostgreSQL extension releases on PGXN' => 'Recent PostgreSQL extension releases on PGXN',
donors_intro => 'All the great folks who funded the inital development of PGXN will be listed in perpetuity here on the âDonorsâ page of PGXN.org. All donors are invited to the PGXN Launch Party at <a href="https://www.pgcon.org/2011/">PGCon<...
);
sub accept {
shift->get_handle( I18N::LangTags::Detect->http_accept_langs(shift) );
}
sub list {
my ($lh, $items) = @_;
return unless @{ $items };
return $items->[0] if @{ $items } == 1;
my $last = pop @{ $items };
my $comma = $lh->maketext('listcomma');
my $ret = join "$comma ", @$items;
$ret .= $comma if @{ $items } > 1;
my $and = $lh->maketext('listand');
return "$ret $and $last";
}
sub qlist {
my ($lh, $items) = @_;
return unless @{ $items };
my $open = $lh->maketext('openquote');
my $shut = $lh->maketext('shutquote');
return $open . $items->[0] . $shut if @{ $items } == 1;
my $last = pop @{ $items };
my $comma = $lh->maketext('listcomma');
my $ret = $open . join("$shut$comma $open", @$items) . $shut;
$ret .= $comma if @{ $items } > 1;
my $and = $lh->maketext('listand');
return "$ret $and $open$last$shut";
}
my %PATHS_FOR;
sub DESTROY {
delete $PATHS_FOR{ ref shift };
}
sub from_file {
my ($self, $path) = (shift, shift);
my $class = ref $self;
my $file = $PATHS_FOR{$class}{$path} ||= _find_file($class, $path);
open my $fh, '<:utf8', $file or die "Cannot open $file: $!\n";
my $value = do { local $/; $self->_compile(<$fh>); };
return ref $value eq 'CODE' ? $value->($self, @_) : ${ $value };
}
sub _find_file {
my $class = shift;
my @path = split m{/}, shift;
(my $dir = __FILE__) =~ s{[.]pm$}{};
no strict 'refs';
foreach my $super ($class, @{$class . '::ISA'}, __PACKAGE__ . '::en') {
my $file = File::Spec->catfile($dir, $super->language_tag, @path);
return $file if -e $file;
}
croak "No file found for path " . join('/', @path);
}
1;
=encoding utf8
=head1 Name
PGXN::Site::Locale - Localization for PGXN::Site
=head1 Synopsis
use PGXN::Site::Locale;
my $mt = PGXN::Site::Locale->accept($env->{HTTP_ACCEPT_LANGUAGE});
=head1 Description
This class provides localization support for PGXN::Site. Each locale must
create a subclass named for the locale and put its translations in the
C<%Lexicon> hash. It is further designed to support easy creation of
a handle from an HTTP_ACCEPT_LANGUAGE header.
=head1 Interface
The interface inherits from L<Locale::Maketext> and adds the following
method.
=head2 Constructor Methods
=head3 C<accept>
my $mt = PGXN::Site::Locale->accept($env->{HTTP_ACCEPT_LANGUAGE});
Returns a PGXN::Site::Locale handle appropriate for the specified
argument, which must take the form of the HTTP_ACCEPT_LANGUAGE string
typically created in web server environments and specified in L<RFC
3282|https://tools.ietf.org/html/rfc3282>. The parsing of this header is
handled by L<I18N::LangTags::Detect>.
=head2 Instance Methods
=head3 C<list>
# "Missing these keys: foo, bar, and baz"
say $mt->maketext(
'Missing these keys: [list,_1])'
[qw(foo bar baz)],
);
Formats a list of items. The list of items to be formatted should be passed as
an array reference. If there is only one item, it will be returned. If there
are two, they will be joined with " and ". If there are more, there will be a
comma-separated list with the final item joined on ", and ".
( run in 0.556 second using v1.01-cache-2.11-cpan-71847e10f99 )