| 1 | ############################################################################## | ||||||||||||||||||||||||||||
| 2 | # The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. # | ||||||||||||||||||||||||||||
| 3 | # # | ||||||||||||||||||||||||||||
| 4 | # This program is free software; you can redistribute it and/or # | ||||||||||||||||||||||||||||
| 5 | # modify it under the terms of the GNU General Public License # | ||||||||||||||||||||||||||||
| 6 | # as published by the Free Software Foundation; either version 2 # | ||||||||||||||||||||||||||||
| 7 | # of the License, or (at your option) any later version. # | ||||||||||||||||||||||||||||
| 8 | # # | ||||||||||||||||||||||||||||
| 9 | # This program is distributed in the hope that it will be useful, # | ||||||||||||||||||||||||||||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||||||||||||||||||||||||||||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||||||||||||||||||||||||||||
| 12 | # GNU General Public License for more details. # | ||||||||||||||||||||||||||||
| 13 | # # | ||||||||||||||||||||||||||||
| 14 | # You should have received a copy of the GNU General Public License # | ||||||||||||||||||||||||||||
| 15 | # along with this program; if not, write to the Free Software # | ||||||||||||||||||||||||||||
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.# | ||||||||||||||||||||||||||||
| 17 | # # | ||||||||||||||||||||||||||||
| 18 | # Jon Howell can be contacted at: # | ||||||||||||||||||||||||||||
| 19 | # 6211 Sudikoff Lab, Dartmouth College # | ||||||||||||||||||||||||||||
| 20 | # Hanover, NH 03755-3510 # | ||||||||||||||||||||||||||||
| 21 | # jonh@cs.dartmouth.edu # | ||||||||||||||||||||||||||||
| 22 | # # | ||||||||||||||||||||||||||||
| 23 | # An electronic copy of the GPL is available at: # | ||||||||||||||||||||||||||||
| 24 | # http://www.gnu.org/copyleft/gpl.html # | ||||||||||||||||||||||||||||
| 25 | # # | ||||||||||||||||||||||||||||
| 26 | ############################################################################## | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | ### | ||||||||||||||||||||||||||||
| 31 | ### I18N.pm | ||||||||||||||||||||||||||||
| 32 | ### | ||||||||||||||||||||||||||||
| 33 | ### Internationalization support routines | ||||||||||||||||||||||||||||
| 34 | ### | ||||||||||||||||||||||||||||
| 35 | # huge THANKS: to Dirk Hansen and Okke Timm, who did the first translation | ||||||||||||||||||||||||||||
| 36 | # (to German), which involved weaving gettext() calls all over the code. | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | package FAQ::OMatic::I18N; | ||||||||||||||||||||||||||||
| 39 | #use Locale::PGetText; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | ▶ | use FAQ::OMatic; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use Exporter (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | use vars qw(@ISA @EXPORT); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | @EXPORT = qw(&gettext &gettexta &gettext_noop); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 53 | 0 | my $force = shift; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my $tx = FAQ::OMatic::getLocal('i18n'); | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ($force or not defined $tx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$force or not defined $tx
MC/DC0%0/2
$force or not defined $tx
$force
not defined $tx
Truth table0%0/3
A or not(B)
A= $forceB= not defined $tx
| |||||||||||||||||||||||||||||
| 57 | 0 | $tx = {}; | |||||||||||||||||||||||||||
| 58 | 0 | bless $tx; | |||||||||||||||||||||||||||
| 59 | 0 | $tx->load(); | |||||||||||||||||||||||||||
| 60 | 0 | FAQ::OMatic::setLocal('i18n', $tx); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 0 | return $tx; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub reload { | ||||||||||||||||||||||||||
|
Subroutine
reload: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | # force next gettext() to reload | ||||||||||||||||||||||||||||
| 67 | 0 | my $tx = new FAQ::OMatic::I18N('force'); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | ▶ | sub language { | ||||||||||||||||||||||||||
|
Subroutine
language: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | 2 | ▶ | return $FAQ::OMatic::Config::language || 'en'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$FAQ::OMatic::Config::language || 'en'
MC/DC0%0/1
$FAQ::OMatic::Config::language || 'en'
$FAQ::OMatic::Config::language
Truth table50%1/2
A
A= $FAQ::OMatic::Config::language
| |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($self->language() ne 'en') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | my $kit = "FAQ/OMatic/Language_".$self->language().".pm"; | |||||||||||||||||||||||||||
| 78 | 0 | eval { | |||||||||||||||||||||||||||
| 79 | 0 | require $kit; | |||||||||||||||||||||||||||
| 80 | }; | ||||||||||||||||||||||||||||
| 81 | 0 | translations($self); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub gettext { | ||||||||||||||||||||||||||
|
Subroutine
gettext: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 0 | my $text = shift; | |||||||||||||||||||||||||||
| 87 | 0 | my $tx = new FAQ::OMatic::I18N(); | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $translated = $tx->{$text} || $text; | ||||||||||||||||||||||||||
|
Condition0%0/3
$tx->{$text} || $text
MC/DC0%0/2
$tx->{$text} || $text
$tx->{$text}
$text
Truth table0%0/3
A || B
A= $tx->{$text}B= $text
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if (language() ne 'en' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
language() ne "en" and not exists $tx->{$text}
MC/DC0%0/2
language() ne "en" and not exists $tx->{$text}
language() ne "en"
not exists $tx->{$text}
Truth table0%0/3
A and not(B)
A= language() ne "en"B= not exists $tx->{$text}
| |||||||||||||||||||||||||||||
| 90 | and not exists $tx->{$text}) { | ||||||||||||||||||||||||||||
| 91 | 0 | FAQ::OMatic::gripe('debug', "No \"" | |||||||||||||||||||||||||||
| 92 | .$tx->language()."\" translation for \"$text\""); | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 0 | return $translated; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub gettexta { | ||||||||||||||||||||||||||
|
Subroutine
gettexta: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 98 | # a slower version that plugs in arguments. | ||||||||||||||||||||||||||||
| 99 | # (if perl were partially evaluated, we'd only have this | ||||||||||||||||||||||||||||
| 100 | # sub, and gettext would be the curried version. :v) | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | my $text = shift; | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | if (not defined($text)) {$text = ''}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | my $translated = gettext($text); | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | if (not defined($translated)) {$translated = ''}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | my $arg; | |||||||||||||||||||||||||||
| 108 | 0 | my $i=0; | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | $translated =~ s/\%(\d+)/defined($_[$1])?$_[$1]:('%'.$1)/sge; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | return $translated; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | sub gettext_noop | ||||||||||||||||||||||||||||
| 114 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
gettext_noop: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 0 | return $_[0]; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 1 | 1; | |||||||||||||||||||||||||||