| 1 | package Silki::Localize::Gettext; | ||||||||||||||||||||
| 2 | { | ||||||||||||||||||||
| 3 | 6 | $Silki::Localize::Gettext::VERSION = '0.29'; | |||||||||||||||||||
| 4 | } | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 6 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 6 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 6 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 6 | ▶ | use feature ':5.10'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 6 | ▶ | use Silki::Localize::Format::Gettext; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 6 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 6 | extends 'Data::Localize::Gettext'; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | # Overrides parent to do parent locale lookup and return id if no msgstr is | ||||||||||||||||||||
| 19 | # found | ||||||||||||||||||||
| 20 | 24 | ▶ | sub get_lexicon { | ||||||||||||||||||
|
Subroutine
get_lexicon: called CC=5 SCAR=19.7
Pod
documented
| |||||||||||||||||||||
| 21 | 24 | my $self = shift; | |||||||||||||||||||
| 22 | 24 | my $lang = shift; | |||||||||||||||||||
| 23 | 24 | my $id = shift; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 24 | my $lexicon; | |||||||||||||||||||
| 26 | 24 | ▶ | until ( $lexicon = $self->get_lexicon_map($lang) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | 0 | $lang = $self->_parent_lang($lang); | |||||||||||||||||||
| 28 | 0 | ▶ | last unless $lang; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 24 | ▶ | return () unless $lexicon; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 24 | ▶ | return $lexicon->get($id) || $id; | ||||||||||||||||||
|
Condition33%1/3
$lexicon->get($id) || $id
MC/DC0%0/2
$lexicon->get($id) || $id
$lexicon->get($id)
$id
Truth table33%1/3
A || B
A= $lexicon->get($id)B= $id
| |||||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | # The parsing of locale codes and fallback logic is borrowed from LDML.pm in | ||||||||||||||||||||
| 37 | # the DateTime::Locale distro. | ||||||||||||||||||||
| 38 | 0 | ▶ | sub _parent_lang { | ||||||||||||||||||
|
Subroutine
_parent_lang: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||||||||||
| 40 | 0 | my $lang = shift; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | my @parts = $self->_parse_lang($lang); | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | pop @parts; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | return join '_', @parts; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | ▶ | sub _parse_lang { | ||||||||||||||||||
|
Subroutine
_parse_lang: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 50 | 0 | my $self = shift; | |||||||||||||||||||
| 51 | 0 | my $lang = shift; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | return grep {defined} $lang =~ /([a-z]+) # language | |||||||||||||||||||
| 54 | (?: [-_]([A-Z][a-z]+) )? # script - Title Case - optional | ||||||||||||||||||||
| 55 | (?: [-_]([A-Z]+) )? # territory - ALL CAPS - optional | ||||||||||||||||||||
| 56 | (?: [-_]([A-Z]+) )? # variant - ALL CAPS - optional | ||||||||||||||||||||
| 57 | /x; | ||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 1 | ▶ | sub _build_formatter { | ||||||||||||||||||
|
Subroutine
_build_formatter: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 61 | 1 | return Silki::Localize::Format::Gettext->new(); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 6 | __PACKAGE__->meta()->make_immutable(); | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 6 | 1; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | # ABSTRACT: A subclass of Data::Localize::Gettext | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||