| 1 | package Localizer::Lexicon; | ||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use 5.010_001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Class::Accessor::Lite 0.05 ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | rw => [qw(dictionary)], | |||||||||||||||||||||||||||
| 9 | 5 | ); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 6 | my $class = shift; | |||||||||||||||||||||||||||
| 13 | 6 | ▶ | my $dictionary = { @_==1 ? %{$_[0]} : @_ }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 6 | bless { dictionary => $dictionary }, $class; | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | sub msgids { keys %{shift->dictionary} } | ||||||||||||||||||||||||||
|
Subroutine
msgids: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 30 | ▶ | sub msgstr { | ||||||||||||||||||||||||||
|
Subroutine
msgstr: called CC=3 SCAR=13.1
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 30 | my ( $self, $msgid ) = @_; | |||||||||||||||||||||||||||
| 21 | 30 | ▶ | ( exists $self->dictionary->{$msgid} && $self->dictionary->{$msgid} ) || undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->dictionary->{$msgid} and $self->dictionary->{$msgid}
MC/DC0%0/2
exists $self->dictionary->{$msgid} and $self->dictionary->{$msgid}
exists $self->dictionary->{$msgid}
$self->dictionary->{$msgid}
Truth table33%1/3
A and B
A= exists $self->dictionary->{$msgid}B= $self->dictionary->{$msgid}
| |||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 5 | 1; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =encoding utf-8 | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head1 NAME | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | Localizer::Lexicon - Default lexicon class | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | use Localizer::Resource; | ||||||||||||||||||||||||||||
| 35 | use Localizer::Style::Gettext; | ||||||||||||||||||||||||||||
| 36 | use Localizer::Lexicon | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | my $es = Localizer::Resource->new( | ||||||||||||||||||||||||||||
| 39 | dictionary => Localizer::Lexicon->new( 'Hi, %1.' => 'Hola %1.' ), | ||||||||||||||||||||||||||||
| 40 | format => Localizer::Style::Gettext->new(), | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | say $es->maketext("Hi, %1.", "John"); # => Hola, John. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | L<Localizer::Lexicon> is just the default lexicon that is built internally when you provide a hashref as your dictionary. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | You can implement your own class to replace this one as your L<Localizer> dictionary, for instance, to get your translations from a database or API. Just pass your object which implements msgids() and msgstr() like this one as your dictionary. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head1 METHODS | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =over 4 | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =item * Localizer::Lexicon->new(%args | \%args) | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Constructor. It will initialize the lexicon from a list or hashref | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | e.g. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | my $de = Localizer::Lexicon->new( | ||||||||||||||||||||||||||||
| 62 | 'Hello, World!' => 'Hello, Welt!' | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =over 8 | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =item dictionary: Hash Reference | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | Dictionary data to localize. | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =back | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =item * $localizer->msgids(); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Returns a list of msgeid's which are the keys of the dictionary. | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =item * $localizer->msgstr($msgid); | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | Return the message to translate given $msgid (dictionary data with key). If you give nonexistent key to this method, it returns undef. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =back | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | L<Locale::Maketext>, L<Locale::Maketext::Lexicon> | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Copyright (C) Tokuhiro Matsuno. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 92 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||