Lines 44-55
sub token_negligible_p( $ ) {
Link Here
|
44 |
my($x) = @_; |
44 |
my($x) = @_; |
45 |
my $t = $x->type; |
45 |
my $t = $x->type; |
46 |
return !$extract_all_p && ( |
46 |
return !$extract_all_p && ( |
47 |
$t == TmplTokenType::TEXT? string_negligible_p( $x->string ): |
47 |
$t == C4::TmplTokenType::TEXT? string_negligible_p( $x->string ): |
48 |
$t == TmplTokenType::DIRECTIVE? 1: |
48 |
$t == C4::TmplTokenType::DIRECTIVE? 1: |
49 |
$t == TmplTokenType::TEXT_PARAMETRIZED |
49 |
$t == C4::TmplTokenType::TEXT_PARAMETRIZED |
50 |
&& join( '', map { my $t = $_->type; |
50 |
&& join( '', map { my $t = $_->type; |
51 |
$t == TmplTokenType::DIRECTIVE? |
51 |
$t == C4::TmplTokenType::DIRECTIVE? |
52 |
'1': $t == TmplTokenType::TAG? |
52 |
'1': $t == C4::TmplTokenType::TAG? |
53 |
'': token_negligible_p( $_ )? |
53 |
'': token_negligible_p( $_ )? |
54 |
'': '1' } @{$x->children} ) eq '' ); |
54 |
'': '1' } @{$x->children} ) eq '' ); |
55 |
} |
55 |
} |
Lines 91-105
sub text_extract (*) {
Link Here
|
91 |
my $s = TmplTokenizer::next_token $h; |
91 |
my $s = TmplTokenizer::next_token $h; |
92 |
last unless defined $s; |
92 |
last unless defined $s; |
93 |
my($kind, $t, $attr) = ($s->type, $s->string, $s->attributes); |
93 |
my($kind, $t, $attr) = ($s->type, $s->string, $s->attributes); |
94 |
if ($kind eq TmplTokenType::TEXT) { |
94 |
if ($kind eq C4::TmplTokenType::TEXT) { |
95 |
if ($t =~ /\S/s && $t !~ /<!/){ |
95 |
if ($t =~ /\S/s && $t !~ /<!/){ |
96 |
remember( $s, $t ); |
96 |
remember( $s, $t ); |
97 |
} |
97 |
} |
98 |
} elsif ($kind eq TmplTokenType::TEXT_PARAMETRIZED) { |
98 |
} elsif ($kind eq C4::TmplTokenType::TEXT_PARAMETRIZED) { |
99 |
if ($s->form =~ /\S/s && $s->form !~ /<!/){ |
99 |
if ($s->form =~ /\S/s && $s->form !~ /<!/){ |
100 |
remember( $s, $s->form ); |
100 |
remember( $s, $s->form ); |
101 |
} |
101 |
} |
102 |
} elsif ($kind eq TmplTokenType::TAG && %$attr) { |
102 |
} elsif ($kind eq C4::TmplTokenType::TAG && %$attr) { |
103 |
# value [tag=input], meta |
103 |
# value [tag=input], meta |
104 |
my $tag = lc($1) if $t =~ /^<(\S+)/s; |
104 |
my $tag = lc($1) if $t =~ /^<(\S+)/s; |
105 |
for my $a ('alt', 'content', 'title', 'value','label') { |
105 |
for my $a ('alt', 'content', 'title', 'value','label') { |
Lines 165-183
msgstr ""
Link Here
|
165 |
EOF |
165 |
EOF |
166 |
my $directory_re = quotemeta("$directory/"); |
166 |
my $directory_re = quotemeta("$directory/"); |
167 |
for my $t (string_list) { |
167 |
for my $t (string_list) { |
168 |
if ($text{$t}->[0]->type == TmplTokenType::TEXT_PARAMETRIZED) { |
168 |
if ($text{$t}->[0]->type == C4::TmplTokenType::TEXT_PARAMETRIZED) { |
169 |
my($token, $n) = ($text{$t}->[0], 0); |
169 |
my($token, $n) = ($text{$t}->[0], 0); |
170 |
printf OUTPUT "#. For the first occurrence,\n" |
170 |
printf OUTPUT "#. For the first occurrence,\n" |
171 |
if @{$text{$t}} > 1 && $token->parameters_and_fields > 0; |
171 |
if @{$text{$t}} > 1 && $token->parameters_and_fields > 0; |
172 |
for my $param ($token->parameters_and_fields) { |
172 |
for my $param ($token->parameters_and_fields) { |
173 |
$n += 1; |
173 |
$n += 1; |
174 |
my $type = $param->type; |
174 |
my $type = $param->type; |
175 |
my $subtype = ($type == TmplTokenType::TAG |
175 |
my $subtype = ($type == C4::TmplTokenType::TAG |
176 |
&& $param->string =~ /^<input\b/is? |
176 |
&& $param->string =~ /^<input\b/is? |
177 |
$param->attributes->{'type'}->[1]: undef); |
177 |
$param->attributes->{'type'}->[1]: undef); |
178 |
my $fmt = TmplTokenizer::_formalize( $param ); |
178 |
my $fmt = TmplTokenizer::_formalize( $param ); |
179 |
$fmt =~ s/^%/%$n\$/; |
179 |
$fmt =~ s/^%/%$n\$/; |
180 |
if ($type == TmplTokenType::DIRECTIVE) { |
180 |
if ($type == C4::TmplTokenType::DIRECTIVE) { |
181 |
# $type = "Template::Toolkit Directive"; |
181 |
# $type = "Template::Toolkit Directive"; |
182 |
$type = $param->string =~ /\[%(.*?)%\]/is? $1: 'ERROR'; |
182 |
$type = $param->string =~ /\[%(.*?)%\]/is? $1: 'ERROR'; |
183 |
my $name = $param->string =~ /\bname=(["']?)([^\s"']+)\1/is? |
183 |
my $name = $param->string =~ /\bname=(["']?)([^\s"']+)\1/is? |
Lines 193-199
EOF
Link Here
|
193 |
. (defined $value? " value=$value->[1]": ''); |
193 |
. (defined $value? " value=$value->[1]": ''); |
194 |
} |
194 |
} |
195 |
} |
195 |
} |
196 |
} elsif ($text{$t}->[0]->type == TmplTokenType::TAG) { |
196 |
} elsif ($text{$t}->[0]->type == C4::TmplTokenType::TAG) { |
197 |
my($token) = ($text{$t}->[0]); |
197 |
my($token) = ($text{$t}->[0]); |
198 |
printf OUTPUT "#. For the first occurrence,\n" |
198 |
printf OUTPUT "#. For the first occurrence,\n" |
199 |
if @{$text{$t}} > 1 && $token->parameters_and_fields > 0; |
199 |
if @{$text{$t}} > 1 && $token->parameters_and_fields > 0; |
Lines 220-226
EOF
Link Here
|
220 |
$pathname =~ s/^.*\/koha-tmpl\/(.*)$/$1/; |
220 |
$pathname =~ s/^.*\/koha-tmpl\/(.*)$/$1/; |
221 |
printf OUTPUT "#: %s:%d\n", $pathname, $token->line_number |
221 |
printf OUTPUT "#: %s:%d\n", $pathname, $token->line_number |
222 |
if defined $pathname && defined $token->line_number; |
222 |
if defined $pathname && defined $token->line_number; |
223 |
$cformat_p = 1 if $token->type == TmplTokenType::TEXT_PARAMETRIZED; |
223 |
$cformat_p = 1 if $token->type == C4::TmplTokenType::TEXT_PARAMETRIZED; |
224 |
} |
224 |
} |
225 |
printf OUTPUT "#, c-format\n" if $cformat_p; |
225 |
printf OUTPUT "#, c-format\n" if $cformat_p; |
226 |
printf OUTPUT "msgid %s\n", TmplTokenizer::quote_po |
226 |
printf OUTPUT "msgid %s\n", TmplTokenizer::quote_po |
Lines 246-252
sub convert_translation_file () {
Link Here
|
246 |
$msgid =~ s/^SELECTED>//; |
246 |
$msgid =~ s/^SELECTED>//; |
247 |
|
247 |
|
248 |
# Create dummy token |
248 |
# Create dummy token |
249 |
my $token = TmplToken->new( $msgid, TmplTokenType::UNKNOWN, undef, undef ); |
249 |
my $token = TmplToken->new( $msgid, C4::TmplTokenType::UNKNOWN, undef, undef ); |
250 |
remember( $token, $msgid ); |
250 |
remember( $token, $msgid ); |
251 |
$msgstr =~ s/^(?:LIMIT;|LIMITED;)//g; # unneeded for tmpl_process3 |
251 |
$msgstr =~ s/^(?:LIMIT;|LIMITED;)//g; # unneeded for tmpl_process3 |
252 |
$translation{$msgid} = $msgstr unless $msgstr eq '*****'; |
252 |
$translation{$msgid} = $msgstr unless $msgstr eq '*****'; |