| 1 | package Silki::Localize::Format::Gettext; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 6 | $Silki::Localize::Format::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 DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use DateTime::Locale; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use HTML::Entities qw( encode_entities ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use Silki::I18N (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 6 | extends 'Data::Localize::Format::Gettext'; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | sub html { | ||||||||||||||||||||||||||
|
Subroutine
html: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 23 | 1 | my $lang = shift; | |||||||||||||||||||||||||||
| 24 | 1 | my $args = shift; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | return encode_entities( $args->[0] ); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 6 | ▶ | sub quant { | ||||||||||||||||||||||||||
|
Subroutine
quant: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 31 | 6 | my $lang = shift; | |||||||||||||||||||||||||||
| 32 | 6 | my $args = shift; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 6 | my $num = shift @{$args}; | |||||||||||||||||||||||||||
| 35 | 6 | $num += 0; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 6 | my @forms = @{$args}; | |||||||||||||||||||||||||||
| 38 | 6 | s/^\s+|\s+$//g for @forms; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 6 | ▶ | die "quant can only be called with 2 or 3 forms" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@forms == 2 or @forms == 3
MC/DC100%2/2
@forms == 2 or @forms == 3
@forms == 2
@forms == 3
Truth table100%3/3
A or B
A= @forms == 2B= @forms == 3
| |||||||||||||||||||||||||||||
| 41 | unless @forms == 2 || @forms == 3; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 4 | ▶ | return $forms[2] if @forms == 3 && $num == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@forms == 3 and $num == 0
MC/DC50%1/2
@forms == 3 and $num == 0
@forms == 3
$num == 0
Truth table66%2/3
A and B
A= @forms == 3B= $num == 0
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | return ( | ||||||||||||||||||||||||||||
| 46 | 3 | ▶ | $self->_number($num) . q{ } . ( $num == 1 ? $forms[0] : $forms[1] ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 3 | ▶ | sub _number { | ||||||||||||||||||||||||||
|
Subroutine
_number: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 3 | return $_[0]; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 6 | ▶ | sub on_date { | ||||||||||||||||||||||||||
|
Subroutine
on_date: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 57 | 6 | my $lang = shift; | |||||||||||||||||||||||||||
| 58 | 6 | my $args = shift; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 6 | my $dt = $args->[0]; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 6 | my $day_key = $self->_day_key_for_dt($dt); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 6 | my $id; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 6 | given ($day_key) { | |||||||||||||||||||||||||||
| 67 | 6 | when ('today') { $id = loc('Today') } | |||||||||||||||||||||||||||
| 68 | 5 | when ('yesterday') { $id = loc('Yesterday') } | |||||||||||||||||||||||||||
| 69 | 0 | when ('two_days_ago') { $id = loc('Two days ago') } | |||||||||||||||||||||||||||
| 70 | 0 | when ('three_days_ago') { $id = loc('Three days ago') } | |||||||||||||||||||||||||||
| 71 | 4 | when ('any') { $id = loc('on %date(%1)') } | |||||||||||||||||||||||||||
| 72 | 0 | default { die "Unknown day key: $day_key" } | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 6 | return Silki::I18N::loc( $id, $dt ); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 4 | ▶ | sub on_datetime { | ||||||||||||||||||||||||||
|
Subroutine
on_datetime: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 80 | 4 | my $lang = shift; | |||||||||||||||||||||||||||
| 81 | 4 | my $args = shift; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 4 | my $dt = $args->[0]; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 4 | my $day_key = $self->_day_key_for_dt($dt); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 4 | my $id; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 4 | given ($day_key) { | |||||||||||||||||||||||||||
| 90 | 4 | when ('today') { $id = loc('Today %at_time(%1)') } | |||||||||||||||||||||||||||
| 91 | 3 | when ('yesterday') { $id = loc('Yesterday %at_time(%1)') } | |||||||||||||||||||||||||||
| 92 | 0 | when ('two_days_ago') { $id = loc('Two days ago %at_time(%1)') } | |||||||||||||||||||||||||||
| 93 | 0 | when ('three_days_ago') { $id = loc('Three days ago %at_time(%1)') } | |||||||||||||||||||||||||||
| 94 | 2 | when ('any') { $id = loc('on %date(%1) %at_time(%1)') } | |||||||||||||||||||||||||||
| 95 | 0 | default { die "Unknown day key: $day_key" } | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 4 | return Silki::I18N::loc( $id, $dt ); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 14 | ▶ | sub _day_key_for_dt { | ||||||||||||||||||||||||||
|
Subroutine
_day_key_for_dt: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 102 | 14 | my $self = shift; | |||||||||||||||||||||||||||
| 103 | 14 | my $dt = shift; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 14 | my $date = $dt->clone()->truncate( to => 'day' ); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 14 | my $cmp = DateTime->today( time_zone => $dt->time_zone() ); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 14 | ▶ | return 'today' if $date eq $cmp; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 11 | $cmp->subtract( days => 1 ); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 11 | ▶ | return 'yesterday' if $date eq $cmp; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | # $cmp->subtract( days => 1 ); | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # return 'two_days' | ||||||||||||||||||||||||||||
| 118 | # if $date eq $cmp && $dt->locale()->relative_field_name( 'day', -2 ); | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # $cmp->subtract( days => 1 ); | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # return 'three_days' | ||||||||||||||||||||||||||||
| 123 | # if $date eq $cmp && $dt->locale()->relative_field_name( 'day', -3 ); | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 8 | return 'any'; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 8 | ▶ | sub date { | ||||||||||||||||||||||||||
|
Subroutine
date: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 129 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 130 | 8 | my $lang = shift; | |||||||||||||||||||||||||||
| 131 | 8 | my $args = shift; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 8 | my $dt = $args->[0]; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 8 | my $locale = DateTime::Locale->load($lang); | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 8 | my $today = DateTime->today( time_zone => $dt->time_zone() ); | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 8 | my $format_dt = $dt->clone()->set( locale => $locale ); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 8 | ▶ | my $cldr | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | = $format_dt->year() eq $today->year() | ||||||||||||||||||||||||||||
| 143 | ? $locale->format_for('MMMd') | ||||||||||||||||||||||||||||
| 144 | : $locale->date_format_default(); | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 8 | return $format_dt->format_cldr($cldr); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 4 | ▶ | sub datetime { | ||||||||||||||||||||||||||
|
Subroutine
datetime: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 150 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 151 | 4 | my $lang = shift; | |||||||||||||||||||||||||||
| 152 | 4 | my $args = shift; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 4 | my $dt = $args->[0]; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 4 | my $day_key = $self->_day_key_for_dt($dt); | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 4 | my $id; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 4 | given ($day_key) { | |||||||||||||||||||||||||||
| 161 | 4 | when ('today') { $id = loc('Today %at_time(%1)') } | |||||||||||||||||||||||||||
| 162 | 3 | when ('yesterday') { $id = loc('Yesterday %at_time(%1)') } | |||||||||||||||||||||||||||
| 163 | 0 | when ('two_days_ago') { $id = loc('Two days ago %at_time(%1)') } | |||||||||||||||||||||||||||
| 164 | 0 | when ('three_days_ago') { $id = loc('Three days ago %at_time(%1)') } | |||||||||||||||||||||||||||
| 165 | 2 | when ('any') { $id = loc('%date(%1) %at_time(%1)') } | |||||||||||||||||||||||||||
| 166 | 0 | default { die "Unknown day key: $day_key" } | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 4 | return Silki::I18N::loc( $id, $dt ); | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 10 | ▶ | sub at_time { | ||||||||||||||||||||||||||
|
Subroutine
at_time: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 173 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 174 | 10 | my $lang = shift; | |||||||||||||||||||||||||||
| 175 | 10 | my $args = shift; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 10 | my $dt = $args->[0]; | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 10 | return Silki::I18N::loc( 'at %time(%1)', $dt ); | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 12 | ▶ | sub time { | ||||||||||||||||||||||||||
|
Subroutine
time: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 183 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 184 | 12 | my $lang = shift; | |||||||||||||||||||||||||||
| 185 | 12 | my $args = shift; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 12 | my $dt = $args->[0]; | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 12 | my $locale = DateTime::Locale->load($lang); | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 12 | my $format_dt = $dt->clone()->set( locale => $locale ); | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 12 | ▶ | my $cldr | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | = $locale->prefers_24_hour_time() | ||||||||||||||||||||||||||||
| 195 | ? $locale->format_for('Hm') | ||||||||||||||||||||||||||||
| 196 | : $locale->format_for('hm'); | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 12 | return $format_dt->format_cldr($cldr); | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # This exists so that the extraction code finds the strings up above and | ||||||||||||||||||||||||||||
| 202 | # sticks them in the .po files for translation. | ||||||||||||||||||||||||||||
| 203 | 14 | ▶ | sub loc { $_[0] } | ||||||||||||||||||||||||||
|
Subroutine
loc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 6 | __PACKAGE__->meta()->make_immutable(); | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 6 | 1; | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | # ABSTRACT: Provides functions for localization, like %date and %quant | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | __END__ | ||||||||||||||||||||||||||||