line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
# Curses::UI::Language |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (c) 2001-2002 by Maurice Makaay. All rights reserved. |
5
|
|
|
|
|
|
|
# This file is part of Curses::UI. Curses::UI is free software. |
6
|
|
|
|
|
|
|
# You can redistribute it and/or modify it under the same terms |
7
|
|
|
|
|
|
|
# as perl itself. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Currently maintained by Marcus Thiesen |
10
|
|
|
|
|
|
|
# e-mail: marcus@cpan.thiesenweb.de |
11
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Curses::UI::Language; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $default_lang = 'English'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %lang_alias = ( |
18
|
|
|
|
|
|
|
'en' => 'english', |
19
|
|
|
|
|
|
|
'uk' => 'english', |
20
|
|
|
|
|
|
|
'us' => 'english', |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
'it' => 'italian', |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
'pl' => 'polish', |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
'ru' => 'russian', |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
'de' => 'german', |
29
|
|
|
|
|
|
|
'at' => 'german', |
30
|
|
|
|
|
|
|
'ch' => 'german', |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
'du' => 'dutch', |
33
|
|
|
|
|
|
|
'nl' => 'dutch', |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
'fr' => 'french', |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
'pt' => 'portuguese', |
38
|
|
|
|
|
|
|
'pt_BR' => 'portuguese', |
39
|
|
|
|
|
|
|
'br' => 'portuguese', |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
'no' => 'norwegian', |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
'es' => 'spanish', |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
'tr' => 'tukish', |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
'cn' => 'chinese', |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub new() |
52
|
|
|
|
|
|
|
{ |
53
|
9
|
|
|
9
|
0
|
50
|
my $class = shift; |
54
|
9
|
|
|
|
|
20
|
my $lang = shift; |
55
|
|
|
|
|
|
|
|
56
|
9
|
|
|
|
|
44
|
my $this = { |
57
|
|
|
|
|
|
|
-tags => {}, |
58
|
|
|
|
|
|
|
-lang => undef, |
59
|
|
|
|
|
|
|
}; |
60
|
9
|
|
|
|
|
29
|
bless $this, $class; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Load english tags so these can be used |
63
|
|
|
|
|
|
|
# as a fallback for other languages. |
64
|
9
|
|
|
|
|
39
|
$this->loadlanguage('english'); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Load the wanted language. |
67
|
9
|
|
|
|
|
33
|
$this->loadlanguage($lang); |
68
|
|
|
|
|
|
|
|
69
|
9
|
|
|
|
|
28
|
return $this; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub loadlanguage($;) |
73
|
|
|
|
|
|
|
{ |
74
|
18
|
|
|
18
|
0
|
29
|
my $this = shift; |
75
|
18
|
|
|
|
|
29
|
my $lang = shift; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Construct the language module to use. |
78
|
18
|
100
|
|
|
|
58
|
$lang = $default_lang unless defined $lang; |
79
|
18
|
|
|
|
|
45
|
$lang =~ s/[^\w\_]//g; |
80
|
18
|
|
|
|
|
34
|
$lang = lc $lang; |
81
|
18
|
50
|
|
|
|
67
|
$lang = $lang_alias{$lang} if defined $lang_alias{$lang}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Loading the same language twice is not very useful. |
84
|
18
|
100
|
66
|
|
|
138
|
return $this if defined $this->{-lang} and |
85
|
|
|
|
|
|
|
$lang eq $this->{-lang}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Determine filename for the language package. |
88
|
9
|
|
|
|
|
91
|
(my $l_file = __FILE__) =~ s/\.pm$/\/$lang\.pm/; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Save the name of the currently loaded language. |
91
|
9
|
|
|
|
|
90
|
$this->{-lang} = $lang; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Create a filehandle to the __DATA__ section |
94
|
|
|
|
|
|
|
# of the language package. |
95
|
9
|
|
|
|
|
26
|
local *LANG_DATA; |
96
|
9
|
50
|
|
|
|
631
|
open(LANG_DATA, "< $l_file") or die "Can't open $l_file: $!"; |
97
|
|
|
|
|
|
|
|
98
|
9
|
|
|
|
|
261
|
while () { |
99
|
72
|
100
|
|
|
|
243
|
last if /^\s*__DATA__$/; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Read and store tags/blocks. |
103
|
9
|
|
|
|
|
22
|
my $tag = undef; |
104
|
9
|
|
|
|
|
17
|
my $block = ''; |
105
|
9
|
|
|
|
|
41
|
LINE: while () { |
106
|
639
|
100
|
|
|
|
2507
|
if (m/^#/) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
107
|
198
|
|
|
|
|
568
|
next LINE; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
elsif (m/^\s*\[\s*(.*)\s*\]\s*(.*)$/) { |
110
|
207
|
|
|
|
|
254
|
my $oldtag = $tag; |
111
|
207
|
|
|
|
|
315
|
$tag = $1; |
112
|
207
|
|
|
|
|
412
|
$this->store($oldtag, $block); |
113
|
207
|
|
|
|
|
319
|
$block = $2; |
114
|
207
|
50
|
|
|
|
786
|
$block = '' unless defined $block; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
elsif (defined $tag) { |
117
|
216
|
|
|
|
|
579
|
$block .= "$_"; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
elsif (!m/^\s*$/) { |
120
|
0
|
|
|
|
|
0
|
warn "$l_file, line $.: found data outside tag block\n"; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
9
|
|
|
|
|
30
|
$this->store($tag, $block); |
124
|
|
|
|
|
|
|
|
125
|
9
|
|
|
|
|
384
|
close(LANG_DATA); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub store($$;) |
129
|
|
|
|
|
|
|
{ |
130
|
216
|
|
|
216
|
0
|
237
|
my $this = shift; |
131
|
216
|
|
|
|
|
244
|
my $tag = shift; |
132
|
216
|
|
|
|
|
234
|
my $block = shift; |
133
|
|
|
|
|
|
|
|
134
|
216
|
100
|
|
|
|
419
|
return $this unless defined $tag; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Remove empty start- and endlines. |
137
|
207
|
|
|
|
|
520
|
my @block = split /\n/, $block; |
138
|
207
|
|
33
|
|
|
1137
|
while (@block and $block[0] =~ /^\s*$/) { shift @block } |
|
0
|
|
|
|
|
0
|
|
139
|
207
|
|
33
|
|
|
944
|
while (@block and $block[-1] =~ /^\s*$/) { pop @block } |
|
0
|
|
|
|
|
0
|
|
140
|
|
|
|
|
|
|
|
141
|
207
|
|
|
|
|
754
|
$this->{-tags}->{lc $tag} = join "\n", @block; |
142
|
|
|
|
|
|
|
|
143
|
207
|
|
|
|
|
367
|
return $this; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub get($;) |
148
|
|
|
|
|
|
|
{ |
149
|
0
|
|
|
0
|
0
|
|
my $this = shift; |
150
|
0
|
|
|
|
|
|
my $tag = shift; |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
my $block = $this->{-tags}->{$tag}; |
153
|
0
|
0
|
|
|
|
|
unless (defined $block) { |
154
|
0
|
|
|
|
|
|
warn "get(): no language block for tag '$tag'"; |
155
|
0
|
|
|
|
|
|
$block = ''; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return $block; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub getarray($;) |
162
|
|
|
|
|
|
|
{ |
163
|
0
|
|
|
0
|
0
|
|
my $this = shift; |
164
|
0
|
|
|
|
|
|
my $tag = shift; |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
my $block = $this->get($tag); |
167
|
0
|
0
|
|
|
|
|
return () unless defined $block; |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
$block =~ s/\n/ /g; |
170
|
0
|
|
|
|
|
|
return split " ", $block; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |