Bug 5917 : Fixing the translation script
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
This commit is contained in:
parent
961e9fec87
commit
241846c62c
2 changed files with 21 additions and 10 deletions
|
@ -42,7 +42,7 @@ sub build_tokens{
|
|||
$self->handler(end => "end", "self, line, tag, attr, text"); #signature is end( self, linenumber, tagename, origional text )
|
||||
$self->handler(declaration => "declaration", "self, line, text, is_cdata"); # declaration
|
||||
$self->handler(comment => "comment", "self, line, text, is_cdata"); # comments
|
||||
$self->handler(default => "default", "self, line, text, is_cdata"); # anything else
|
||||
# $self->handler(default => "default", "self, line, text, is_cdata"); # anything else
|
||||
$self->marked_sections(1); #treat anything inside CDATA tags as text, should really make it a TmplTokenType::CDATA
|
||||
$self->unbroken_text(1); #make contiguous whitespace into a single token (can span multiple lines)
|
||||
$self->parse_file($filename);
|
||||
|
@ -120,7 +120,12 @@ sub start{
|
|||
# tags seem to be uses in an 'interesting' way elsewhere..
|
||||
for my $key( %$hash ) {
|
||||
next unless defined $hash->{$key};
|
||||
if ($key eq "/"){
|
||||
$attr{+lc($key)} = [ $key, $hash->{$key}, $key."=".$hash->{$key}, 1 ];
|
||||
}
|
||||
else {
|
||||
$attr{+lc($key)} = [ $key, $hash->{$key}, $key."=".$hash->{$key}, 0 ];
|
||||
}
|
||||
}
|
||||
$t->set_attributes( \%attr );
|
||||
push @tokens, $t;
|
||||
|
|
|
@ -48,6 +48,7 @@ sub find_translation ($) {
|
|||
sub text_replace_tag ($$) {
|
||||
my($t, $attr) = @_;
|
||||
my $it;
|
||||
|
||||
# value [tag=input], meta
|
||||
my $tag = lc($1) if $t =~ /^<(\S+)/s;
|
||||
my $translated_p = 0;
|
||||
|
@ -55,8 +56,8 @@ sub text_replace_tag ($$) {
|
|||
if ($attr->{$a}) {
|
||||
next if $a eq 'label' && $tag ne 'optgroup';
|
||||
next if $a eq 'content' && $tag ne 'meta';
|
||||
next if $a eq 'value' && ($tag ne 'input'
|
||||
|| (ref $attr->{'type'} && $attr->{'type'}->[1] =~ /^(?:checkbox|hidden|radio|text)$/)); # FIXME
|
||||
next if $a eq 'value' && ($tag ne 'input' || (ref $attr->{'type'} && $attr->{'type'}->[1] =~ /^(?:checkbox|hidden|radio|text)$/)); # FIXME
|
||||
|
||||
my($key, $val, $val_orig, $order) = @{$attr->{$a}}; #FIXME
|
||||
if ($val =~ /\S/s) {
|
||||
my $s = find_translation($val);
|
||||
|
@ -69,17 +70,22 @@ sub text_replace_tag ($$) {
|
|||
}
|
||||
}
|
||||
if ($translated_p) {
|
||||
$it = "<$tag"
|
||||
. join('', map {
|
||||
sprintf(' %s=%s', $_, $attr->{$_}->[2]) #FIXME
|
||||
} sort {
|
||||
$attr->{$a}->[3] <=> $attr->{$b}->[3] #FIXME
|
||||
} keys %$attr);
|
||||
$it = "<$tag"
|
||||
. join('', map { if ($_ ne '/'){
|
||||
sprintf(' %s="%s"', $_, $attr->{$_}->[1]);
|
||||
}
|
||||
else {
|
||||
sprintf(' %s',$_);
|
||||
}
|
||||
|
||||
} sort {
|
||||
$attr->{$a}->[3] <=> $attr->{$b}->[3] #FIXME
|
||||
} keys %$attr);
|
||||
if ($tag eq 'img'){
|
||||
$it .= ' />';
|
||||
}
|
||||
else {
|
||||
$it .= ' >';
|
||||
$it .= '>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in a new issue