| 1 | # -*- perl -*- | ||||||||||||||
| 2 | # | ||||||||||||||
| 3 | # HTML::EP - A Perl based HTML extension. | ||||||||||||||
| 4 | # | ||||||||||||||
| 5 | # | ||||||||||||||
| 6 | # Copyright (C) 1998 Jochen Wiedmann | ||||||||||||||
| 7 | # Am Eisteich 9 | ||||||||||||||
| 8 | # 72555 Metzingen | ||||||||||||||
| 9 | # Germany | ||||||||||||||
| 10 | # | ||||||||||||||
| 11 | # Phone: +49 7123 14887 | ||||||||||||||
| 12 | # Email: joe@ispsoft.de | ||||||||||||||
| 13 | # | ||||||||||||||
| 14 | # All rights reserved. | ||||||||||||||
| 15 | # | ||||||||||||||
| 16 | # You may distribute this module under the terms of either | ||||||||||||||
| 17 | # the GNU General Public License or the Artistic License, as | ||||||||||||||
| 18 | # specified in the Perl README file. | ||||||||||||||
| 19 | # | ||||||||||||||
| 20 | ############################################################################ | ||||||||||||||
| 21 | |||||||||||||||
| 22 | 5 | require 5.004; | |||||||||||||
| 23 | 5 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | 5 | ▶ | use HTML::EP (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 26 | |||||||||||||||
| 27 | |||||||||||||||
| 28 | package HTML::EP::Locale; | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 5 | @HTML::EP::Locale::ISA = qw(HTML::EP); | |||||||||||||
| 31 | |||||||||||||||
| 32 | |||||||||||||||
| 33 | 15 | ▶ | sub init ($$) { | ||||||||||||
|
Subroutine
init: called CC=12 SCAR=31.4
Pod
undocumented
| |||||||||||||||
| 34 | 15 | my $self = shift; my $attr = shift; | |||||||||||||
| 35 | 15 | ▶ | return $self->{'_ep_language'} if $self->{'_ep_language'}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | 15 | $self->SUPER::init(); | |||||||||||||
| 37 | |||||||||||||||
| 38 | # Try to guess a language. First try to guess what languages are | ||||||||||||||
| 39 | # offered. | ||||||||||||||
| 40 | 15 | my @offered; | |||||||||||||
| 41 | 15 | ▶ | if ($attr->{'accept-language'}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | 11 | @offered = split(/,/, $attr->{'accept-language'}); | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | 15 | ▶ | @offered = ($self->{'_ep_config'}->{'default_language'}, "en") | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | unless @offered; | ||||||||||||||
| 46 | |||||||||||||||
| 47 | # Next, try to guess what the user wants. First let's see, if there | ||||||||||||||
| 48 | # is a CGI variable 'language'. | ||||||||||||||
| 49 | 15 | my $get; | |||||||||||||
| 50 | 15 | ▶ | if (my $lang = $self->{'cgi'}->param('language')) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | 0 | foreach my $l (@offered) { | |||||||||||||
| 52 | 0 | ▶ | return ($self->{'_ep_language'} = $l) if $l eq $lang; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | } | ||||||||||||||
| 54 | } | ||||||||||||||
| 55 | # If there's no such CGI variable, look at the value of | ||||||||||||||
| 56 | # $ENV{'HTTP_ACCEPT_LANGUAGE'}. | ||||||||||||||
| 57 | 15 | ▶ | if (exists($ENV{'HTTP_ACCEPT_LANGUAGE'})) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | 0 | ▶ | foreach my $lang (split(/\s*,\s*/, | ||||||||||||
|
Condition0%0/2
$ENV{'HTTP_ACCEPT_LANGUAGE'} || ''
MC/DC0%0/1
$ENV{'HTTP_ACCEPT_LANGUAGE'} || ''
$ENV{'HTTP_ACCEPT_LANGUAGE'}
Truth table0%0/2
A
A= $ENV{'HTTP_ACCEPT_LANGUAGE'}
| |||||||||||||||
| 59 | ($ENV{'HTTP_ACCEPT_LANGUAGE'} || ''))) { | ||||||||||||||
| 60 | 0 | foreach my $l (@offered) { | |||||||||||||
| 61 | 0 | ▶ | return ($self->{'_ep_language'} = $l) if $l eq $lang; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | } | ||||||||||||||
| 63 | } | ||||||||||||||
| 64 | } | ||||||||||||||
| 65 | # If anything else fails, choose a default language | ||||||||||||||
| 66 | 15 | return $self->{'_ep_language'} = $offered[0]; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | |||||||||||||||
| 70 | 12 | ▶ | sub _ep_language { | ||||||||||||
|
Subroutine
_ep_language: called CC=14 SCAR=26.5
| |||||||||||||||
| 71 | 12 | my($self, $attr, $tokens) = @_; | |||||||||||||
| 72 | 12 | my $language = $self->{'_ep_language'}; | |||||||||||||
| 73 | 12 | my $debug = $self->{'debug'}; | |||||||||||||
| 74 | return exists $attr->{$language} ? $attr->{$language} : '' | ||||||||||||||
| 75 | 12 | ▶ | unless exists $attr->{'language'}; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 76 | |||||||||||||||
| 77 | 9 | my $level = 0; | |||||||||||||
| 78 | 9 | my $state = $attr->{'language'} eq $language; | |||||||||||||
| 79 | 9 | my $state_done = $state; | |||||||||||||
| 80 | 9 | ▶ | my $start = $tokens->First() if $state; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 81 | 9 | my $last; | |||||||||||||
| 82 | 9 | ▶ | while (defined(my $token = $tokens->Token())) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 83 | 24 | ▶ | if ($token->{'type'} eq 'S') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 84 | 3 | ▶ | if ($token->{'tag'} eq 'ep-language') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 85 | 3 | ▶ | if ($state) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 86 | 1 | $last = $tokens->First()-1; | |||||||||||||
| 87 | 1 | $state = 0; | |||||||||||||
| 88 | } elsif (!$state_done) { | ||||||||||||||
| 89 | 2 | my $at = $self->ParseAttr($token->{'attr'}); | |||||||||||||
| 90 | 2 | ▶ | if ($state = ($at->{'language'} eq $language)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | 1 | $start = $tokens->First(); | |||||||||||||
| 92 | 1 | $state_done = 1; | |||||||||||||
| 93 | } | ||||||||||||||
| 94 | } | ||||||||||||||
| 95 | } | ||||||||||||||
| 96 | } elsif ($token->{'type'} eq 'E') { | ||||||||||||||
| 97 | 9 | ▶ | if ($token->{'tag'} eq 'ep-language') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 98 | 9 | ▶ | return '' unless $state_done; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 99 | 4 | ▶ | $last = $tokens->First()-1 if $state; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 100 | 4 | return $self->TokenMarch($tokens->Clone($start, $last)); | |||||||||||||
| 101 | } | ||||||||||||||
| 102 | } | ||||||||||||||
| 103 | } | ||||||||||||||
| 104 | 0 | die "ep-language without /ep-language"; | |||||||||||||
| 105 | } | ||||||||||||||
| 106 | |||||||||||||||
| 107 | |||||||||||||||
| 108 | 4 | ▶ | sub _format_DM { | ||||||||||||
|
Subroutine
_format_DM: called CC=2 SCAR=6.9
| |||||||||||||||
| 109 | 4 | my $self = shift; my $str = shift; | |||||||||||||
| 110 | 4 | $str = sprintf("%.2f DM", $str); | |||||||||||||
| 111 | 4 | ▶ | while ($str =~ s/(\d)(\d\d\d[\.\s])/$1 $2/) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 112 | } | ||||||||||||||
| 113 | 4 | $str =~ s/\./,/; | |||||||||||||
| 114 | 4 | $str; | |||||||||||||
| 115 | } | ||||||||||||||
| 116 | |||||||||||||||
| 117 | 1 | ▶ | sub _format_Dollar { | ||||||||||||
|
Subroutine
_format_Dollar: called CC=2 SCAR=7.0
| |||||||||||||||
| 118 | 1 | my $self = shift; my $str = shift; | |||||||||||||
| 119 | 1 | $str = sprintf("%.2f \$", $str); | |||||||||||||
| 120 | 1 | ▶ | while ($str =~ s/(\d)(\d\d\d[,\s])/$1 $2/) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 121 | } | ||||||||||||||
| 122 | 1 | $str; | |||||||||||||
| 123 | } | ||||||||||||||
| 124 | |||||||||||||||
| 125 | |||||||||||||||
| 126 | 2 | ▶ | sub _format_TIME { | ||||||||||||
|
Subroutine
_format_TIME: called CC=3 SCAR=11.0
| |||||||||||||||
| 127 | 2 | my $self = shift; my $date = shift; | |||||||||||||
| 128 | 2 | ▶ | if ($self->{'_ep_language'} eq 'de') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 129 | # Sun, 7 Feb 1999 18:17:57 +0100 | ||||||||||||||
| 130 | 1 | ▶ | if ($date =~ m{(\S+),\s+ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 131 | (\d+)\s+ | ||||||||||||||
| 132 | (\S+)\s+ | ||||||||||||||
| 133 | (\d+)\s+ | ||||||||||||||
| 134 | (\d+\:\d+\:\d+)\s+ | ||||||||||||||
| 135 | (\+\d+)}x) { | ||||||||||||||
| 136 | 1 | my %wdays = ('sun' => 0, 'mon' => 1, 'tue' => 2, | |||||||||||||
| 137 | 'wed' => 3, 'thu' => 4, 'fri' => 5, | ||||||||||||||
| 138 | 'sat' => 6); | ||||||||||||||
| 139 | my $wday = (('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', | ||||||||||||||
| 140 | 1 | 'Donnerstag', 'Freitag', 'Samstag')[$wdays{lc $1}]); | |||||||||||||
| 141 | 1 | my %months = ('jan' => 0, 'feb' => 1, 'mar' => 2, | |||||||||||||
| 142 | 'apr' => 3, 'may' => 4, 'jun' => 5, | ||||||||||||||
| 143 | 'jul' => 6, 'aug' => 7, 'sep' => 8, | ||||||||||||||
| 144 | 'oct' => 9, 'nov' => 10, 'dec' => 12 | ||||||||||||||
| 145 | ); | ||||||||||||||
| 146 | my $mon = (('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', | ||||||||||||||
| 147 | 'Juli', 'August', 'September', 'Oktober', 'November', | ||||||||||||||
| 148 | 1 | 'Dezember')[$months{lc $3}]); | |||||||||||||
| 149 | 1 | $date = "$wday, den $2. $mon $4, $5 Uhr ($6)"; | |||||||||||||
| 150 | } | ||||||||||||||
| 151 | } | ||||||||||||||
| 152 | 2 | $date; | |||||||||||||
| 153 | } | ||||||||||||||
| 154 | |||||||||||||||
| 155 | 5 | 1; | |||||||||||||