| 1 | #!/usr/bin/env perl | ||||||||||||||||||||
| 2 | # -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*- | ||||||||||||||||||||
| 3 | # vim:ts=8:sw=2:et:sta:sts=2 | ||||||||||||||||||||
| 4 | ######### | ||||||||||||||||||||
| 5 | # Author: rmp | ||||||||||||||||||||
| 6 | # | ||||||||||||||||||||
| 7 | package ClearPress::Localize; | ||||||||||||||||||||
| 8 | 7 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 7 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 7 | ▶ | use base qw(Locale::Maketext); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 7 | ▶ | use HTTP::ClientDetect::Language; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 7 | ▶ | use Locale::Maketext::Lexicon { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 7 | _auto => 1, | |||||||||||||||||||
| 14 | _style => 'gettext', | ||||||||||||||||||||
| 15 | 7 | }; | |||||||||||||||||||
| 16 | 7 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 7 | our $VERSION = q[2026.07.25]; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 83 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 21 | 83 | my ($class, $locales) = @_; | |||||||||||||||||||
| 22 | 83 | Locale::Maketext::Lexicon->import($locales); | |||||||||||||||||||
| 23 | 83 | return 1; | |||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | sub lang { | ||||||||||||||||||
|
Subroutine
lang: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 27 | 0 | my $lang_detect = HTTP::ClientDetect::Language->new(server_default => 'en_GB'); | |||||||||||||||||||
| 28 | my $req = { | ||||||||||||||||||||
| 29 | accept_language => $ENV{HTTP_ACCEPT_LANGUAGE}, | ||||||||||||||||||||
| 30 | 0 | }; | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | my $sym = \%ClearPress::request::; | |||||||||||||||||||
| 33 | 0 | ▶ | if(!exists $sym->{accept_language}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 0 | ▶ | *ClearPress::request::accept_language = sub { my $self = shift; return $self->{accept_language}; }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | bless $req, 'ClearPress::request'; | |||||||||||||||||||
| 38 | 0 | my $lang = $lang_detect->language($req); | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | # if($lang) { | ||||||||||||||||||||
| 41 | # carp qq[Detected $lang from $ENV{HTTP_ACCEPT_LANGUAGE}]; | ||||||||||||||||||||
| 42 | # } | ||||||||||||||||||||
| 43 | 0 | return $lang; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | ▶ | sub localizer { | ||||||||||||||||||
|
Subroutine
localizer: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 47 | 0 | my ($class, $lang) = @_; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | ▶ | my $lh = __PACKAGE__->get_handle($lang || __PACKAGE__->lang()); | ||||||||||||||||||
|
Condition0%0/3
$lang || __PACKAGE__->lang
MC/DC0%0/2
$lang || __PACKAGE__->lang
$lang
__PACKAGE__->lang
Truth table0%0/3
A || B
A= $langB= __PACKAGE__->lang
| |||||||||||||||||||||
| 50 | 0 | ▶ | if(!$lh) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 0 | carp qq[Could not construct localizer for $lang]; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | 0 | return $lh; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 7 | 1; | |||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||